Java Code Examples for org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#resetThreadLocalProvisioningServiceProvider()

The following examples show how to use org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#resetThreadLocalProvisioningServiceProvider() . 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: DefaultStepBasedSequenceHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param context
 * @param mappedRoles
 * @param extAttributesValueMap
 */
protected void handleJitProvisioning(String subjectIdentifier, AuthenticationContext context,
                                     List<String> mappedRoles, Map<String, String> extAttributesValueMap)
        throws FrameworkException {

    try {
        @SuppressWarnings("unchecked")
        String userStoreDomain = null;
        String provisioningClaimUri = context.getExternalIdP().getProvisioningUserStoreClaimURI();
        String provisioningUserStoreId = context.getExternalIdP().getProvisioningUserStoreId();

        if (provisioningUserStoreId != null) {
            userStoreDomain = provisioningUserStoreId;
        } else if (provisioningClaimUri != null) {
            userStoreDomain = extAttributesValueMap.get(provisioningClaimUri);
        }

        // setup thread local variable to be consumed by the provisioning
        // framework.
        ThreadLocalProvisioningServiceProvider serviceProvider = new ThreadLocalProvisioningServiceProvider();
        serviceProvider.setServiceProviderName(context.getSequenceConfig()
                .getApplicationConfig().getApplicationName());
        serviceProvider.setJustInTimeProvisioning(true);
        serviceProvider.setClaimDialect(ApplicationConstants.LOCAL_IDP_DEFAULT_CLAIM_DIALECT);
        serviceProvider.setTenantDomain(context.getTenantDomain());
        IdentityApplicationManagementUtil.setThreadLocalProvisioningServiceProvider(serviceProvider);

        FrameworkUtils.getProvisioningHandler().handle(mappedRoles, subjectIdentifier,
                extAttributesValueMap, userStoreDomain, context.getTenantDomain());

    } catch (FrameworkException e) {
        log.error("User provisioning failed!", e);
    } finally {
        IdentityApplicationManagementUtil.resetThreadLocalProvisioningServiceProvider();
    }
}
 
Example 2
Source File: AuthenticationFilter.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    // reset anything set on provisioning thread local.
    IdentityApplicationManagementUtil.resetThreadLocalProvisioningServiceProvider();

    if (log.isDebugEnabled()) {
        log.debug("Authenticating Entitlement Endpoint request..");
    }
    EntitlementAuthenticatorRegistry entitlementAuthRegistry = EntitlementAuthenticatorRegistry.getInstance();

    if (entitlementAuthRegistry != null) {
        EntitlementAuthenticationHandler entitlementAuthHandler = entitlementAuthRegistry.getAuthenticator(
                containerRequestContext);

        boolean isAuthenticated = false;
        if (entitlementAuthHandler != null) {
            isAuthenticated = entitlementAuthHandler.isAuthenticated(containerRequestContext);

            if (isAuthenticated) {
                return;
            }
        }
    }
    //if null response is not returned(i.e:message continues its way to the resource), return error & terminate.
    UnauthorizedException unauthorizedException = new UnauthorizedException(
            EntitlementEndpointConstants.ERROR_UNAUTHORIZED_MESSAGE);
    Response.ResponseBuilder responseBuilder = Response.status(unauthorizedException.getCode());
    responseBuilder.entity(unauthorizedException.getDescription());

    containerRequestContext.abortWith(responseBuilder.build());
}
 
Example 3
Source File: DefaultStepBasedSequenceHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param context
 * @param mappedRoles
 * @param extAttributesValueMap
 */
protected void handleJitProvisioning(String subjectIdentifier, AuthenticationContext context,
                                     List<String> mappedRoles, Map<String, String> extAttributesValueMap)
        throws FrameworkException {

    try {
        @SuppressWarnings("unchecked")
        String userStoreDomain = null;
        String provisioningClaimUri = context.getExternalIdP()
                .getProvisioningUserStoreClaimURI();
        String provisioningUserStoreId = context.getExternalIdP().getProvisioningUserStoreId();

        if (provisioningUserStoreId != null) {
            userStoreDomain = provisioningUserStoreId;
        } else if (provisioningClaimUri != null) {
            userStoreDomain = extAttributesValueMap.get(provisioningClaimUri);
        }

        // setup thread local variable to be consumed by the provisioning
        // framework.
        ThreadLocalProvisioningServiceProvider serviceProvider = new ThreadLocalProvisioningServiceProvider();
        serviceProvider.setServiceProviderName(context.getSequenceConfig()
                                                       .getApplicationConfig().getApplicationName());
        serviceProvider.setJustInTimeProvisioning(true);
        serviceProvider.setClaimDialect(ApplicationConstants.LOCAL_IDP_DEFAULT_CLAIM_DIALECT);
        serviceProvider.setTenantDomain(context.getTenantDomain());
        IdentityApplicationManagementUtil
                .setThreadLocalProvisioningServiceProvider(serviceProvider);

        FrameworkUtils.getProvisioningHandler().handle(mappedRoles, subjectIdentifier,
                                                       extAttributesValueMap, userStoreDomain, context.getTenantDomain());

    } catch (FrameworkException e) {
        log.error("User provisioning failed!", e);
    } finally {
        IdentityApplicationManagementUtil.resetThreadLocalProvisioningServiceProvider();
    }
}
 
Example 4
Source File: AuthenticationFilter.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public Response handleRequest(Message message, ClassResourceInfo classResourceInfo) {

    // reset anything set on provisioning thread local.
    IdentityApplicationManagementUtil.resetThreadLocalProvisioningServiceProvider();

    if (log.isDebugEnabled()) {
        log.debug("Authenticating SCIM request..");
    }
    SCIMAuthenticatorRegistry SCIMAuthRegistry = SCIMAuthenticatorRegistry.getInstance();
    if (SCIMAuthRegistry != null) {
        SCIMAuthenticationHandler SCIMAuthHandler = SCIMAuthRegistry.getAuthenticator(
                message, classResourceInfo);
        boolean isAuthenticated = false;
        if (SCIMAuthHandler != null) {
            isAuthenticated = SCIMAuthHandler.isAuthenticated(message, classResourceInfo);
            if (isAuthenticated) {
                return null;
            }
        }
    }
    //if null response is not returned(i.e:message continues its way to the resource), return error & terminate.
    UnauthorizedException unauthorizedException = new UnauthorizedException(
            "Authentication failed for this resource.");
    return new JAXRSResponseBuilder().buildResponse(
            AbstractResourceEndpoint.encodeSCIMException(new JSONEncoder(), unauthorizedException));
}
 
Example 5
Source File: ClearThreadLocalInterceptor.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public void handleFault(Message message) {
    IdentityApplicationManagementUtil.resetThreadLocalProvisioningServiceProvider();
}
 
Example 6
Source File: AuthenticationFilter.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public void filter(ContainerRequestContext containerRequestContext,
                   ContainerResponseContext containerResponseContext) throws IOException {
    IdentityApplicationManagementUtil.resetThreadLocalProvisioningServiceProvider();
}
 
Example 7
Source File: ClearThreadLocalInterceptor.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public void handleFault(Message message) {
    IdentityApplicationManagementUtil.resetThreadLocalProvisioningServiceProvider();
}
 
Example 8
Source File: AuthenticationFilter.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public Response handleResponse(Message message, OperationResourceInfo operationResourceInfo, Response response) {
    IdentityApplicationManagementUtil.resetThreadLocalProvisioningServiceProvider();
    return null;
}