Search in sources :

Example 6 with UserProfileDTO

use of org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO in project product-is by wso2.

the class UserManagementServiceAbstractTest method testListUserByClaim.

@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = "wso2.is", description = "Check list users by claim value", dependsOnMethods = "testGetRolesOfCurrentUser")
public void testListUserByClaim() throws Exception {
    UserProfileMgtServiceClient userProfileMgtServiceClient = new UserProfileMgtServiceClient(backendURL, getSessionCookie());
    UserProfileDTO profile = userProfileMgtServiceClient.getUserProfile(newUserName, "default");
    UserFieldDTO[] fields = userProfileMgtServiceClient.getProfileFieldsForInternalStore().getFieldValues();
    String profileConfigs = profile.getProfileName();
    for (UserFieldDTO field : fields) {
        if (field.getDisplayName().equalsIgnoreCase("Last Name")) {
            field.setFieldValue(newUserName + "LastName");
            continue;
        }
        if (field.getRequired()) {
            if (field.getDisplayName().equalsIgnoreCase("Email")) {
                field.setFieldValue(newUserName + "@wso2.com");
            } else {
                field.setFieldValue(newUserName);
            }
            continue;
        }
        if (field.getFieldValue() == null) {
            field.setFieldValue("");
        }
    }
    // creating a new profile with updated values
    UserProfileDTO newProfile = new UserProfileDTO();
    newProfile.setProfileName(profile.getProfileName());
    newProfile.setFieldValues(fields);
    newProfile.setProfileConifuration(profileConfigs);
    userProfileMgtServiceClient.setUserProfile(newUserName, newProfile);
    ClaimValue claimValue = new ClaimValue();
    claimValue.setClaimURI("http://wso2.org/claims/lastname");
    claimValue.setValue(newUserName + "LastName");
    FlaggedName[] allNames = userMgtClient.listUserByClaim(claimValue, newUserName, 10);
    Assert.assertTrue(nameExists(allNames, newUserName), "List user with claim value has failed");
}
Also used : UserProfileMgtServiceClient(org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient) ClaimValue(org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue) UserFieldDTO(org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO) UserProfileDTO(org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO) FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 7 with UserProfileDTO

use of org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO in project product-is by wso2.

the class UserProfileAdminTestCase method testSetUserProfile.

/**
 * Setting a user profile updates the user claim values of the existing user profile of the user.
 * This test method tests the above behavior.
 *
 * @throws Exception
 */
@Test(priority = 3, groups = "wso2.is", description = "Check set user profiles")
public void testSetUserProfile() throws Exception {
    super.init();
    logManger = new AuthenticatorClient(backendURL);
    userProfileMgtClient = new UserProfileMgtServiceClient(backendURL, sessionCookie);
    logManger.login(isServer.getSuperTenant().getTenantAdmin().getUserName(), isServer.getSuperTenant().getTenantAdmin().getPassword(), isServer.getInstance().getHosts().get("default"));
    UserProfileDTO profile = new UserProfileDTO();
    profile.setProfileName("default");
    UserFieldDTO lastName = new UserFieldDTO();
    lastName.setClaimUri("http://wso2.org/claims/lastname");
    lastName.setFieldValue("lastname");
    UserFieldDTO givenname = new UserFieldDTO();
    givenname.setClaimUri("http://wso2.org/claims/givenname");
    givenname.setFieldValue("firstname");
    UserFieldDTO email = new UserFieldDTO();
    email.setClaimUri("http://wso2.org/claims/emailaddress");
    email.setFieldValue("email@email.com");
    UserFieldDTO[] fields = new UserFieldDTO[3];
    fields[0] = lastName;
    fields[1] = givenname;
    fields[2] = email;
    profile.setFieldValues(fields);
    userProfileMgtClient.setUserProfile(userId1, profile);
    UserProfileDTO getProfile = userProfileMgtClient.getUserProfile(userId1, "default");
    UserFieldDTO[] updatedFields = getProfile.getFieldValues();
    for (UserFieldDTO updatedField : updatedFields) {
        if (updatedField.getClaimUri().equals("http://wso2.org/claims/lastname")) {
            Assert.assertEquals(updatedField.getFieldValue(), "lastname");
        } else if (updatedField.getClaimUri().equals("http://wso2.org/claims/givenname")) {
            Assert.assertEquals(updatedField.getFieldValue(), "firstname");
        } else if (updatedField.getClaimUri().equals("http://wso2.org/claims/emailaddress")) {
            Assert.assertEquals(updatedField.getFieldValue(), "email@email.com");
        }
    }
    logManger.logOut();
}
Also used : UserProfileMgtServiceClient(org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient) AuthenticatorClient(org.wso2.carbon.integration.common.admin.client.AuthenticatorClient) UserFieldDTO(org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO) UserProfileDTO(org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 8 with UserProfileDTO

use of org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO in project product-is by wso2.

the class UserProfileAdminTestCase method testGetUserProfile.

@Test(priority = 2, groups = "wso2.is", description = "Check get user profile")
public void testGetUserProfile() throws Exception {
    super.init();
    userProfileMgtClient = new UserProfileMgtServiceClient(backendURL, sessionCookie);
    UserProfileDTO profile = userProfileMgtClient.getUserProfile(userId1, "default");
    UserFieldDTO[] fields = profile.getFieldValues();
    String displayValue = null;
    for (UserFieldDTO field : fields) {
        if ("Last Name".equals(field.getDisplayName())) {
            displayValue = field.getFieldValue();
            break;
        }
    }
    Assert.assertTrue(userId1.equals(displayValue), "Getting user profile has failed.");
}
Also used : UserProfileMgtServiceClient(org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient) UserFieldDTO(org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO) UserProfileDTO(org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 9 with UserProfileDTO

use of org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO in project product-is by wso2.

the class UserProfileMgtTestCase method testGetUserProfiles.

@Test(groups = "wso2.is", description = "Check get user profiles")
public void testGetUserProfiles() throws Exception {
    UserProfileDTO[] profiles = userProfileMgtClient.getUserProfiles(userId1);
    String profile = null;
    for (UserProfileDTO userProfileDTO : profiles) {
        profile = userProfileDTO.getProfileName();
    }
    Assert.assertEquals(profile, "default", "Getting user profiles has failed.");
}
Also used : UserProfileDTO(org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 10 with UserProfileDTO

use of org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO in project carbon-identity-framework by wso2.

the class UserProfileAdmin method getUserProfiles.

public UserProfileDTO[] getUserProfiles(String username) throws UserProfileException {
    UserProfileDTO[] profiles;
    String[] availableProfileConfigurations = new String[0];
    String profileConfig = null;
    try {
        if (!this.isAuthorized(username, USER_PROFILE_VIEW_PERMISSION)) {
            throw new UserProfileException(authorizationFailureMessage);
        }
        // Any other attempt is unauthorized. So attempts will be logged and denied.
        if (isAdminProfileSpoof(username)) {
            log.warn("Unauthorized attempt. User " + CarbonContext.getThreadLocalCarbonContext().getUsername() + " is trying to view the profile of the admin user.");
            throw new UserProfileException(authorizationFailureMessage);
        }
        UserRealm realm = getUserRealm();
        UserStoreManager userStoreManager = realm.getUserStoreManager();
        boolean isReadOnly = userStoreManager.isReadOnly();
        int index;
        index = username.indexOf("/");
        UserStoreManager secUserStoreManager = null;
        // Check whether we have a secondary UserStoreManager setup.
        if (index > 0) {
            // Using the short-circuit. User name comes with the domain name.
            String domain = username.substring(0, index);
            if (userStoreManager instanceof AbstractUserStoreManager) {
                secUserStoreManager = ((AbstractUserStoreManager) userStoreManager).getSecondaryUserStoreManager(domain);
                if (secUserStoreManager != null) {
                    isReadOnly = secUserStoreManager.isReadOnly();
                }
            }
        }
        ProfileConfigurationManager profileAdmin = realm.getProfileConfigurationManager();
        if (profileAdmin != null) {
            availableProfileConfigurations = getAvailableProfileConfiguration(profileAdmin);
        }
        String[] profileNames = null;
        if (secUserStoreManager != null) {
            profileNames = secUserStoreManager.getProfileNames(username);
        } else {
            profileNames = userStoreManager.getProfileNames(username);
        }
        profiles = new UserProfileDTO[profileNames.length];
        Claim[] claims = getAllSupportedClaims(realm, UserCoreConstants.DEFAULT_CARBON_DIALECT);
        String[] claimUris = new String[claims.length + 1];
        for (int i = 0; i < claims.length; i++) {
            claimUris[i] = claims[i].getClaimUri();
        }
        claimUris[claims.length] = UserCoreConstants.PROFILE_CONFIGURATION;
        for (int i = 0; i < profileNames.length; i++) {
            String profile = profileNames[i];
            Map<String, String> valueMap = userStoreManager.getUserClaimValues(username, claimUris, profile);
            List<UserFieldDTO> userFields = new ArrayList<UserFieldDTO>();
            for (int j = 0; j < claims.length; j++) {
                UserFieldDTO data = new UserFieldDTO();
                Claim claim = claims[j];
                String claimUri = claim.getClaimUri();
                if (!UserCoreConstants.PROFILE_CONFIGURATION.equals(claimUri)) {
                    data.setClaimUri(claimUri);
                    data.setFieldValue(valueMap.get(claimUri));
                    data.setDisplayName(claim.getDisplayTag());
                    data.setRegEx(claim.getRegEx());
                    data.setRequired(claim.isRequired());
                    data.setDisplayOrder(claim.getDisplayOrder());
                    data.setCheckedAttribute(claim.isCheckedAttribute());
                    data.setReadOnly(claim.isReadOnly());
                    userFields.add(data);
                }
            }
            UserProfileDTO temp = new UserProfileDTO();
            temp.setProfileName(profile);
            temp.setFieldValues(userFields.toArray(new UserFieldDTO[userFields.size()]));
            temp.setProfileConfigurations(availableProfileConfigurations);
            profileConfig = valueMap.get(UserCoreConstants.PROFILE_CONFIGURATION);
            if (profileConfig == null) {
                profileConfig = UserCoreConstants.DEFAULT_PROFILE_CONFIGURATION;
            }
            if (isReadOnly) {
                profileConfig = "readonly";
            }
            temp.setProfileConifuration(profileConfig);
            profiles[i] = temp;
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        // Not logging. Already logged.
        throw new UserProfileException(e.getMessage(), e);
    }
    return profiles;
}
Also used : ArrayList(java.util.ArrayList) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) UserStoreException(org.wso2.carbon.user.api.UserStoreException) CarbonException(org.wso2.carbon.CarbonException) FederatedAssociationManagerException(org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProfileConfigurationManager(org.wso2.carbon.user.core.profile.ProfileConfigurationManager) UserRealm(org.wso2.carbon.user.core.UserRealm) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Claim(org.wso2.carbon.user.api.Claim)

Aggregations

UserProfileDTO (org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO)11 Test (org.testng.annotations.Test)9 UserFieldDTO (org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO)9 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)9 UserProfileMgtServiceClient (org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient)5 CarbonException (org.wso2.carbon.CarbonException)4 FederatedAssociationManagerException (org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException)4 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)4 UserStoreException (org.wso2.carbon.user.api.UserStoreException)4 UserRealm (org.wso2.carbon.user.core.UserRealm)4 Claim (org.wso2.carbon.user.api.Claim)3 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)3 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)3 ProfileConfigurationManager (org.wso2.carbon.user.core.profile.ProfileConfigurationManager)3 ArrayList (java.util.ArrayList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 MessageContext (org.apache.axis2.context.MessageContext)2 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)2 HashMap (java.util.HashMap)1 VerificationBean (org.wso2.carbon.identity.mgt.stub.beans.VerificationBean)1