use of org.wso2.carbon.user.core.config.RealmConfiguration in project core-util by WSO2Telco.
the class UserRoleProsser method getRolesByUserName.
public List<String> getRolesByUserName(String userName) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null);
List<String> currentUserRoleList = null;
try {
RealmConfiguration realmConfiguration = new RealmConfiguration();
String[] currentUserRoles = realmService.getUserRealm(realmConfiguration).getUserStoreManager().getRoleListOfUser(userName);
currentUserRoleList = Arrays.asList(currentUserRoles);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("unable to retrieve user roles for user " + userName + " : ", e);
}
if (currentUserRoleList != null && !currentUserRoleList.isEmpty()) {
return currentUserRoleList;
} else {
return Collections.emptyList();
}
}
use of org.wso2.carbon.user.core.config.RealmConfiguration in project carbon-apimgt by wso2.
the class RegistrationServiceImpl method isUserSuperAdmin.
private boolean isUserSuperAdmin(String username) {
try {
RealmConfiguration realmConfig = new RealmConfigXMLProcessor().buildRealmConfigurationFromFile();
String adminUserName = realmConfig.getAdminUserName();
return adminUserName.equalsIgnoreCase(username);
} catch (UserStoreException e) {
log.error("Error while retrieving super admin username", e);
return false;
}
}
use of org.wso2.carbon.user.core.config.RealmConfiguration in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testIsUserNameWithAllowedDomainNameException.
@Test(expected = APIManagementException.class)
public void testIsUserNameWithAllowedDomainNameException() throws Exception {
UserRealm userRealm = Mockito.mock(UserRealm.class);
RealmConfiguration realmConfiguration = new RealmConfiguration();
realmConfiguration.addRestrictedDomainForSelfSignUp("bar.com");
Mockito.when(userRealm.getRealmConfiguration()).thenThrow(new UserStoreException());
SelfSignUpUtil.isUserNameWithAllowedDomainName("bar.com/john", userRealm);
}
use of org.wso2.carbon.user.core.config.RealmConfiguration in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testIsUserNameWithAllowedDomainNameTrue.
@Test
public void testIsUserNameWithAllowedDomainNameTrue() throws Exception {
UserRealm userRealm = Mockito.mock(UserRealm.class);
RealmConfiguration realmConfiguration = new RealmConfiguration();
realmConfiguration.addRestrictedDomainForSelfSignUp("foo.com");
Mockito.when(userRealm.getRealmConfiguration()).thenReturn(realmConfiguration);
boolean result = SelfSignUpUtil.isUserNameWithAllowedDomainName("bar.com/john", userRealm);
Assert.assertTrue(result);
}
use of org.wso2.carbon.user.core.config.RealmConfiguration in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testIsUserNameWithAllowedDomainNameWhenDomainNotGiven.
@Test
public void testIsUserNameWithAllowedDomainNameWhenDomainNotGiven() throws Exception {
UserRealm userRealm = Mockito.mock(UserRealm.class);
RealmConfiguration realmConfiguration = new RealmConfiguration();
realmConfiguration.addRestrictedDomainForSelfSignUp("foo.com");
Mockito.when(userRealm.getRealmConfiguration()).thenReturn(realmConfiguration);
boolean result = SelfSignUpUtil.isUserNameWithAllowedDomainName("john", userRealm);
Assert.assertTrue(result);
}
Aggregations