Search in sources :

Example 1 with OIDCSessionDataCacheKey

use of org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheKey in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCLogoutServlet method removeSessionDataFromCache.

private void removeSessionDataFromCache(String sessionDataKey) {
    OIDCSessionDataCacheKey cacheKey = new OIDCSessionDataCacheKey(sessionDataKey);
    OIDCSessionDataCache.getInstance().clearCacheEntry(cacheKey);
}
Also used : OIDCSessionDataCacheKey(org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheKey)

Example 2 with OIDCSessionDataCacheKey

use of org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheKey in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCLogoutServletTest method testDoGet.

@Test(dataProvider = "provideDataForTestDoGet")
public void testDoGet(Object cookie, boolean sessionExists, String redirectUrl, String expected, String consent, String sessionDataKey, boolean skipUserConsent, String idTokenHint, boolean isJWTSignedWithSPKey, String postLogoutUrl, Object flowStatus) throws Exception {
    TestUtil.startTenantFlow(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    mockStatic(OIDCSessionManagementUtil.class);
    when(OIDCSessionManagementUtil.handleAlreadyLoggedOutSessionsGracefully()).thenReturn(false);
    when(OIDCSessionManagementUtil.getOPBrowserStateCookie(request)).thenReturn((Cookie) cookie);
    when(OIDCSessionManagementUtil.getErrorPageURL(anyString(), anyString())).thenReturn(redirectUrl);
    mockStatic(OIDCSessionManager.class);
    when(OIDCSessionManagementUtil.getSessionManager()).thenReturn(oidcSessionManager);
    when(oidcSessionManager.sessionExists(OPBROWSER_STATE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(sessionExists);
    when(request.getParameter("consent")).thenReturn(consent);
    when(request.getHeaderNames()).thenReturn(Collections.enumeration(Arrays.asList(new String[] { "cookie" })));
    when(request.getHeader("COOKIE")).thenReturn("opbs");
    when(request.getAttribute(FrameworkConstants.RequestParams.FLOW_STATUS)).thenReturn(flowStatus);
    doThrow(new ServletException()).when(commonAuthenticationHandler).doPost(request, response);
    when(request.getSession()).thenReturn(httpSession);
    when(httpSession.getMaxInactiveInterval()).thenReturn(2);
    mockStatic(IdentityConfigParser.class);
    when(IdentityConfigParser.getInstance()).thenReturn(identityConfigParser);
    when(request.getParameter("sessionDataKey")).thenReturn(sessionDataKey);
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(oAuthServerConfiguration);
    when(oAuthServerConfiguration.getOpenIDConnectSkipLogoutConsentConfig()).thenReturn(skipUserConsent);
    when(request.getParameter("id_token_hint")).thenReturn(idTokenHint);
    when(OIDCSessionManagementUtil.removeOPBrowserStateCookie(any(HttpServletRequest.class), any(HttpServletResponse.class))).thenReturn((Cookie) cookie);
    when(OIDCSessionManagementUtil.getOIDCLogoutConsentURL()).thenReturn(redirectUrl);
    when(OIDCSessionManagementUtil.getOIDCLogoutURL()).thenReturn(redirectUrl);
    mockStatic(IdentityTenantUtil.class);
    when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(TENANT_ID);
    when(IdentityTenantUtil.getTenantDomain(TENANT_ID)).thenReturn(SUPER_TENANT_DOMAIN_NAME);
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(oAuthServerConfiguration);
    when(oAuthServerConfiguration.isJWTSignedWithSPKey()).thenReturn(isJWTSignedWithSPKey);
    mockStatic(KeyStoreManager.class);
    when(KeyStoreManager.getInstance(TENANT_ID)).thenReturn(keyStoreManager);
    when(keyStoreManager.getDefaultPublicKey()).thenReturn(TestUtil.getPublicKey(TestUtil.loadKeyStoreFromFileSystem(TestUtil.getFilePath("wso2carbon.jks"), "wso2carbon", "JKS"), "wso2carbon"));
    mockStatic(OIDCSessionManagementComponentServiceHolder.class);
    when(OIDCSessionManagementComponentServiceHolder.getApplicationMgtService()).thenReturn(mockedApplicationManagementService);
    when(mockedApplicationManagementService.getServiceProviderNameByClientId(anyString(), anyString(), anyString())).thenReturn("SP1");
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(oAuthServerConfiguration);
    when(oAuthServerConfiguration.getPersistenceProcessor()).thenReturn(tokenPersistenceProcessor);
    when(tokenPersistenceProcessor.getProcessedClientId(anyString())).thenAnswer(invocation -> invocation.getArguments()[0]);
    when(request.getParameter("post_logout_redirect_uri")).thenReturn(postLogoutUrl);
    mockStatic(IdentityDatabaseUtil.class);
    when(IdentityDatabaseUtil.getDBConnection()).thenAnswer(invocationOnMock -> dataSource.getConnection());
    mockStatic(OAuth2Util.class);
    when(OAuth2Util.getAppInformationByClientId(anyString())).thenCallRealMethod();
    when(OAuth2Util.getTenantDomainOfOauthApp(anyString())).thenReturn("wso2.com");
    when(OAuth2Util.getTenantDomainOfOauthApp(any(oAuthAppDO.getClass()))).thenReturn("wso2.com");
    when(keyStoreManager.getKeyStore(anyString())).thenReturn(TestUtil.loadKeyStoreFromFileSystem(TestUtil.getFilePath("wso2carbon.jks"), "wso2carbon", "JKS"));
    mockServiceURLBuilder(OIDCSessionConstants.OIDCEndpoints.OIDC_LOGOUT_ENDPOINT);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    mockStatic(OIDCSessionDataCache.class);
    when(OIDCSessionDataCache.getInstance()).thenReturn(oidcSessionDataCache);
    OIDCSessionDataCacheKey opbsKey = mock(OIDCSessionDataCacheKey.class);
    OIDCSessionDataCacheKey sessionIdKey = mock(OIDCSessionDataCacheKey.class);
    when(opbsKey.getSessionDataId()).thenReturn(OPBROWSER_STATE);
    when(sessionIdKey.getSessionDataId()).thenReturn(sessionDataKey);
    when(OIDCSessionDataCache.getInstance().getValueFromCache(opbsKey)).thenReturn(opbsCacheEntry);
    when(OIDCSessionDataCache.getInstance().getValueFromCache(sessionIdKey)).thenReturn(sessionIdCacheEntry);
    ConcurrentMap<String, String> paramMap = new ConcurrentHashMap<>();
    paramMap.put(OIDCSessionConstants.OIDC_CACHE_CLIENT_ID_PARAM, CLIENT_ID_VALUE);
    paramMap.put(OIDCSessionConstants.OIDC_CACHE_TENANT_DOMAIN_PARAM, SUPER_TENANT_DOMAIN_NAME);
    when(opbsCacheEntry.getParamMap()).thenReturn(paramMap);
    when(sessionIdCacheEntry.getParamMap()).thenReturn(paramMap);
    logoutServlet.doGet(request, response);
    verify(response).sendRedirect(captor.capture());
    assertTrue(captor.getValue().contains(expected));
}
Also used : ServletException(javax.servlet.ServletException) HttpServletRequest(javax.servlet.http.HttpServletRequest) OIDCSessionDataCacheKey(org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheKey) HttpServletResponse(javax.servlet.http.HttpServletResponse) Matchers.anyString(org.mockito.Matchers.anyString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with OIDCSessionDataCacheKey

use of org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheKey in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCLogoutServlet method addSessionDataToCache.

private void addSessionDataToCache(String sessionDataKey, OIDCSessionDataCacheEntry cacheEntry) {
    OIDCSessionDataCacheKey cacheKey = new OIDCSessionDataCacheKey(sessionDataKey);
    OIDCSessionDataCache.getInstance().addToCache(cacheKey, cacheEntry);
}
Also used : OIDCSessionDataCacheKey(org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheKey)

Aggregations

OIDCSessionDataCacheKey (org.wso2.carbon.identity.oidc.session.cache.OIDCSessionDataCacheKey)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Matchers.anyString (org.mockito.Matchers.anyString)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 AfterTest (org.testng.annotations.AfterTest)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1