Search in sources :

Example 1 with ClaimCache

use of org.wso2.carbon.identity.oauth.util.ClaimCache in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListener method removeClaimCacheEntry.

/**
 * Remove ClaimCache Entry if available.
 *
 * @param username
 * @param userStoreManager
 */
private void removeClaimCacheEntry(String username, UserStoreManager userStoreManager) throws UserStoreException {
    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.setUserName(username);
    authenticatedUser.setTenantDomain(IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId()));
    authenticatedUser.setUserStoreDomain(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration()));
    ClaimMetaDataCacheEntry cacheEntry = ClaimMetaDataCache.getInstance().getValueFromCache(new ClaimMetaDataCacheKey(authenticatedUser), IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId()));
    if (cacheEntry == null) {
        return;
    }
    ClaimCache.getInstance().clearCacheEntry(cacheEntry.getClaimCacheKey(), IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId()));
}
Also used : ClaimMetaDataCacheEntry(org.wso2.carbon.identity.oauth.util.ClaimMetaDataCacheEntry) ClaimMetaDataCacheKey(org.wso2.carbon.identity.oauth.util.ClaimMetaDataCacheKey) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)

Example 2 with ClaimCache

use of org.wso2.carbon.identity.oauth.util.ClaimCache in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuthUtil method removeUserClaimsFromCache.

/**
 * Remove user claims from ClaimCache
 *
 * @param userName
 */
public static boolean removeUserClaimsFromCache(String userName, UserStoreManager userStoreManager) throws UserStoreException {
    ClaimCache claimCache = ClaimCache.getInstance();
    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.setUserName(userName);
    authenticatedUser.setTenantDomain(IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId()));
    authenticatedUser.setUserStoreDomain(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration()));
    ClaimCacheKey cacheKey = new ClaimCacheKey(authenticatedUser);
    if (cacheKey != null) {
        claimCache.clearCacheEntry(cacheKey, userStoreManager.getTenantId());
    }
    return true;
}
Also used : ClaimCache(org.wso2.carbon.identity.oauth.util.ClaimCache) ClaimCacheKey(org.wso2.carbon.identity.oauth.util.ClaimCacheKey) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)

Example 3 with ClaimCache

use of org.wso2.carbon.identity.oauth.util.ClaimCache in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListenerTest method testDoPostUpdateCredentialByAdmin.

@Test
public void testDoPostUpdateCredentialByAdmin() throws Exception {
    IdentityEventListenerConfig listenerConfig = mock(IdentityEventListenerConfig.class);
    IdentityCacheConfig identityCacheConfig = mock(IdentityCacheConfig.class);
    ClaimCache claimCache = mock(ClaimCache.class);
    OAuthServerConfiguration mockedServerConfig = mock(OAuthServerConfiguration.class);
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(listenerConfig);
    when(StringUtils.isNotBlank(anyString())).thenReturn(true);
    IdentityOathEventListener ioeListener = new IdentityOathEventListener();
    assertTrue(ioeListener.doPostUpdateCredentialByAdmin(username, new Object(), userStoreManager));
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(null);
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    when(IdentityUtil.getIdentityCacheConfig(anyString(), anyString())).thenReturn(identityCacheConfig);
    when(claimCache.isEnabled()).thenReturn(false);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockedServerConfig);
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPostUpdateCredentialByAdmin(username, new Object(), userStoreManager));
}
Also used : IdentityCacheConfig(org.wso2.carbon.identity.core.model.IdentityCacheConfig) ClaimCache(org.wso2.carbon.identity.oauth.util.ClaimCache) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 4 with ClaimCache

use of org.wso2.carbon.identity.oauth.util.ClaimCache in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListenerTest method testDoPostSetUserClaimValue.

@Test
public void testDoPostSetUserClaimValue() throws Exception {
    IdentityEventListenerConfig listenerConfig = mock(IdentityEventListenerConfig.class);
    IdentityCacheConfig identityCacheConfig = mock(IdentityCacheConfig.class);
    ClaimCache claimCache = mock(ClaimCache.class);
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(listenerConfig);
    when(StringUtils.isNotBlank(anyString())).thenReturn(true);
    assertTrue(identityOathEventListener.doPostSetUserClaimValue(username, userStoreManager));
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(null);
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    when(IdentityUtil.getIdentityCacheConfig(anyString(), anyString())).thenReturn(identityCacheConfig);
    when(claimCache.isEnabled()).thenReturn(false);
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPostSetUserClaimValue(username, userStoreManager));
}
Also used : IdentityCacheConfig(org.wso2.carbon.identity.core.model.IdentityCacheConfig) ClaimCache(org.wso2.carbon.identity.oauth.util.ClaimCache) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 5 with ClaimCache

use of org.wso2.carbon.identity.oauth.util.ClaimCache in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListenerTest method testDoPostAuthenticate.

@Test
public void testDoPostAuthenticate() throws Exception {
    IdentityEventListenerConfig listenerConfig = mock(IdentityEventListenerConfig.class);
    IdentityCacheConfig identityCacheConfig = mock(IdentityCacheConfig.class);
    ClaimCache claimCache = mock(ClaimCache.class);
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(listenerConfig);
    when(StringUtils.isNotBlank(anyString())).thenReturn(true);
    assertTrue(identityOathEventListener.doPostAuthenticate(username, true, userStoreManager));
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(null);
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    when(IdentityUtil.getIdentityCacheConfig(anyString(), anyString())).thenReturn(identityCacheConfig);
    when(claimCache.isEnabled()).thenReturn(false);
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPostAuthenticate(username, true, userStoreManager));
}
Also used : IdentityCacheConfig(org.wso2.carbon.identity.core.model.IdentityCacheConfig) ClaimCache(org.wso2.carbon.identity.oauth.util.ClaimCache) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Aggregations

ClaimCache (org.wso2.carbon.identity.oauth.util.ClaimCache)9 Test (org.testng.annotations.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 IdentityCacheConfig (org.wso2.carbon.identity.core.model.IdentityCacheConfig)7 IdentityEventListenerConfig (org.wso2.carbon.identity.core.model.IdentityEventListenerConfig)7 IdentityBaseTest (org.wso2.carbon.identity.testutil.IdentityBaseTest)7 OAuthServerConfiguration (org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration)4 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)2 Key (java.security.Key)1 Certificate (java.security.cert.Certificate)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Matchers.anyString (org.mockito.Matchers.anyString)1 AfterTest (org.testng.annotations.AfterTest)1 BeforeTest (org.testng.annotations.BeforeTest)1 ClaimCacheKey (org.wso2.carbon.identity.oauth.util.ClaimCacheKey)1 ClaimMetaDataCacheEntry (org.wso2.carbon.identity.oauth.util.ClaimMetaDataCacheEntry)1 ClaimMetaDataCacheKey (org.wso2.carbon.identity.oauth.util.ClaimMetaDataCacheKey)1 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)1 OAuth2Util (org.wso2.carbon.identity.oauth2.util.OAuth2Util)1