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);
}
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);
}
Aggregations