use of org.wso2.carbon.identity.oauth2.dao.AccessTokenDAO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthAdminServiceImplTest method testRevokeIssuedTokensByApplication.
@Test
public void testRevokeIssuedTokensByApplication() throws Exception {
String userId = UUID.randomUUID().toString();
String consumerKey = UUID.randomUUID().toString();
String accessToken = UUID.randomUUID().toString();
String refreshToken = UUID.randomUUID().toString();
OAuthAppDO oAuthAppDO = new OAuthAppDO();
oAuthAppDO.setOauthConsumerKey(consumerKey);
oAuthAppDO.setApplicationName("some-user-name");
when(oAuthAppDAO.getAppInformation(consumerKey)).thenReturn(oAuthAppDO);
PowerMockito.whenNew(OAuthAppDAO.class).withNoArguments().thenReturn(oAuthAppDAO);
AuthenticatedUser user = buildUser("some-user-name");
user.setUserId(userId);
user.setFederatedIdPName(TestConstants.LOCAL_IDP);
OAuthAppRevocationRequestDTO oAuthAppRevocationRequestDTO = new OAuthAppRevocationRequestDTO();
oAuthAppRevocationRequestDTO.setConsumerKey(consumerKey);
AccessTokenDO dummyToken = new AccessTokenDO();
dummyToken.setAccessToken(accessToken);
dummyToken.setRefreshToken(refreshToken);
dummyToken.setAuthzUser(user);
dummyToken.setScope(new String[] { "openid" });
Set<AccessTokenDO> accessTokenDOSet = new HashSet<>();
accessTokenDOSet.add(dummyToken);
OAuthTokenPersistenceFactory tokenPersistenceFactory = OAuthTokenPersistenceFactory.getInstance();
TokenManagementDAOImpl mockTokenManagementDAOImpl = mock(TokenManagementDAOImpl.class);
Whitebox.setInternalState(tokenPersistenceFactory, "managementDAO", mockTokenManagementDAOImpl);
AccessTokenDAO mockAccessTokenDAO = mock(AccessTokenDAO.class);
Whitebox.setInternalState(tokenPersistenceFactory, "tokenDAO", mockAccessTokenDAO);
when(mockAccessTokenDAO.getActiveAcessTokenDataByConsumerKey(anyString())).thenReturn(accessTokenDOSet);
OAuthRevocationResponseDTO expectedOAuthRevocationResponseDTO = new OAuthRevocationResponseDTO();
expectedOAuthRevocationResponseDTO.setError(false);
ApplicationManagementService appMgtService = mock(ApplicationManagementService.class);
when(appMgtService.getServiceProviderNameByClientId(consumerKey, INBOUND_AUTH2_TYPE, user.getTenantDomain())).thenReturn(oAuthAppDO.getApplicationName());
OAuth2ServiceComponentHolder.setApplicationMgtService(appMgtService);
OAuthAdminServiceImpl oAuthAdminServiceImpl = spy(new OAuthAdminServiceImpl());
doNothing().when(oAuthAdminServiceImpl, "triggerPreApplicationTokenRevokeListeners", anyObject());
doNothing().when(oAuthAdminServiceImpl, "triggerPostApplicationTokenRevokeListeners", anyObject(), anyObject(), anyObject());
OAuthRevocationResponseDTO actualOAuthRevocationResponseDTO = oAuthAdminServiceImpl.revokeIssuedTokensByApplication(oAuthAppRevocationRequestDTO);
Assert.assertEquals(actualOAuthRevocationResponseDTO.isError(), expectedOAuthRevocationResponseDTO.isError());
}
use of org.wso2.carbon.identity.oauth2.dao.AccessTokenDAO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ServiceTest method testRevokeTokenByOAuthClientWithAccessToken.
@Test
public void testRevokeTokenByOAuthClientWithAccessToken() throws Exception {
setUpRevokeToken();
AccessTokenDO accessTokenDO = getAccessToken();
TokenBinding tokenBinding = new TokenBinding();
tokenBinding.setBindingReference("dummyReference");
accessTokenDO.setTokenBinding(tokenBinding);
when(OAuth2Util.findAccessToken(anyString(), anyBoolean())).thenReturn(accessTokenDO);
OAuthTokenPersistenceFactory oAuthTokenPersistenceFactory = OAuthTokenPersistenceFactory.getInstance();
TokenManagementDAOImpl mockTokenManagementDAOImpl = mock(TokenManagementDAOImpl.class);
Whitebox.setInternalState(oAuthTokenPersistenceFactory, "managementDAO", mockTokenManagementDAOImpl);
AccessTokenDAO mockAccessTokenDAO = mock(AccessTokenDAO.class);
Whitebox.setInternalState(oAuthTokenPersistenceFactory, "tokenDAO", mockAccessTokenDAO);
when(mockAccessTokenDAO.getAccessToken(anyString(), anyBoolean())).thenReturn(accessTokenDO);
OAuthAppDO oAuthAppDO = new OAuthAppDO();
when(OAuth2Util.getAppInformationByClientId(anyString())).thenReturn(oAuthAppDO);
OAuthRevocationRequestDTO revokeRequestDTO = getOAuthRevocationRequestDTO();
oAuth2Service.revokeTokenByOAuthClient(revokeRequestDTO);
assertFalse(oAuth2Service.revokeTokenByOAuthClient(revokeRequestDTO).isError());
}
use of org.wso2.carbon.identity.oauth2.dao.AccessTokenDAO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2UtilTest method getAccessTokenDOFromTokenIdentifier.
private AccessTokenDO getAccessTokenDOFromTokenIdentifier(boolean isCacheAvailable) throws Exception {
when(oauthServerConfigurationMock.getPersistenceProcessor()).thenReturn(new PlainTextPersistenceProcessor());
AccessTokenDO accessTokenDO = new AccessTokenDO();
accessTokenDO.setConsumerKey("dummyConsumerKey");
mockStatic(OAuthCache.class);
when(OAuthCache.getInstance()).thenReturn(oAuthCacheMock);
if (isCacheAvailable) {
when(oAuthCacheMock.getValueFromCache(any(OAuthCacheKey.class))).thenReturn(accessTokenDO);
} else {
WhiteboxImpl.setInternalState(OAuthTokenPersistenceFactory.getInstance(), "tokenDAO", accessTokenDAO);
when(accessTokenDAO.getAccessToken(anyString(), anyBoolean())).thenReturn(accessTokenDO);
}
when(oauthServerConfigurationMock.isClientSecretHashEnabled()).thenReturn(false);
return accessTokenDO;
}
Aggregations