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