use of org.wso2.carbon.identity.common.testng.realm.MockUserStoreManager in project carbon-identity-framework by wso2.
the class MockRealm method init.
@Override
public void init(RealmConfiguration realmConfiguration, Map<String, ClaimMapping> claimMappingMap, Map<String, ProfileConfiguration> map1, int tenantId) throws UserStoreException {
this.realmConfiguration = realmConfiguration;
this.tenantId = tenantId;
DataSource dataSource = MockInitialContextFactory.initializeDatasource(UM_DB_JNDI_NAME, this.getClass(), new String[] { UM_DB_SQL_FILE });
userStoreManager = new MockUserStoreManager(dataSource);
((MockUserStoreManager) this.userStoreManager).setRealmConfiguration(this.realmConfiguration);
claimManager = new MockClaimManager(claimMappingMap);
((MockUserStoreManager) this.userStoreManager).setClaimManager(this.claimManager);
HybridRoleManager hybridRoleManager = new MockHybridRoleManager(dataSource, tenantId, realmConfiguration, this);
((MockUserStoreManager) this.userStoreManager).setHybridRoleManager(hybridRoleManager);
}
use of org.wso2.carbon.identity.common.testng.realm.MockUserStoreManager in project carbon-identity-framework by wso2.
the class ApplicationMgtUtilTest method testIsUserAuthorizedUserStoreException.
@Test
public void testIsUserAuthorizedUserStoreException() throws UserStoreException {
mockUserStoreManager();
doThrow(new UserStoreException("")).when(mockUserStoreManager).getRoleListOfUser(anyString());
assertThrows(IdentityApplicationManagementException.class, () -> ApplicationMgtUtil.isUserAuthorized(APPLICATION_NAME, USERNAME));
}
use of org.wso2.carbon.identity.common.testng.realm.MockUserStoreManager in project carbon-identity-framework by wso2.
the class ApplicationMgtUtilTest method testIsValidApplicationOwner.
@Test(dataProvider = "validApplicationOwnerDataProvider")
public void testIsValidApplicationOwner(String username, String tenantDomain, Boolean hasOwner, Boolean expected) throws IdentityApplicationManagementException, UserStoreException {
ServiceProvider serviceProvider = new ServiceProvider();
if (hasOwner) {
User user = new User();
user.setUserName(username);
user.setTenantDomain(tenantDomain);
serviceProvider.setOwner(user);
}
mockUserStoreManager();
when(mockUserStoreManager.isExistingUser(anyString())).thenReturn(FALSE);
when(mockUserRealm.getRealmConfiguration()).thenReturn(mockRealmConfiguration);
when(mockRealmConfiguration.getAdminUserName()).thenReturn("admin");
when(mockRealmConfiguration.getUserStoreProperty(anyString())).thenReturn("property");
when(mockCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN);
assertEquals(ApplicationMgtUtil.isValidApplicationOwner(serviceProvider), expected);
}
use of org.wso2.carbon.identity.common.testng.realm.MockUserStoreManager in project carbon-identity-framework by wso2.
the class CarbonBasedTestListener method createRealmService.
private RealmService createRealmService(WithRealmService withRealmService, boolean reuseIfAvailable) throws UserStoreException {
if (testSessionRealmService != null && reuseIfAvailable) {
return testSessionRealmService;
}
try {
int tenantId = withRealmService.tenantId();
String tenantDomain = withRealmService.tenantDomain();
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
testSessionRealmService = new InMemoryRealmService(tenantId);
UserStoreManager userStoreManager = testSessionRealmService.getTenantUserRealm(tenantId).getUserStoreManager();
((MockUserStoreManager) userStoreManager).addSecondaryUserStoreManager("PRIMARY", (MockUserStoreManager) userStoreManager);
IdentityTenantUtil.setRealmService(testSessionRealmService);
TenantManager tenantManager = new InMemoryTenantManager();
testSessionRealmService.setTenantManager(tenantManager);
RegistryDataHolder.getInstance().setRealmService(testSessionRealmService);
OSGiDataHolder.getInstance().setUserRealmService(testSessionRealmService);
Class[] singletonClasses = withRealmService.injectToSingletons();
for (Class singletonClass : singletonClasses) {
Object instance = getSingletonInstance(singletonClass);
if (instance != null) {
setInstanceValue(testSessionRealmService, RealmService.class, singletonClass, instance);
} else {
setInstanceValue(testSessionRealmService, RealmService.class, singletonClass, null);
}
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return testSessionRealmService;
}
use of org.wso2.carbon.identity.common.testng.realm.MockUserStoreManager in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandlerTest method testHandleWithAuthenticatedUserWithFederatedIdp.
@Test(description = "This test case tests the Post JIT provisioning handling flow with an authenticated user")
public void testHandleWithAuthenticatedUserWithFederatedIdp() throws FrameworkException, FederatedAssociationManagerException, AccountLockServiceException, UserStoreException {
AuthenticationContext context = processAndGetAuthenticationContext(sp, true, true);
FederatedAssociationManager federatedAssociationManager = mock(FederatedAssociationManagerImpl.class);
when(FrameworkUtils.getFederatedAssociationManager()).thenReturn(federatedAssociationManager);
doReturn("test").when(federatedAssociationManager).getUserForFederatedAssociation(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
when(FrameworkUtils.getStepBasedSequenceHandler()).thenReturn(Mockito.mock(StepBasedSequenceHandler.class));
mockStatic(FrameworkServiceDataHolder.class);
PowerMockito.when(FrameworkServiceDataHolder.getInstance()).thenReturn(frameworkServiceDataHolder);
mockStatic(AccountLockService.class);
when(frameworkServiceDataHolder.getAccountLockService()).thenReturn(accountLockService);
when(accountLockService.isAccountLocked(anyString(), anyString())).thenReturn(false);
RealmService mockRealmService = mock(RealmService.class);
PowerMockito.when(FrameworkServiceDataHolder.getInstance().getRealmService()).thenReturn(mockRealmService);
UserRealm mockUserRealm = mock(UserRealm.class);
UserStoreManager mockUserStoreManager = mock(UserStoreManager.class);
Map<String, String> mockClaimValues = mock(HashMap.class);
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(1);
when(mockRealmService.getTenantUserRealm(anyInt())).thenReturn(mockUserRealm);
when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager);
when(mockUserStoreManager.getUserClaimValues(anyString(), eq(new String[] { AccountConstants.ACCOUNT_DISABLED_CLAIM }), eq(UserCoreConstants.DEFAULT_PROFILE))).thenReturn(mockClaimValues);
when(mockClaimValues.get(AccountConstants.ACCOUNT_DISABLED_CLAIM)).thenReturn("false");
PostAuthnHandlerFlowStatus postAuthnHandlerFlowStatus = postJITProvisioningHandler.handle(request, response, context);
Assert.assertEquals(postAuthnHandlerFlowStatus, PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED, "Post JIT provisioning handler executed while having a authenticated user without federated " + "authenticator");
}
Aggregations