Search in sources :

Example 1 with RealmConfiguration

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();
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) RealmService(org.wso2.carbon.user.core.service.RealmService) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext)

Example 2 with RealmConfiguration

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;
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) RealmConfigXMLProcessor(org.wso2.carbon.user.core.config.RealmConfigXMLProcessor) UserStoreException(org.wso2.carbon.user.core.UserStoreException)

Example 3 with RealmConfiguration

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);
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserRealm(org.wso2.carbon.user.core.UserRealm) UserStoreException(org.wso2.carbon.user.core.UserStoreException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with RealmConfiguration

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);
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserRealm(org.wso2.carbon.user.core.UserRealm) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with RealmConfiguration

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);
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserRealm(org.wso2.carbon.user.core.UserRealm) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Test (org.junit.Test)5 UserRealm (org.wso2.carbon.user.core.UserRealm)5 RealmService (org.wso2.carbon.user.core.service.RealmService)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)3 UserStoreException (org.wso2.carbon.user.core.UserStoreException)3 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)3 File (java.io.File)2 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)2 RealmConfigXMLProcessor (org.wso2.carbon.user.core.config.RealmConfigXMLProcessor)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 Environment (org.wso2.carbon.apimgt.api.model.Environment)1 ResourceFile (org.wso2.carbon.apimgt.api.model.ResourceFile)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 APIMConfigService (org.wso2.carbon.apimgt.impl.config.APIMConfigService)1 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)1