use of org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry in project carbon-identity-framework by wso2.
the class FrameworkUtils method addAuthenticationResultToCache.
/**
* @param key
* @param authenticationResult
*/
public static void addAuthenticationResultToCache(String key, AuthenticationResult authenticationResult) {
AuthenticationResultCacheKey cacheKey = new AuthenticationResultCacheKey(key);
AuthenticationResultCacheEntry cacheEntry = new AuthenticationResultCacheEntry();
cacheEntry.setResult(authenticationResult);
cacheEntry.setValidityPeriod(TimeUnit.MINUTES.toNanos(IdentityUtil.getOperationCleanUpTimeout()));
AuthenticationResultCache.getInstance().addToCache(cacheKey, cacheEntry);
}
use of org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2AuthzEndpoint method getAuthenticationResultFromCache.
private AuthenticationResult getAuthenticationResultFromCache(String sessionDataKey) {
AuthenticationResult authResult = null;
AuthenticationResultCacheEntry authResultCacheEntry = FrameworkUtils.getAuthenticationResultFromCache(sessionDataKey);
if (authResultCacheEntry != null) {
authResult = authResultCacheEntry.getResult();
} else {
log.error("Cannot find AuthenticationResult from the cache");
}
return authResult;
}
use of org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry in project carbon-identity-framework by wso2.
the class FrameworkUtils method getAuthenticationResultFromCache.
/**
* To get authentication cache result from cache.
* @param key
* @return
*/
public static AuthenticationResultCacheEntry getAuthenticationResultFromCache(String key) {
AuthenticationResultCacheKey cacheKey = new AuthenticationResultCacheKey(key);
AuthenticationResultCacheEntry authResult = AuthenticationResultCache.getInstance().getValueFromCache(cacheKey);
return authResult;
}
use of org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry in project carbon-identity-framework by wso2.
the class DefaultAuthenticationRequestHandlerTest method testPopulateErrorInformation.
@Test(dataProvider = "errorInfoDataProvider")
public void testPopulateErrorInformation(String errorCode, String errorMessage, String errorUri, String requestType) throws Exception {
AuthenticationResult authenticationResult = new AuthenticationResult();
doReturn(authenticationResult).when(request).getAttribute(FrameworkConstants.RequestAttribute.AUTH_RESULT);
// Populate the context with error details
AuthenticationContext context = new AuthenticationContext();
context.setProperty(FrameworkConstants.AUTH_ERROR_CODE, errorCode);
context.setProperty(FrameworkConstants.AUTH_ERROR_MSG, errorMessage);
context.setProperty(FrameworkConstants.AUTH_ERROR_URI, errorUri);
// request type is does not cache authentication result
context.setRequestType(requestType);
response = spy(new CommonAuthResponseWrapper(response));
// if request type caches authentication result we need to mock required dependent objects
AuthenticationResultCacheEntry cacheEntry = spy(new AuthenticationResultCacheEntry());
when(cacheEntry.getResult()).thenReturn(authenticationResult);
mockStatic(FrameworkUtils.class);
when(FrameworkUtils.getAuthenticationResultFromCache(anyString())).thenReturn(cacheEntry);
authenticationRequestHandler.populateErrorInformation(request, response, context);
// Assert stuff
AuthenticationResult modifiedAuthenticationResult = (AuthenticationResult) request.getAttribute(FrameworkConstants.RequestAttribute.AUTH_RESULT);
assertNotNull(modifiedAuthenticationResult);
assertEquals(modifiedAuthenticationResult.getProperty(FrameworkConstants.AUTH_ERROR_CODE), errorCode);
assertEquals(modifiedAuthenticationResult.getProperty(FrameworkConstants.AUTH_ERROR_MSG), errorMessage);
assertEquals(modifiedAuthenticationResult.getProperty(FrameworkConstants.AUTH_ERROR_URI), errorUri);
}
use of org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry in project carbon-identity-framework by wso2.
the class IdentityProcessor method processResponseFromFrameworkLogin.
/**
* Processes the IdentityMessageContext and retrieved the using {@code sessionDataKey} parameter and sets the
* AuthenticationResult to message context if found in AuthenticationResultCache
*
* @param context IdentityMessageContext
* @param identityRequest Current IdentityRequest object
* @return AuthenticationResult
*/
protected AuthenticationResult processResponseFromFrameworkLogin(IdentityMessageContext context, IdentityRequest identityRequest) {
String sessionDataKey = identityRequest.getParameter(InboundConstants.RequestProcessor.CONTEXT_KEY);
AuthenticationResultCacheEntry entry = FrameworkUtils.getAuthenticationResultFromCache(sessionDataKey);
AuthenticationResult authnResult = null;
if (entry != null) {
authnResult = entry.getResult();
} else {
throw FrameworkRuntimeException.error("Cannot find AuthenticationResult from the cache");
}
FrameworkUtils.removeAuthenticationResultFromCache(sessionDataKey);
if (authnResult.isAuthenticated()) {
context.addParameter(InboundConstants.RequestProcessor.AUTHENTICATION_RESULT, authnResult);
}
return authnResult;
}
Aggregations