Search in sources :

Example 6 with AuthenticationRequestCacheEntry

use of org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCLogoutServlet method sendToFrameworkForLogout.

private void sendToFrameworkForLogout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        triggerLogoutHandlersForPreLogout(request, response);
    } catch (OIDCSessionManagementException e) {
        log.error("Error executing logout handlers on pre logout.");
        if (log.isDebugEnabled()) {
            log.debug("Error executing logout handlers on pre logout.", e);
        }
        response.sendRedirect(getRedirectURL(getErrorPageURL(OAuth2ErrorCodes.SERVER_ERROR, "User logout failed."), request));
    }
    // Generate a SessionDataKey. Authentication framework expects this parameter
    String sessionDataKey = UUID.randomUUID().toString();
    String opBrowserStateCookieValue = OIDCSessionManagementUtil.getOPBrowserStateCookie(request).getValue();
    // Add all parameters to authentication context before sending to authentication framework
    AuthenticationRequest authenticationRequest = new AuthenticationRequest();
    Map<String, String[]> map = new HashMap<>();
    map.put(OIDCSessionConstants.OIDC_SESSION_DATA_KEY_PARAM, new String[] { sessionDataKey });
    authenticationRequest.setRequestQueryParams(map);
    authenticationRequest.addRequestQueryParam(FrameworkConstants.RequestParams.LOGOUT, new String[] { "true" });
    try {
        authenticationRequest.setCommonAuthCallerPath(ServiceURLBuilder.create().addPath(OIDC_LOGOUT_ENDPOINT).build().getRelativeInternalURL());
    } catch (URLBuilderException e) {
        log.error("Error building commonauth caller path to send logout request to framework.", e);
        response.sendRedirect(getRedirectURL(getErrorPageURL(OAuth2ErrorCodes.SERVER_ERROR, "User logout failed."), request));
    }
    authenticationRequest.setPost(true);
    OIDCSessionDataCacheEntry cacheEntry = getSessionDataFromCache(opBrowserStateCookieValue);
    if (cacheEntry != null) {
        authenticationRequest.setRelyingParty(cacheEntry.getParamMap().get(OIDCSessionConstants.OIDC_CACHE_CLIENT_ID_PARAM));
        authenticationRequest.setTenantDomain(cacheEntry.getParamMap().get(OIDCSessionConstants.OIDC_CACHE_TENANT_DOMAIN_PARAM));
        addOPBSCookieValueToCacheEntry(opBrowserStateCookieValue, cacheEntry);
        addSessionDataToCache(sessionDataKey, cacheEntry);
    }
    // Add headers to AuthenticationRequestContext
    for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); ) {
        String headerName = e.nextElement().toString();
        authenticationRequest.addHeader(headerName, request.getHeader(headerName));
    }
    AuthenticationRequestCacheEntry authenticationRequestCacheEntry = new AuthenticationRequestCacheEntry(authenticationRequest);
    addAuthenticationRequestToRequest(request, authenticationRequestCacheEntry);
    OIDCSessionManagementUtil.removeOPBrowserStateCookie(request, response);
    sendRequestToFramework(request, response, sessionDataKey, FrameworkConstants.RequestType.CLAIM_TYPE_OIDC);
}
Also used : URLBuilderException(org.wso2.carbon.identity.core.URLBuilderException) Enumeration(java.util.Enumeration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) OIDCSessionDataCacheEntry(org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheEntry) AuthenticationRequest(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationRequest) OIDCSessionManagementException(org.wso2.carbon.identity.oidc.session.OIDCSessionManagementException) AuthenticationRequestCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheEntry)

Example 7 with AuthenticationRequestCacheEntry

use of org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.

the class EndpointUtil method buildAuthenticationRequestCacheEntry.

private static AuthenticationRequestCacheEntry buildAuthenticationRequestCacheEntry(String clientId, boolean forceAuthenticate, boolean checkAuthentication, Map<String, String[]> reqParams) throws IdentityOAuth2Exception, URLBuilderException {
    AuthenticationRequest authenticationRequest = new AuthenticationRequest();
    int tenantId = OAuth2Util.getClientTenatId();
    // Build the authentication request context.
    String commonAuthCallerPath = ServiceURLBuilder.create().addPath(OAUTH2_AUTHORIZE).build().getRelativeInternalURL();
    authenticationRequest.setCommonAuthCallerPath(commonAuthCallerPath);
    authenticationRequest.setForceAuth(forceAuthenticate);
    authenticationRequest.setPassiveAuth(checkAuthentication);
    authenticationRequest.setRelyingParty(clientId);
    authenticationRequest.setTenantDomain(OAuth2Util.getTenantDomain(tenantId));
    authenticationRequest.setRequestQueryParams(reqParams);
    // Build an AuthenticationRequestCacheEntry which wraps AuthenticationRequestContext
    return new AuthenticationRequestCacheEntry(authenticationRequest);
}
Also used : AuthenticationRequest(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationRequest) AuthenticationRequestCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheEntry)

Aggregations

AuthenticationRequestCacheEntry (org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheEntry)5 AuthenticationRequest (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationRequest)5 HashMap (java.util.HashMap)4 Map (java.util.Map)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AuthenticationResultCacheEntry (org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry)2 Enumeration (java.util.Enumeration)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AuthenticationRequestCacheKey (org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheKey)1 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)1 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)1 JsFailureException (org.wso2.carbon.identity.application.authentication.framework.exception.JsFailureException)1 MisconfigurationException (org.wso2.carbon.identity.application.authentication.framework.exception.MisconfigurationException)1 PostAuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)1 AuthenticationFrameworkWrapper (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationFrameworkWrapper)1 CommonAuthResponseWrapper (org.wso2.carbon.identity.application.authentication.framework.model.CommonAuthResponseWrapper)1 URLBuilderException (org.wso2.carbon.identity.core.URLBuilderException)1 OIDCSessionManagementException (org.wso2.carbon.identity.oidc.session.OIDCSessionManagementException)1 OIDCSessionDataCacheEntry (org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheEntry)1