org.wso2.carbon.user.mgt.stub.UserAdminStub Java Examples

The following examples show how to use org.wso2.carbon.user.mgt.stub.UserAdminStub. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplicationManagementServiceClient.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param cookie
 * @param backendServerURL
 * @param configCtx
 * @throws AxisFault
 */
public ApplicationManagementServiceClient(String cookie, String backendServerURL,
                                          ConfigurationContext configCtx) throws AxisFault {

    String serviceURL = backendServerURL + "IdentityApplicationManagementService";
    String userAdminServiceURL = backendServerURL + "UserAdmin";
    stub = new IdentityApplicationManagementServiceStub(configCtx, serviceURL);
    userAdminStub = new UserAdminStub(configCtx, userAdminServiceURL);

    ServiceClient client = stub._getServiceClient();
    Options option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    ServiceClient userAdminClient = userAdminStub._getServiceClient();
    Options userAdminOptions = userAdminClient.getOptions();
    userAdminOptions.setManageSession(true);
    userAdminOptions.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    if (debugEnabled) {
        log.debug("Invoking service " + serviceURL);
    }

}
 
Example #2
Source File: ApplicationManagementServiceClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param cookie
 * @param backendServerURL
 * @param configCtx
 * @throws AxisFault
 */
public ApplicationManagementServiceClient(String cookie, String backendServerURL,
                                          ConfigurationContext configCtx) throws AxisFault {

    String serviceURL = backendServerURL + "IdentityApplicationManagementService";
    String userAdminServiceURL = backendServerURL + "UserAdmin";
    stub = new IdentityApplicationManagementServiceStub(configCtx, serviceURL);
    userAdminStub = new UserAdminStub(configCtx, userAdminServiceURL);

    ServiceClient client = stub._getServiceClient();
    Options option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    ServiceClient userAdminClient = userAdminStub._getServiceClient();
    Options userAdminOptions = userAdminClient.getOptions();
    userAdminOptions.setManageSession(true);
    userAdminOptions.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    if (debugEnabled) {
        log.debug("Invoking service " + serviceURL);
    }

}
 
Example #3
Source File: UserSignUpWorkflowExecutorTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    RealmService realmService = Mockito.mock(RealmService.class);
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    userStoreManager = Mockito.mock(UserStoreManager.class);
    PowerMockito.mockStatic(CarbonUtils.class);
    userAdminStub = Mockito.mock(UserAdminStub.class);
    userRegistrationAdminServiceStub = Mockito.mock(UserRegistrationAdminServiceStub.class);
    serviceClient =  Mockito.mock(ServiceClient.class);;
    PowerMockito.whenNew(UserAdminStub.class).withAnyArguments().thenReturn(userAdminStub);
    PowerMockito.whenNew(UserRegistrationAdminServiceStub.class).withAnyArguments().thenReturn
            (userRegistrationAdminServiceStub);
    PowerMockito.when(userRegistrationAdminServiceStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(serviceClient.getOptions()).thenReturn(new Options());
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getBootstrapRealm()).thenReturn(userRealm);
    Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    PowerMockito.doNothing().when(CarbonUtils.class, "setBasicAccessSecurityHeaders", Mockito.anyString(),
            Mockito.anyString(), Mockito.anyBoolean(), (ServiceClient) Mockito.anyObject());
    FlaggedName flaggedName = new FlaggedName();
    flaggedName.setSelected(true);
    flaggedName.setItemName(role);
    flaggedNames = new FlaggedName[]{flaggedName};
}
 
Example #4
Source File: UserSignUpWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Method to delete a user
 * @param serverURL
 * @param adminUsername
 * @param adminPassword
 * @param userName
 * @throws Exception
 */
protected static void deleteUser(String serverURL, String adminUsername,
                                 String adminPassword, String userName) throws Exception {
	if (log.isDebugEnabled()) {
		log.debug("Remove the rejected user :" + userName);
	}		
	String url = serverURL + "UserAdmin";
	
	int index = userName.indexOf(UserCoreConstants.DOMAIN_SEPARATOR);
	//remove the PRIMARY part from the user name
	if (index > 0) {
		if(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME.equalsIgnoreCase(userName.substring(0, index))){
			userName = userName.substring(index + 1);
		}			
	} 

	UserAdminStub userAdminStub = new UserAdminStub(url);
	CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient());
	userAdminStub.deleteUser(userName);

}
 
Example #5
Source File: UserAdminClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public UserAdminClient(String cookie, String url, String serviceName,
        ConfigurationContext configContext) throws java.lang.Exception {
    try {
        stub = new UserAdminStub(configContext, url + serviceName);
        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);


        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example #6
Source File: UserManagementClient.java    From product-es with Apache License 2.0 5 votes vote down vote up
public UserManagementClient(String backendURL, String userName, String password)
        throws AxisFault {

    String endPoint = backendURL + serviceName;
    userAdminStub = new UserAdminStub(endPoint);
    AuthenticateStub.authenticateStub(userName, password, userAdminStub);
}
 
Example #7
Source File: HumanTaskAdminClient.java    From product-es with Apache License 2.0 5 votes vote down vote up
public HumanTaskAdminClient(String backEndUrl, String userName, String password) throws AxisFault {

		htStub = new HumanTaskClientAPIAdminStub(backEndUrl + "HumanTaskClientAPIAdmin");
		AuthenticateStub.authenticateStub(userName, password, htStub);

		umStub = new UserAdminStub(backEndUrl + "UserAdmin");
		AuthenticateStub.authenticateStub(userName, password, umStub);

		wlStub = new WorkListServiceStub(backEndUrl + "WorkListService");
		AuthenticateStub.authenticateStub(userName, password, wlStub);
	}
 
Example #8
Source File: HumanTaskAdminClient.java    From product-es with Apache License 2.0 5 votes vote down vote up
public HumanTaskAdminClient(String backEndUrl, String sessionCookie) throws AxisFault {
	htStub = new HumanTaskClientAPIAdminStub(backEndUrl + "HumanTaskClientAPIAdmin");
	AuthenticateStub.authenticateStub(sessionCookie, htStub);

	umStub = new UserAdminStub(backEndUrl + "UserAdmin");
	AuthenticateStub.authenticateStub(sessionCookie, umStub);

	wlStub = new WorkListServiceStub(backEndUrl + "WorkListService");
	AuthenticateStub.authenticateStub(sessionCookie, wlStub);
}
 
Example #9
Source File: UserSignUpSimpleWorkflowExecutorTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@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);
    userAdminStub = Mockito.mock(UserAdminStub.class);
    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);
    PowerMockito.whenNew(UserAdminStub.class).withAnyArguments().thenReturn(userAdminStub);
    Mockito.when(userAdminStub._getServiceClient()).thenReturn(serviceClient);
    PowerMockito.doNothing().when(CarbonUtils.class, "setBasicAccessSecurityHeaders", Mockito.anyString(),
            Mockito.anyString(), Mockito.anyBoolean(), (ServiceClient) Mockito.anyObject());

}
 
Example #10
Source File: UserSignUpWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Method updates Roles users with subscriber role
 * @param serverURL
 * @param adminUsername
 * @param adminPassword
 * @param userName
 * @param role
 * @throws Exception
 */
protected static void updateRolesOfUser(String serverURL, String adminUsername,
                                        String adminPassword, String userName, String role)
                                                                                           throws Exception {
	if (log.isDebugEnabled()) {
		log.debug("Adding Subscriber role to " + userName);
	}

	String url = serverURL + "UserAdmin";
	RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
	UserRealm realm = realmService.getBootstrapRealm();
	UserStoreManager manager = realm.getUserStoreManager();
	if (!manager.isExistingRole(role)){
		log.error("Could not find role " + role + " in the user store");
		throw new Exception("Could not find role " + role + " in the user store");
	}

	UserAdminStub userAdminStub = new UserAdminStub(url);
	CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient());
	FlaggedName[] flaggedNames = userAdminStub.getRolesOfUser(userName, "*", -1);
	List<String> roles = new ArrayList<String>();
	if (flaggedNames != null) {
		for (FlaggedName flaggedName : flaggedNames) {
			if (flaggedName.getSelected()) {
				roles.add(flaggedName.getItemName());
			}
		}
	}
	roles.add(role);
	userAdminStub.updateRolesOfUser(userName, roles.toArray(new String[roles.size()]));
}
 
Example #11
Source File: UserAdminClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public UserAdminClient(String cookie, String url, ConfigurationContext configContext)
        throws java.lang.Exception {
    try {

        stub = new UserAdminStub(configContext, url + "UserAdmin");
        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example #12
Source File: UserAdminClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public UserAdminClient(String cookie, String url, String serviceName,
        ConfigurationContext configContext) throws java.lang.Exception {
    try {
        stub = new UserAdminStub(configContext, url + serviceName);
        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);


        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example #13
Source File: SamplesInvoker.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private static void initUserAdminStub() throws Exception {
    userAdminStub = new UserAdminStub(USER_MANAGEMENT_SERVICE_URL);

    ServiceClient serviceClient = userAdminStub._getServiceClient();
    Options serviceClientOptions = serviceClient.getOptions();
    serviceClientOptions.setManageSession(true);
    CarbonUtils.setBasicAccessSecurityHeaders("admin", "admin", serviceClient);
}
 
Example #14
Source File: UserAdminClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public UserAdminClient(String cookie, String url, ConfigurationContext configContext)
        throws java.lang.Exception {
    try {

        stub = new UserAdminStub(configContext, url + "UserAdmin");
        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example #15
Source File: UserSignUpWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Method updates Roles users with list of roles
 * @param serverURL
 * @param adminUsername
 * @param adminPassword
 * @param userName
 * @param tenantID
 * @param role
 * @throws Exception
 */
protected static void updateRolesOfUser(String serverURL, String adminUsername,
                                        String adminPassword, String userName,
                                        List<String> roleList, String tenantDomain)
                                        		throws Exception {

	if (log.isDebugEnabled()) {
		log.debug("Adding roles to " + userName + "in " + tenantDomain + " Domain");
	}
	String url = serverURL + "UserAdmin";
	RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
	int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager()
			.getTenantId(tenantDomain);
	UserRealm realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
	UserStoreManager manager = realm.getUserStoreManager();
	
	if(manager.isExistingUser(userName)) {
		// check whether given roles exist
		for (String role : roleList) {
			if (!manager.isExistingRole(role)) {
				log.error("Could not find role " + role + " in the user store");
				throw new Exception("Could not find role " + role + " in the user store");
			}
		}

		UserAdminStub userAdminStub = new UserAdminStub(url);
		CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient());
		
		FlaggedName[] flaggedNames = userAdminStub.getRolesOfUser(userName, "*", -1);
		List<String> roles = new ArrayList<String>();
		if (flaggedNames != null) {
			for (FlaggedName flaggedName : flaggedNames) {
				if (flaggedName.getSelected()) {
					roles.add(flaggedName.getItemName());
				}
			}
		}
		roles.addAll(roleList);
		userAdminStub.updateRolesOfUser(userName, roles.toArray(new String[roles.size()]));
	} else {
		log.error("User does not exist. Unable to approve user " + userName);
	} 
	
}
 
Example #16
Source File: UserSignUpWSWorkflowExecutorTest.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@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);
    userAdminStub = Mockito.mock(UserAdminStub.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);
    APIMgtWorkflowDataPublisher apiMgtWorkflowDataPublisher = Mockito.mock(APIMgtWorkflowDataPublisher.class);
    Mockito.when(serviceReferenceHolder.getApiMgtWorkflowDataPublisher()).thenReturn(apiMgtWorkflowDataPublisher);
    PowerMockito.whenNew(UserAdminStub.class).withAnyArguments().thenReturn(userAdminStub);
    apiMgtDAO = TestUtils.getApiMgtDAO();
    userSignUpWSWorkflowExecutor = new UserSignUpWSWorkflowExecutor();
    workflowDTO = new WorkflowDTO();
    workflowDTO.setCallbackUrl(callBackURL);
    workflowDTO.setTenantDomain(tenantDomain);
    workflowDTO.setExternalWorkflowReference(externalWFReference);
    workflowDTO.setWorkflowReference(testUsername + "@carbon.super");
}
 
Example #17
Source File: UserManagementClient.java    From product-es with Apache License 2.0 4 votes vote down vote up
public UserManagementClient(String backendURL, String sessionCookie) throws AxisFault {

        String endPoint = backendURL + serviceName;
        userAdminStub = new UserAdminStub(endPoint);
        AuthenticateStub.authenticateStub(sessionCookie, userAdminStub);
    }