use of org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthServiceComponent method activate.
protected void activate(ComponentContext context) {
try {
// initialize the OAuth Server configuration
OAuthServerConfiguration oauthServerConfig = OAuthServerConfiguration.getInstance();
if (OAuthCache.getInstance().isEnabled()) {
log.debug("OAuth Caching is enabled. Initializing the cache.");
}
IdentityOathEventListener listener = new IdentityOathEventListener();
serviceRegistration = context.getBundleContext().registerService(UserOperationEventListener.class.getName(), listener, null);
log.debug("Identity Oath Event Listener is enabled");
context.getBundleContext().registerService(AbstractEventHandler.class.getName(), new IdentityOauthEventHandler(), null);
if (log.isDebugEnabled()) {
log.debug("Identity Oauth Event handler is enabled");
}
OAuth2Service oauth2Service = new OAuth2Service();
context.getBundleContext().registerService(OAuth2Service.class.getName(), oauth2Service, null);
OAuthComponentServiceHolder.getInstance().setOauth2Service(oauth2Service);
// We need to explicitly populate the OAuthTokenIssuerMap since it's used for token validation.
oauthServerConfig.populateOAuthTokenIssuerMap();
OAuthAdminServiceImpl oauthAdminService = new OAuthAdminServiceImpl();
OAuthComponentServiceHolder.getInstance().setOAuthAdminService(oauthAdminService);
OAuth2ServiceComponentHolder.getInstance().setOAuthAdminService(oauthAdminService);
context.getBundleContext().registerService(OAuthEventInterceptor.class, new OAuthTokenSessionMappingEventHandler(), null);
if (log.isDebugEnabled()) {
log.debug("OAuthTokenSessionMapping Event Handler is enabled");
}
context.getBundleContext().registerService(OAuthAdminServiceImpl.class.getName(), oauthAdminService, null);
if (log.isDebugEnabled()) {
log.debug("Identity OAuth bundle is activated");
}
} catch (Throwable e) {
String errMsg = "Error occurred while activating OAuth Service Component";
log.error(errMsg, e);
throw new RuntimeException(errMsg, e);
}
}
use of org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthAdminServiceImplTest method testValidateAudiencesWithValidAudiences.
@Test(description = "Test validating invalid audiences", dataProvider = "validAudienceDataProvider")
public void testValidateAudiencesWithValidAudiences(String[] validaAudience) throws Exception {
OAuthConsumerAppDTO appDTO = new OAuthConsumerAppDTO();
appDTO.setAudiences(validaAudience);
OAuthAdminServiceImpl oAuthAdminService = new OAuthAdminServiceImpl();
invokeMethod(oAuthAdminService, "validateAudiences", appDTO);
}
use of org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthAdminServiceImplTest method testGetAllOAuthApplicationData.
@Test
public void testGetAllOAuthApplicationData() throws Exception {
String username = "Moana";
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain("carbon.super");
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username);
OAuthAppDO app = buildDummyOAuthAppDO(username);
when(oAuthAppDAO.getOAuthConsumerAppsOfUser(username, tenantId)).thenReturn(new OAuthAppDO[] { app });
whenNew(OAuthAppDAO.class).withAnyArguments().thenReturn(oAuthAppDAO);
OAuthAdminServiceImpl oAuthAdminServiceImpl = new OAuthAdminServiceImpl();
OAuthConsumerAppDTO[] oAuthConsumerApps = oAuthAdminServiceImpl.getAllOAuthApplicationData();
Assert.assertTrue((oAuthConsumerApps.length == 1), "OAuth consumer application count should be one.");
assertAllAttributesOfConsumerAppDTO(oAuthConsumerApps[0], app);
}
use of org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthAdminServiceImplTest method testGetAllOAuthApplicationData.
@Test(dataProvider = "getDataForAllOAuthApplicationData")
public void testGetAllOAuthApplicationData(String userName) throws Exception {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain("carbon.super");
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(-1234);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
whenNew(OAuthAppDAO.class).withNoArguments().thenReturn(oAuthAppDAO);
OAuthAppDO oAuthAppDO = new OAuthAppDO();
AuthenticatedUser authenticatedUser = new AuthenticatedUser();
oAuthAppDO.setApplicationName("testapp1");
oAuthAppDO.setUser(authenticatedUser);
authenticatedUser.setUserName(userName);
when(oAuthAppDAO.getOAuthConsumerAppsOfUser(userName, -1234)).thenReturn(new OAuthAppDO[] { oAuthAppDO });
OAuthAdminServiceImpl oAuthAdminServiceImpl = new OAuthAdminServiceImpl();
try {
OAuthConsumerAppDTO[] allOAuthApplicationData = oAuthAdminServiceImpl.getAllOAuthApplicationData();
Assert.assertNotNull(allOAuthApplicationData);
Assert.assertEquals(allOAuthApplicationData.length, 1);
Assert.assertEquals(allOAuthApplicationData[0].getApplicationName(), "testapp1");
} catch (IdentityOAuthAdminException allOAuthApplicationData) {
Assert.assertEquals(allOAuthApplicationData.getMessage(), "User not logged in to get all registered OAuth Applications.");
}
}
use of org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl 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());
}
Aggregations