Java Code Examples for org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#getProperties()

The following examples show how to use org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#getProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostAuthAssociationHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * To set the associated local user in automation context and to add the relevant claims.
 *
 * @param associatedLocalUserName Associated Local username.
 * @param context                 Authentication context.
 * @param stepConfig              Configuration related with current authentication step.
 * @throws PostAuthenticationFailedException Post Authentication failed exception.
 */
private void setAssociatedLocalUserToContext(String associatedLocalUserName, AuthenticationContext context,
        StepConfig stepConfig) throws PostAuthenticationFailedException {

    SequenceConfig sequenceConfig = context.getSequenceConfig();
    String fullQualifiedAssociatedUserId = FrameworkUtils.prependUserStoreDomainToName(
            associatedLocalUserName + UserCoreConstants.TENANT_DOMAIN_COMBINER + context.getTenantDomain());
    UserCoreUtil.setDomainInThreadLocal(UserCoreUtil.extractDomainFromName(associatedLocalUserName));
    sequenceConfig.setAuthenticatedUser(
            AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier(fullQualifiedAssociatedUserId));
    sequenceConfig.getApplicationConfig().setMappedSubjectIDSelected(true);

    Map<String, String> mappedAttrs = handleClaimMappings(stepConfig, context);
    handleRoleMapping(context, sequenceConfig, mappedAttrs);
    Map<ClaimMapping, String> authenticatedUserAttributes = getClaimMapping(context, mappedAttrs);
    if (MapUtils.isNotEmpty(authenticatedUserAttributes)) {
        sequenceConfig.getAuthenticatedUser().setUserAttributes(authenticatedUserAttributes);
        if (log.isDebugEnabled()) {
            log.debug("Local claims from the local user: " + associatedLocalUserName + ", set as "
                    + "user attributed for the federated scenario");
        }
    }
    // in this case associatedID is a local user name - belongs to a tenant in IS.
    String tenantDomain = MultitenantUtils.getTenantDomain(associatedLocalUserName);
    Map<String, Object> authProperties = context.getProperties();

    if (authProperties == null) {
        authProperties = new HashMap<>();
        context.setProperties(authProperties);
    }
    authProperties.put(USER_TENANT_DOMAIN, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug(
                "Authenticated User: " + sequenceConfig.getAuthenticatedUser().getAuthenticatedSubjectIdentifier());
        log.debug("Authenticated User Tenant Domain: " + tenantDomain);
    }
}
 
Example 2
Source File: DefaultAuthenticationRequestHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private String getAuthenticatedUserTenantDomain(AuthenticationContext context,
                                                AuthenticationResult authenticationResult) {

    String authenticatedUserTenantDomain = null;
    if (context.getProperties() != null) {
        authenticatedUserTenantDomain = (String) context.getProperties()
                .get("user-tenant-domain");
    }
    return authenticatedUserTenantDomain;
}
 
Example 3
Source File: DefaultAuthenticationRequestHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private String getAuthenticatedUserTenantDomain(AuthenticationContext context,
                                                AuthenticationResult authenticationResult) {
    String authenticatedUserTenantDomain = null;
    if (context.getProperties() != null) {
        authenticatedUserTenantDomain = (String) context.getProperties()
                .get("user-tenant-domain");
    }
    return authenticatedUserTenantDomain;
}
 
Example 4
Source File: OAuthRequestPathAuthenticator.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
protected void processAuthenticationResponse(HttpServletRequest request,
                                             HttpServletResponse response, AuthenticationContext context)
        throws AuthenticationFailedException {

    String headerValue = (String) request.getSession().getAttribute(AUTHORIZATION_HEADER_NAME);

    String token = null;
    if (headerValue != null) {
        token = headerValue.trim().split(" ")[1];
    } else {
        token = request.getParameter(ACCESS_TOKEN);
    }


    try {
        OAuth2TokenValidationService validationService = new OAuth2TokenValidationService();
        OAuth2TokenValidationRequestDTO validationReqDTO = new OAuth2TokenValidationRequestDTO();
        OAuth2AccessToken accessToken = validationReqDTO.new OAuth2AccessToken();
        accessToken.setIdentifier(token);
        accessToken.setTokenType("bearer");
        validationReqDTO.setAccessToken(accessToken);
        OAuth2TokenValidationResponseDTO validationResponse = validationService.validate(validationReqDTO);

        if (!validationResponse.isValid()) {
            log.error("RequestPath OAuth authentication failed");
            throw new AuthenticationFailedException("Authentication Failed");
        }

        String user = validationResponse.getAuthorizedUser();
        String tenantDomain = MultitenantUtils.getTenantDomain(user);

        if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
            user = MultitenantUtils.getTenantAwareUsername(user);
        }

        Map<String, Object> authProperties = context.getProperties();

        if (authProperties == null) {
            authProperties = new HashMap<String, Object>();
            context.setProperties(authProperties);
        }

        // TODO: user tenant domain has to be an attribute in the
        // AuthenticationContext
        authProperties.put("user-tenant-domain", tenantDomain);

        if (log.isDebugEnabled()) {
            log.debug("Authenticated user " + user);
        }

        context.setSubject(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier(user));
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new AuthenticationFailedException(e.getMessage(), e);
    }
}