Search in sources :

Example 1 with AuthenticationResultCacheEntry

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);
}
Also used : AuthenticationResultCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry) AuthenticationResultCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheKey)

Example 2 with AuthenticationResultCacheEntry

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;
}
Also used : AuthenticationResultCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry) AuthenticationResult(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult)

Example 3 with AuthenticationResultCacheEntry

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;
}
Also used : AuthenticationResultCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry) AuthenticationResultCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheKey)

Example 4 with AuthenticationResultCacheEntry

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);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) CommonAuthResponseWrapper(org.wso2.carbon.identity.application.authentication.framework.model.CommonAuthResponseWrapper) AuthenticationResultCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry) AuthenticationResult(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult) Test(org.testng.annotations.Test) PostAuthenticationMgtServiceTest(org.wso2.carbon.identity.application.authentication.framework.services.PostAuthenticationMgtServiceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with AuthenticationResultCacheEntry

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;
}
Also used : AuthenticationResultCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry) AuthenticationResult(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult)

Aggregations

AuthenticationResultCacheEntry (org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry)7 AuthenticationResult (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Test (org.testng.annotations.Test)3 BeforeTest (org.testng.annotations.BeforeTest)2 AuthenticationResultCacheKey (org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheKey)2 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 Response (javax.ws.rs.core.Response)1 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)1 Matchers.anyString (org.mockito.Matchers.anyString)1 AfterTest (org.testng.annotations.AfterTest)1 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)1 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)1 CommonAuthResponseWrapper (org.wso2.carbon.identity.application.authentication.framework.model.CommonAuthResponseWrapper)1 PostAuthenticationMgtServiceTest (org.wso2.carbon.identity.application.authentication.framework.services.PostAuthenticationMgtServiceTest)1 SessionDataCacheKey (org.wso2.carbon.identity.oauth.cache.SessionDataCacheKey)1