Search in sources :

Example 61 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class IdentityClaimManager method getAllSupportedClaims.

/**
 * Returns all supported claims.
 *
 * @param realm user realm
 * @return array of all supported claims
 * @throws IdentityException if error occurs while building supported claims
 */
public Claim[] getAllSupportedClaims(UserRealm realm) throws IdentityException {
    try {
        ClaimManager claimAdmin = realm.getClaimManager();
        ClaimMapping[] mappings = claimAdmin.getAllSupportClaimMappingsByDefault();
        Claim[] claims = new Claim[0];
        if (mappings != null) {
            claims = new Claim[mappings.length];
            for (int i = 0; i < mappings.length; i++) {
                claims[i] = (Claim) mappings[i].getClaim();
            }
        }
        return claims;
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        log.error("Error occurred while loading supported claims", e);
        getException("Error occurred while loading supported claima", e);
    }
    return new Claim[0];
}
Also used : ClaimManager(org.wso2.carbon.user.core.claim.ClaimManager) ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) Claim(org.wso2.carbon.user.core.claim.Claim)

Example 62 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticator method proceedOTPWithFederatedMobileNumber.

private void proceedOTPWithFederatedMobileNumber(AuthenticationContext context, HttpServletResponse response, String username, String queryParams, boolean sendOtpToFederatedMobile) throws AuthenticationFailedException {
    try {
        String federatedMobileAttributeKey;
        String mobile = null;
        StepConfig stepConfig = context.getSequenceConfig().getStepMap().get(context.getCurrentStep() - 1);
        String previousStepAuthenticator = stepConfig.getAuthenticatedAutenticator().getName();
        StepConfig currentStep = context.getSequenceConfig().getStepMap().get(context.getCurrentStep());
        String currentStepAuthenticator = currentStep.getAuthenticatorList().iterator().next().getName();
        if (sendOtpToFederatedMobile) {
            federatedMobileAttributeKey = getFederatedMobileAttributeKey(context, previousStepAuthenticator);
            if (StringUtils.isEmpty(federatedMobileAttributeKey)) {
                federatedMobileAttributeKey = getFederatedMobileAttributeKey(context, currentStepAuthenticator);
            }
            Map<ClaimMapping, String> userAttributes = context.getCurrentAuthenticatedIdPs().values().iterator().next().getUser().getUserAttributes();
            for (Map.Entry<ClaimMapping, String> entry : userAttributes.entrySet()) {
                String key = String.valueOf(entry.getKey().getLocalClaim().getClaimUri());
                String value = entry.getValue();
                if (key.equals(federatedMobileAttributeKey)) {
                    mobile = String.valueOf(value);
                    proceedWithOTP(response, context, getErrorPage(context), mobile, queryParams, username);
                    break;
                }
            }
            if (StringUtils.isEmpty(mobile)) {
                if (log.isDebugEnabled()) {
                    log.debug("There is no mobile claim to send otp ");
                }
                throw new AuthenticationFailedException("There is no mobile claim to send otp");
            }
        } else {
            redirectToErrorPage(response, context, queryParams, SMSOTPConstants.SEND_OTP_DIRECTLY_DISABLE);
        }
    } catch (AuthenticationFailedException e) {
        throw new AuthenticationFailedException(" Failed to process SMSOTP flow ", e);
    }
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) AuthenticationFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) Map(java.util.Map) HashMap(java.util.HashMap)

Example 63 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-auth-oauth by wso2-extensions.

the class UserInfoUserStoreClaimRetrieverTest method getUserAttributes.

@DataProvider
public Object[][] getUserAttributes() {
    ClaimMapping map1 = ClaimMapping.build("localClaimUri1", "remoteClaimUri1", "defaultValue1", true);
    ClaimMapping map2 = ClaimMapping.build("localClaimUri2", "remoteClaimUri2", "defaultValue1", true);
    Map<ClaimMapping, Object> claims1 = new HashMap<ClaimMapping, Object>();
    Map<ClaimMapping, Object> claims2 = new HashMap<ClaimMapping, Object>();
    claims1.put(map1, "User1");
    claims2.put(map2, "User1, User2");
    return new Object[][] { { claims1 }, { claims2 } };
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) HashMap(java.util.HashMap) DataProvider(org.testng.annotations.DataProvider)

Example 64 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-auth-oauth by wso2-extensions.

the class DefaultClaimsRetriever method getDefaultClaims.

@Override
public String[] getDefaultClaims(String endUserName) throws IdentityOAuth2Exception {
    int tenantId = MultitenantConstants.SUPER_TENANT_ID;
    try {
        tenantId = OAuth2Util.getTenantIdFromUserName(endUserName);
        // if no claims were requested, return all
        if (log.isDebugEnabled()) {
            log.debug("No claims set requested. Returning all claims in the dialect");
        }
        ClaimManager claimManager = OAuthComponentServiceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getClaimManager();
        ClaimMapping[] claims = claimManager.getAllClaimMappings(dialectURI);
        return claimToString(claims);
    } catch (UserStoreException e) {
        throw new IdentityOAuth2Exception("Error while reading default claims for user : " + endUserName, e);
    }
}
Also used : ClaimManager(org.wso2.carbon.user.api.ClaimManager) ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 65 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-auth-oauth by wso2-extensions.

the class ClaimUtil method getUserClaimsUsingTokenResponse.

public static Map<String, Object> getUserClaimsUsingTokenResponse(OAuth2TokenValidationResponseDTO tokenResponse) throws UserInfoEndpointException {
    Map<ClaimMapping, String> userAttributes = getUserAttributesFromCache(tokenResponse);
    Map<String, Object> userClaimsInOIDCDialect;
    if (isEmpty(userAttributes)) {
        if (log.isDebugEnabled()) {
            log.debug("User attributes not found in cache against the token. Retrieved claims from user store.");
        }
        userClaimsInOIDCDialect = getClaimsFromUserStore(tokenResponse);
    } else {
        UserInfoClaimRetriever retriever = UserInfoEndpointConfig.getInstance().getUserInfoClaimRetriever();
        userClaimsInOIDCDialect = retriever.getClaimsMap(userAttributes);
    }
    if (isEmpty(userClaimsInOIDCDialect)) {
        userClaimsInOIDCDialect = new HashMap<>();
    }
    return userClaimsInOIDCDialect;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) UserInfoClaimRetriever(org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever)

Aggregations

ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)109 HashMap (java.util.HashMap)60 ArrayList (java.util.ArrayList)52 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)28 Map (java.util.Map)26 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)24 ClaimMapping (org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping)24 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)24 Claim (org.wso2.carbon.identity.application.common.model.Claim)23 Test (org.testng.annotations.Test)22 Claim (org.wso2.carbon.identity.application.common.model.xsd.Claim)21 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)21 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)20 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)20 List (java.util.List)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 UserStoreException (org.wso2.carbon.user.api.UserStoreException)17 Matchers.anyString (org.mockito.Matchers.anyString)16 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)14 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)13