Search in sources :

Example 1 with AdditionalClaims

use of org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims in project identity-inbound-auth-oauth by wso2-extensions.

the class ClaimProviderImpl method getAdditionalClaims.

@Override
public Map<String, Object> getAdditionalClaims(OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext, OAuth2AuthorizeRespDTO oAuth2AuthorizeRespDTO) throws IdentityOAuth2Exception {
    Map<String, Object> additionalClaims = new HashMap<>();
    String claimValue;
    OIDCSessionState previousSession = getSessionState(oAuthAuthzReqMessageContext);
    if (previousSession == null) {
        // If there is no previous browser session, generate new sid value.
        claimValue = UUID.randomUUID().toString();
        if (log.isDebugEnabled()) {
            log.debug("sid claim is generated for auth request. ");
        }
    } else {
        // Previous browser session exists, get sid claim from OIDCSessionState.
        claimValue = previousSession.getSidClaim();
        if (log.isDebugEnabled()) {
            log.debug("sid claim is found in the session state");
        }
    }
    additionalClaims.put(OAuthConstants.OIDCClaims.SESSION_ID_CLAIM, claimValue);
    oAuth2AuthorizeRespDTO.setOidcSessionId(claimValue);
    return additionalClaims;
}
Also used : HashMap(java.util.HashMap) OIDCSessionState(org.wso2.carbon.identity.oidc.session.OIDCSessionState)

Example 2 with AdditionalClaims

use of org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims in project identity-api-server by wso2.

the class ServerTenantManagementService method createTenantInfoBean.

private Tenant createTenantInfoBean(ChannelVerifiedTenantModel channelVerifiedTenantModel) throws TenantManagementClientException {
    Tenant tenant = new Tenant();
    Map<String, String> claimsMap = new HashMap<>();
    tenant.setActive(true);
    tenant.setDomain(StringUtils.lowerCase(channelVerifiedTenantModel.getDomain()));
    if (channelVerifiedTenantModel.getOwners() != null && channelVerifiedTenantModel.getOwners().size() > 0 && channelVerifiedTenantModel.getOwners().get(0) != null) {
        tenant.setAdminName(channelVerifiedTenantModel.getOwners().get(0).getEmail());
        tenant.setAdminFirstName(channelVerifiedTenantModel.getOwners().get(0).getFirstname());
        tenant.setAdminLastName(channelVerifiedTenantModel.getOwners().get(0).getLastname());
        tenant.setEmail(channelVerifiedTenantModel.getOwners().get(0).getEmail());
        tenant.setProvisioningMethod(VERIFIED_LITE_USER);
        String password = channelVerifiedTenantModel.getOwners().get(0).getPassword();
        String code = channelVerifiedTenantModel.getCode();
        if (StringUtils.isBlank(code)) {
            throw new TenantManagementClientException(TenantConstants.ErrorMessage.ERROR_CODE_MISSING_REQUIRED_PARAMETER.getCode(), String.format(TenantConstants.ErrorMessage.ERROR_CODE_MISSING_REQUIRED_PARAMETER.getMessage(), "code"));
        }
        if (channelVerifiedTenantModel.getPurpose() != null) {
            claimsMap.put(PURPOSE, channelVerifiedTenantModel.getPurpose().getName());
            if (!CollectionUtils.isEmpty(channelVerifiedTenantModel.getPurpose().getAttributes())) {
                channelVerifiedTenantModel.getPurpose().getAttributes().forEach(attribute -> claimsMap.put(PURPOSE + "_" + attribute.getKey(), attribute.getValue()));
            }
        }
        tenant.setClaimsMap(claimsMap);
        tenant.setAdminPassword(password);
        List<AdditionalClaims> additionalClaimsList = channelVerifiedTenantModel.getOwners().get(0).getAdditionalClaims();
        if (CollectionUtils.isNotEmpty(additionalClaimsList)) {
            tenant.setClaimsMap(createClaimsMapping(additionalClaimsList));
        }
    } else {
        throw new TenantManagementClientException(TenantConstants.ErrorMessage.ERROR_CODE_OWNER_REQUIRED);
    }
    return tenant;
}
Also used : TenantManagementClientException(org.wso2.carbon.stratos.common.exception.TenantManagementClientException) Tenant(org.wso2.carbon.user.core.tenant.Tenant) HashMap(java.util.HashMap) AdditionalClaims(org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims)

Example 3 with AdditionalClaims

use of org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims in project identity-inbound-auth-oauth by wso2-extensions.

the class ClaimProviderImpl method getAdditionalClaims.

@Override
public Map<String, Object> getAdditionalClaims(OAuthTokenReqMessageContext oAuthTokenReqMessageContext, OAuth2AccessTokenRespDTO oAuth2AccessTokenRespDTO) throws IdentityOAuth2Exception {
    Map<String, Object> additionalClaims = new HashMap<>();
    String claimValue = null;
    String accessCode = oAuthTokenReqMessageContext.getOauth2AccessTokenReqDTO().getAuthorizationCode();
    if (StringUtils.isBlank(accessCode)) {
        if (log.isDebugEnabled()) {
            log.debug("AccessCode is null. Possibly a back end grant");
        }
        return additionalClaims;
    }
    AuthorizationGrantCacheEntry authzGrantCacheEntry = getAuthorizationGrantCacheEntryFromCode(accessCode);
    if (authzGrantCacheEntry != null) {
        claimValue = authzGrantCacheEntry.getOidcSessionId();
    }
    if (claimValue != null) {
        if (log.isDebugEnabled()) {
            log.debug("sid claim is found in the session state");
        }
        additionalClaims.put("sid", claimValue);
    }
    return additionalClaims;
}
Also used : AuthorizationGrantCacheEntry(org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCacheEntry) HashMap(java.util.HashMap)

Example 4 with AdditionalClaims

use of org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims in project identity-api-server by wso2.

the class ServerTenantManagementService method createTenantInfoBean.

private Tenant createTenantInfoBean(TenantModel tenantModel) throws TenantManagementClientException {
    Tenant tenant = new Tenant();
    tenant.setActive(true);
    tenant.setDomain(tenantModel.getDomain());
    if (tenantModel.getOwners() != null) {
        tenant.setAdminName(tenantModel.getOwners().get(0).getUsername());
        tenant.setAdminFirstName(tenantModel.getOwners().get(0).getFirstname());
        tenant.setAdminLastName(tenantModel.getOwners().get(0).getLastname());
        tenant.setEmail(tenantModel.getOwners().get(0).getEmail());
        String provisioningMethod = tenantModel.getOwners().get(0).getProvisioningMethod();
        if (INLINE_PASSWORD.equalsIgnoreCase(provisioningMethod)) {
            String password = tenantModel.getOwners().get(0).getPassword();
            if (StringUtils.isBlank(password)) {
                throw new TenantManagementClientException(TenantConstants.ErrorMessage.ERROR_CODE_MISSING_REQUIRED_PARAMETER.getCode(), String.format(TenantConstants.ErrorMessage.ERROR_CODE_MISSING_REQUIRED_PARAMETER.getMessage(), "password"));
            }
            tenant.setAdminPassword(password);
        }
        tenant.setProvisioningMethod(provisioningMethod);
        List<AdditionalClaims> additionalClaimsList = tenantModel.getOwners().get(0).getAdditionalClaims();
        if (CollectionUtils.isNotEmpty(additionalClaimsList)) {
            tenant.setClaimsMap(createClaimsMapping(additionalClaimsList));
        }
    } else {
        throw new TenantManagementClientException(TenantConstants.ErrorMessage.ERROR_CODE_OWNER_REQUIRED);
    }
    return tenant;
}
Also used : TenantManagementClientException(org.wso2.carbon.stratos.common.exception.TenantManagementClientException) Tenant(org.wso2.carbon.user.core.tenant.Tenant) AdditionalClaims(org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims)

Aggregations

HashMap (java.util.HashMap)3 AdditionalClaims (org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims)2 TenantManagementClientException (org.wso2.carbon.stratos.common.exception.TenantManagementClientException)2 Tenant (org.wso2.carbon.user.core.tenant.Tenant)2 AuthorizationGrantCacheEntry (org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCacheEntry)1 OIDCSessionState (org.wso2.carbon.identity.oidc.session.OIDCSessionState)1