Change the default value for subject identifier
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
+import org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException;
import org.wso2.carbon.identity.application.authentication.framework.handler.request.AbstractPostAuthnHandler;
import org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
@@ -33,6 +34,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED;
+import static org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus.UNSUCCESS_COMPLETED;
/**
* This PostAuthenticationHandler is responsible for setting subject identifier related with authenticated user.
@@ -88,16 +90,19 @@ public class PostAuthenticatedSubjectIdentifierHandler extends AbstractPostAuthn
SequenceConfig sequenceConfig = context.getSequenceConfig();
String subjectClaimURI = sequenceConfig.getApplicationConfig().getSubjectClaimUri();
String subjectValue = (String) context.getProperty(FrameworkConstants.SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE);
+ try {
if (StringUtils.isNotBlank(subjectClaimURI)) {
if (subjectValue != null) {
handleUserStoreAndTenantDomain(sequenceConfig, subjectValue);
} else {
log.warn("Subject claim could not be found. Defaulting to Name Identifier.");
- setAuthenticatedSujectIdentifierBasedOnUserName(sequenceConfig);
+ setAuthenticatedSubjectIdentifierBasedOnUserId(sequenceConfig);
}
} else {
- setAuthenticatedSujectIdentifierBasedOnUserName(sequenceConfig);
-
+ setAuthenticatedSubjectIdentifierBasedOnUserId(sequenceConfig);
+ }
+ } catch (UserIdNotFoundException e) {
+ return UNSUCCESS_COMPLETED;
}
return SUCCESS_COMPLETED;
}
@@ -133,23 +138,30 @@ public class PostAuthenticatedSubjectIdentifierHandler extends AbstractPostAuthn
}
/**
- * To set authenticated subject identifier based on user name.
+ * To set authenticated subject identifier based on user id.
*
* @param sequenceConfig Relevant sequence config.
*/
- private void setAuthenticatedSujectIdentifierBasedOnUserName(SequenceConfig sequenceConfig) {
+ private void setAuthenticatedSubjectIdentifierBasedOnUserId(SequenceConfig sequenceConfig)
+ throws UserIdNotFoundException {
- String authenticatedUserName = sequenceConfig.getAuthenticatedUser().getUserName();
+ String authenticatedUserId = sequenceConfig.getAuthenticatedUser().getUserId();
boolean isUserstoreDomainInLocalSubjectIdentifier = sequenceConfig.getApplicationConfig()
.isUseUserstoreDomainInLocalSubjectIdentifier();
boolean isUseTenantDomainInLocalSubjectIdentifier = sequenceConfig.getApplicationConfig()
.isUseTenantDomainInLocalSubjectIdentifier();
- if (StringUtils.isNotEmpty(authenticatedUserName)) {
- sequenceConfig.getAuthenticatedUser().setAuthenticatedSubjectIdentifier(
- sequenceConfig.getAuthenticatedUser()
- .getUsernameAsSubjectIdentifier(isUserstoreDomainInLocalSubjectIdentifier,
- isUseTenantDomainInLocalSubjectIdentifier));
+ if (StringUtils.isNotEmpty(authenticatedUserId)) {
+ if (isUseTenantDomainInLocalSubjectIdentifier) {
+ authenticatedUserId = UserCoreUtil.addTenantDomainToEntry(authenticatedUserId,
+ sequenceConfig.getAuthenticatedUser().getTenantDomain());
+ }
+ if (isUserstoreDomainInLocalSubjectIdentifier) {
+ authenticatedUserId = UserCoreUtil.addDomainToName(authenticatedUserId,
+ sequenceConfig.getAuthenticatedUser().getUserStoreDomain());
+ }
+
+ sequenceConfig.getAuthenticatedUser().setAuthenticatedSubjectIdentifier(authenticatedUserId);
}
}
