Search in sources :

Example 6 with FederatedAssociationManager

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;
}
Also used : FederatedAssociationManager(org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) FederatedAssociationManagerException(org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException)

Example 7 with FederatedAssociationManager

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;
}
Also used : FederatedAssociationManager(org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) FederatedAssociationManagerException(org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException) PostAuthenticationFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)

Aggregations

FederatedAssociationManager (org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager)7 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)4 FederatedAssociationManagerException (org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Test (org.testng.annotations.Test)2 AbstractFrameworkTest (org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest)2 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)2 PostAuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)2 PostAuthnHandlerFlowStatus (org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus)2 StepBasedSequenceHandler (org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler)2 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)2 UserRealm (org.wso2.carbon.user.core.UserRealm)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Mockito.anyString (org.mockito.Mockito.anyString)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 Activate (org.osgi.service.component.annotations.Activate)1 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)1 UserIdNotFoundException (org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException)1