Search in sources :

Example 1 with EntitlementAuthenticatorRegistry

use of org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthenticatorRegistry in project carbon-identity-framework by wso2.

the class AuthenticationFilter method filter.

@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());
}
Also used : Response(javax.ws.rs.core.Response) EntitlementAuthenticatorRegistry(org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthenticatorRegistry) EntitlementAuthenticationHandler(org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthenticationHandler) UnauthorizedException(org.wso2.carbon.identity.entitlement.endpoint.exception.UnauthorizedException)

Example 2 with EntitlementAuthenticatorRegistry

use of org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthenticatorRegistry in project carbon-identity-framework by wso2.

the class ApplicationInitializer method initEntitlementAuthenticatorRegistry.

private void initEntitlementAuthenticatorRegistry() {
    EntitlementAuthenticatorRegistry entitlementAuthRegistry = EntitlementAuthenticatorRegistry.getInstance();
    if (entitlementAuthRegistry != null) {
        // set authenticators after building auth config
        EntitlementAuthConfigReader configReader = new EntitlementAuthConfigReader();
        List<EntitlementAuthenticationHandler> entitlementAuthenticators = configReader.buildEntitlementAuthenticators();
        if (entitlementAuthenticators != null && !entitlementAuthenticators.isEmpty()) {
            for (EntitlementAuthenticationHandler entitlementAuthenticator : entitlementAuthenticators) {
                entitlementAuthRegistry.setAuthenticator(entitlementAuthenticator);
            }
        } else {
            // initialize default basic auth authenticator & OAuth authenticator and set it in the auth registry.
            BasicAuthHandler basicAuthHandler = new BasicAuthHandler();
            basicAuthHandler.setDefaultPriority();
            entitlementAuthRegistry.setAuthenticator(basicAuthHandler);
        }
    }
}
Also used : EntitlementAuthenticatorRegistry(org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthenticatorRegistry) EntitlementAuthenticationHandler(org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthenticationHandler) BasicAuthHandler(org.wso2.carbon.identity.entitlement.endpoint.auth.BasicAuthHandler) EntitlementAuthConfigReader(org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthConfigReader)

Aggregations

EntitlementAuthenticationHandler (org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthenticationHandler)2 EntitlementAuthenticatorRegistry (org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthenticatorRegistry)2 Response (javax.ws.rs.core.Response)1 BasicAuthHandler (org.wso2.carbon.identity.entitlement.endpoint.auth.BasicAuthHandler)1 EntitlementAuthConfigReader (org.wso2.carbon.identity.entitlement.endpoint.auth.EntitlementAuthConfigReader)1 UnauthorizedException (org.wso2.carbon.identity.entitlement.endpoint.exception.UnauthorizedException)1