use of org.wso2.carbon.user.core.UserStoreManager in project carbon-apimgt by wso2.
the class APIUtilTest method testGetRoleNamesNonSuperTenant.
@Test
public void testGetRoleNamesNonSuperTenant() throws Exception {
String userName = "John";
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
String[] roleNames = { "role1", "role2" };
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(MultitenantUtils.class);
Mockito.when(MultitenantUtils.getTenantDomain(userName)).thenReturn("test.com");
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
Mockito.when(userStoreManager.getRoleNames()).thenReturn(roleNames);
Assert.assertEquals(roleNames, APIUtil.getRoleNames(userName));
}
use of org.wso2.carbon.user.core.UserStoreManager in project carbon-apimgt by wso2.
the class UserSignUpSimpleWorkflowExecutorTest method testExecutingUserSignUpSimpleWorkflow.
@Test
public void testExecutingUserSignUpSimpleWorkflow() throws APIManagementException, UserStoreException {
Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
roleMap.put(signUpRole, false);
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
userRegistrationConfigDTO.setAdminUserName("admin");
userRegistrationConfigDTO.setAdminPassword("admin");
userRegistrationConfigDTO.setRoles(roleMap);
PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
PowerMockito.when(SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO)).thenCallRealMethod();
Mockito.when(userStoreManager.isExistingUser(username)).thenReturn(true);
Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(true);
Mockito.doNothing().when(userStoreManager).updateRoleListOfUser(username, null, new String[] { "Internal/" + signUpRole });
try {
Assert.assertNotNull(userSignUpSimpleWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException has thrown while executing the user signup simple workflow");
}
}
use of org.wso2.carbon.user.core.UserStoreManager in project carbon-apimgt by wso2.
the class UserSignUpSimpleWorkflowExecutorTest method init.
@Before
public void init() throws Exception {
userSignUpSimpleWorkflowExecutor = new UserSignUpSimpleWorkflowExecutor();
workflowDTO = new WorkflowDTO();
workflowDTO.setExternalWorkflowReference("12345");
workflowDTO.setTenantDomain(tenantDomain);
workflowDTO.setStatus(WorkflowStatus.APPROVED);
workflowDTO.setWorkflowReference(username);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
userStoreManager = Mockito.mock(UserStoreManager.class);
ServiceClient serviceClient = Mockito.mock(ServiceClient.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(SelfSignUpUtil.class);
PowerMockito.mockStatic(CarbonUtils.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(apiManagerConfiguration);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
Mockito.when(realmService.getTenantUserRealm(tenantID)).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
}
use of org.wso2.carbon.user.core.UserStoreManager in project carbon-apimgt by wso2.
the class StandaloneAuthorizationManagerClientTestCase method testGetRolesOfUser.
@Test
public void testGetRolesOfUser() throws Exception {
StandaloneAuthorizationManagerClient standaloneAuthorizationManagerClient = new StandaloneAuthorizationManagerClient();
standaloneAuthorizationManagerClient.getRolesOfUser("john");
Mockito.verify(userStoreManager, Mockito.times(1)).getRoleListOfUser("john");
}
use of org.wso2.carbon.user.core.UserStoreManager in project carbon-apimgt by wso2.
the class APIKeyMgtRemoteUserStoreMgtService method getUserRoles.
/**
* Get the role list of a user. Works for any tenant domain.
* @param username username with tenant domain
* @return list of roles
* @throws APIManagementException
*/
public String[] getUserRoles(String username) throws APIManagementException {
String[] userRoles = null;
String tenantDomain = MultitenantUtils.getTenantDomain(username);
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
UserStoreManager userStoreManager;
try {
userStoreManager = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager();
userRoles = userStoreManager.getRoleListOfUser(MultitenantUtils.getTenantAwareUsername(username));
} catch (UserStoreException e) {
APIUtil.handleException("Error occurred retrieving roles of user " + username, e);
} finally {
PrivilegedCarbonContext.getThreadLocalCarbonContext().endTenantFlow();
}
return userRoles;
}
Aggregations