Search in sources :

Example 41 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-apimgt by wso2.

the class StandaloneAuthorizationManagerClientTestCase method testGetRoleNames.

@Test
public void testGetRoleNames() throws Exception {
    StandaloneAuthorizationManagerClient standaloneAuthorizationManagerClient = new StandaloneAuthorizationManagerClient();
    standaloneAuthorizationManagerClient.getRoleNames();
    Mockito.verify(userStoreManager, Mockito.times(1)).getRoleNames();
}
Also used : StandaloneAuthorizationManagerClient(org.wso2.carbon.apimgt.impl.utils.StandaloneAuthorizationManagerClient) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 42 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-apimgt by wso2.

the class UserSignUpWSWorkflowExecutorTest method init.

@Before
public void init() throws Exception {
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    RealmService realmService = Mockito.mock(RealmService.class);
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    userStoreManager = Mockito.mock(UserStoreManager.class);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    serviceClient = Mockito.mock(ServiceClient.class);
    APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(apiManagerConfiguration);
    PowerMockito.mockStatic(SelfSignUpUtil.class);
    PowerMockito.mockStatic(CarbonUtils.class);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.when(APIUtil.isAnalyticsEnabled()).thenReturn(true);
    PowerMockito.doNothing().when(CarbonUtils.class, "setBasicAccessSecurityHeaders", Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any());
    PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
    PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
    PowerMockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
    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);
    apiMgtDAO = TestUtils.getApiMgtDAO();
    userSignUpWSWorkflowExecutor = new UserSignUpWSWorkflowExecutor();
    workflowDTO = new WorkflowDTO();
    workflowDTO.setCallbackUrl(callBackURL);
    workflowDTO.setTenantDomain(tenantDomain);
    workflowDTO.setExternalWorkflowReference(externalWFReference);
    workflowDTO.setWorkflowReference(testUsername + "@carbon.super");
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) UserRealm(org.wso2.carbon.user.core.UserRealm) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) RealmService(org.wso2.carbon.user.core.service.RealmService) ServiceClient(org.apache.axis2.client.ServiceClient) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Before(org.junit.Before)

Example 43 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-apimgt by wso2.

the class SelfSignUpUtil method isUserNameWithAllowedDomainName.

/**
 * Check whether user can signup to the tenant domain
 *
 * @param userName - The user name
 * @param realm - The realm
 * @return - A boolean value
 * @throws APIManagementException
 */
public static boolean isUserNameWithAllowedDomainName(String userName, UserRealm realm) throws APIManagementException {
    int index;
    index = userName.indexOf('/');
    // Check whether we have a secondary UserStoreManager setup.
    if (index > 0) {
        // Using the short-circuit. User name comes with the domain name.
        try {
            return !realm.getRealmConfiguration().isRestrictedDomainForSlefSignUp(userName.substring(0, index));
        } catch (UserStoreException e) {
            throw new APIManagementException(e.getMessage(), e);
        }
    }
    return true;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 44 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-apimgt by wso2.

the class UserSignUpWorkflowExecutor method deleteUser.

/**
 * Method to delete a user
 *
 * @param tenantDomain
 * @param userName
 * @throws Exception
 */
protected static void deleteUser(String tenantDomain, String userName) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Remove the rejected user :" + userName);
    }
    RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
    int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
    UserRealm realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
    UserStoreManager manager = realm.getUserStoreManager();
    manager.deleteUser(userName);
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager)

Example 45 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-apimgt by wso2.

the class RemoteUserManagerClient method getUserList.

/**
 * Return userlist based on a claim
 *
 * @param claim      - The claim
 * @param claimValue - The Claim Value
 * @return - A user list
 * @throws APIManagementException
 */
public String[] getUserList(String claim, String claimValue) throws APIManagementException {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {
        UserRealm tenantUserRealm = (UserRealm) ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
        UserStoreManager userStoreManager = tenantUserRealm.getUserStoreManager();
        return userStoreManager.getUserList(claim, claimValue, null);
    } catch (Exception e) {
        throw new APIManagementException("Error when retrieving user list", e);
    }
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Aggregations

RealmService (org.wso2.carbon.user.core.service.RealmService)27 UserStoreException (org.wso2.carbon.user.api.UserStoreException)25 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 Test (org.junit.Test)17 UserRealm (org.wso2.carbon.user.core.UserRealm)16 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)12 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)11 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)10 UserRealm (org.wso2.carbon.user.api.UserRealm)8 HashMap (java.util.HashMap)6 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)6 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)4 Assertion (org.opensaml.saml.saml2.core.Assertion)3 Response (org.opensaml.saml.saml2.core.Response)3 Subject (org.opensaml.saml.saml2.core.Subject)3 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)3 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2