use of org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandler method getLocalUserAssociatedForFederatedIdentifier.
/**
* To get the associated username for the current step.
*
* @param idpName Name of IDP related with current step.
* @param authenticatedSubjectIdentifier Authenticated subject identifier.
* @return username associated locally.
*/
private String getLocalUserAssociatedForFederatedIdentifier(String idpName, String authenticatedSubjectIdentifier, String tenantDomain) throws PostAuthenticationFailedException {
String username = null;
try {
FederatedAssociationManager federatedAssociationManager = FrameworkUtils.getFederatedAssociationManager();
username = federatedAssociationManager.getUserForFederatedAssociation(tenantDomain, idpName, authenticatedSubjectIdentifier);
} catch (FederatedAssociationManagerException | FrameworkException e) {
handleExceptions(String.format(ErrorMessages.ERROR_WHILE_GETTING_USERNAME_ASSOCIATED_WITH_IDP.getMessage(), idpName), ErrorMessages.ERROR_WHILE_GETTING_USERNAME_ASSOCIATED_WITH_IDP.getCode(), e);
}
return username;
}
use of org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager in project carbon-identity-framework by wso2.
the class PostAuthAssociationHandler method getUserNameAssociatedWith.
/**
* To get the local user name associated with the given federated IDP and the subject identifier.
*
* @param context Authentication context.
* @param stepConfig Step config.
* @return user name associated with.
* @throws PostAuthenticationFailedException Post Authentication Failed Exception.
*/
private String getUserNameAssociatedWith(AuthenticationContext context, StepConfig stepConfig) throws PostAuthenticationFailedException {
String associatesUserName;
String originalExternalIdpSubjectValueForThisStep = stepConfig.getAuthenticatedUser().getAuthenticatedSubjectIdentifier();
try {
FrameworkUtils.startTenantFlow(context.getTenantDomain());
FederatedAssociationManager federatedAssociationManager = FrameworkUtils.getFederatedAssociationManager();
associatesUserName = federatedAssociationManager.getUserForFederatedAssociation(context.getTenantDomain(), stepConfig.getAuthenticatedIdP(), originalExternalIdpSubjectValueForThisStep);
if (StringUtils.isNotBlank(associatesUserName)) {
if (log.isDebugEnabled()) {
log.debug("User : " + stepConfig.getAuthenticatedUser() + " has an associated account as " + associatesUserName + ". Hence continuing as " + associatesUserName);
}
stepConfig.getAuthenticatedUser().setUserName(associatesUserName);
stepConfig.getAuthenticatedUser().setTenantDomain(context.getTenantDomain());
stepConfig.setAuthenticatedUser(stepConfig.getAuthenticatedUser());
} else {
if (log.isDebugEnabled()) {
log.debug("User " + stepConfig.getAuthenticatedUser() + " doesn't have an associated" + " account. Hence continuing as the same user.");
}
}
} catch (FederatedAssociationManagerException | FrameworkException e) {
throw new PostAuthenticationFailedException(FrameworkErrorConstants.ErrorMessages.ERROR_WHILE_GETTING_LOCAL_USER_ID.getCode(), String.format(FrameworkErrorConstants.ErrorMessages.ERROR_WHILE_GETTING_IDP_BY_NAME.getMessage(), originalExternalIdpSubjectValueForThisStep), e);
} finally {
FrameworkUtils.endTenantFlow();
}
return associatesUserName;
}
Aggregations