forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEYCLOAK-2339 Adding impersonator details to user session notes and s…
…upporting built-in protocol mappers.
- Loading branch information
Showing
8 changed files
with
155 additions
and
17 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
server-spi-private/src/main/java/org/keycloak/models/ImpersonationSessionNote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.keycloak.models; | ||
|
||
/** | ||
* Session note metadata for impersonation details stored in user session notes. | ||
*/ | ||
public enum ImpersonationSessionNote implements UserSessionNoteDescriptor { | ||
IMPERSONATOR_ID("Impersonator User ID"), | ||
IMPERSONATOR_USERNAME("Impersonator Username"); | ||
|
||
final String displayName; | ||
|
||
ImpersonationSessionNote(String displayName) { | ||
this.displayName = displayName; | ||
} | ||
|
||
public String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
public String getTokenClaim() { | ||
return this.toString().toLowerCase().replace('_', '.'); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
server-spi-private/src/main/java/org/keycloak/models/UserSessionNoteDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.keycloak.models; | ||
|
||
/** | ||
* Describes a user session note for simple and generic {@link ProtocolMapperModel} creation. | ||
*/ | ||
public interface UserSessionNoteDescriptor { | ||
/** | ||
* @return A human-readable name for the session note. This should tell the end user what the session note contains | ||
*/ | ||
String getDisplayName(); | ||
|
||
/** | ||
* @return Token claim name/path to store the user session note value in. | ||
*/ | ||
String getTokenClaim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,9 @@ | |
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.keycloak.models.ImpersonationSessionNote.IMPERSONATOR_ID; | ||
import static org.keycloak.models.ImpersonationSessionNote.IMPERSONATOR_USERNAME; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Bill Burke</a> | ||
* @version $Revision: 1 $ | ||
|
@@ -173,6 +176,9 @@ public Map<String, ProtocolMapperModel> getBuiltinMappers() { | |
|
||
model = AllowedWebOriginsProtocolMapper.createClaimMapper(ALLOWED_WEB_ORIGINS); | ||
builtins.put(ALLOWED_WEB_ORIGINS, model); | ||
|
||
builtins.put(IMPERSONATOR_ID.getDisplayName(), UserSessionNoteMapper.createUserSessionNoteMapper(IMPERSONATOR_ID)); | ||
builtins.put(IMPERSONATOR_USERNAME.getDisplayName(), UserSessionNoteMapper.createUserSessionNoteMapper(IMPERSONATOR_USERNAME)); | ||
} | ||
|
||
private static void createUserAttributeMapper(String name, String attrName, String claimName, String type) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,8 @@ | |
import org.keycloak.authorization.util.Tokens; | ||
import org.keycloak.broker.provider.BrokeredIdentityContext; | ||
import org.keycloak.broker.provider.ExchangeExternalToken; | ||
import org.keycloak.broker.provider.IdentityProvider; | ||
import org.keycloak.broker.provider.ExchangeTokenToIdentityProviderToken; | ||
import org.keycloak.broker.provider.IdentityProvider; | ||
import org.keycloak.broker.provider.IdentityProviderFactory; | ||
import org.keycloak.broker.provider.IdentityProviderMapper; | ||
import org.keycloak.common.ClientConnection; | ||
|
@@ -45,8 +45,8 @@ | |
import org.keycloak.events.EventType; | ||
import org.keycloak.jose.jws.JWSInput; | ||
import org.keycloak.jose.jws.JWSInputException; | ||
import org.keycloak.models.AuthenticationFlowModel; | ||
import org.keycloak.models.AuthenticatedClientSessionModel; | ||
import org.keycloak.models.AuthenticationFlowModel; | ||
import org.keycloak.models.ClientModel; | ||
import org.keycloak.models.ClientScopeModel; | ||
import org.keycloak.models.ClientSessionContext; | ||
|
@@ -99,14 +99,17 @@ | |
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status; | ||
import java.security.MessageDigest; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.security.MessageDigest; | ||
|
||
import static org.keycloak.models.ImpersonationSessionNote.IMPERSONATOR_ID; | ||
import static org.keycloak.models.ImpersonationSessionNote.IMPERSONATOR_USERNAME; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Stian Thorgersen</a> | ||
|
@@ -755,12 +758,16 @@ public Response tokenExchange() { | |
} | ||
} | ||
|
||
tokenUser = requestedUser; | ||
tokenSession = session.sessions().createUserSession(realm, requestedUser, requestedUser.getUsername(), clientConnection.getRemoteAddr(), "impersonate", false, null, null); | ||
if (tokenUser != null) { | ||
tokenSession.setNote(IMPERSONATOR_ID.toString(), tokenUser.getId()); | ||
tokenSession.setNote(IMPERSONATOR_USERNAME.toString(), tokenUser.getUsername()); | ||
} | ||
|
||
tokenUser = requestedUser; | ||
} | ||
|
||
String requestedIssuer = formParams.getFirst(OAuth2Constants.REQUESTED_ISSUER); | ||
|
||
if (requestedIssuer == null) { | ||
return exchangeClientToClient(tokenUser, tokenSession); | ||
} else { | ||
|
@@ -825,7 +832,6 @@ protected Response exchangeClientToClient(UserModel targetUser, UserSessionModel | |
} | ||
} | ||
|
||
|
||
if (targetClient.isConsentRequired()) { | ||
event.detail(Details.REASON, "audience requires consent"); | ||
event.error(Errors.CONSENT_DENIED); | ||
|
@@ -924,8 +930,6 @@ public Response exchangeExternalToken(String issuer, String subjectToken) { | |
userSession.setNote(IdentityProvider.FEDERATED_ACCESS_TOKEN, subjectToken); | ||
|
||
return exchangeClientToClient(user, userSession); | ||
|
||
|
||
} | ||
|
||
protected UserModel importUserFromExternalIdentity(BrokeredIdentityContext context) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters