Search in sources :

Example 11 with UserProfileDTO

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

the class UserProfileAdmin method setUserProfile.

public void setUserProfile(String username, UserProfileDTO profile) throws UserProfileException {
    UserRealm realm = null;
    try {
        if (!this.isAuthorized(username, USER_PROFILE_MANAGE_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 modify the profile of the admin user.");
            throw new UserProfileException(authorizationFailureMessage);
        }
        int indexOne;
        indexOne = username.indexOf("/");
        if (indexOne < 0) {
            /*if domain is not provided, this can be the scenario where user from a secondary user store
                logs in without domain name and tries to view his own profile*/
            MessageContext messageContext = MessageContext.getCurrentMessageContext();
            HttpServletRequest request = (HttpServletRequest) messageContext.getProperty("transport.http.servletRequest");
            String domainName = (String) request.getSession().getAttribute("logged_in_domain");
            if (domainName != null) {
                username = domainName + "/" + username;
            }
        }
        realm = getUserRealm();
        UserFieldDTO[] udatas = profile.getFieldValues();
        Map<String, String> map = new HashMap<String, String>();
        for (UserFieldDTO data : udatas) {
            String claimURI = data.getClaimUri();
            String value = data.getFieldValue();
            if (!data.isReadOnly()) {
                // Quick fix for not to remove OTP checkbox when false
                if (value == "" && "http://wso2.org/claims/identity/otp".equals(claimURI)) {
                    value = "false";
                }
                map.put(claimURI, value);
            }
        }
        if (profile.getProfileConifuration() != null) {
            map.put(UserCoreConstants.PROFILE_CONFIGURATION, profile.getProfileConifuration());
        } else {
            map.put(UserCoreConstants.PROFILE_CONFIGURATION, UserCoreConstants.DEFAULT_PROFILE_CONFIGURATION);
        }
        UserStoreManager admin = realm.getUserStoreManager();
        // User store manager expects tenant aware username
        admin.setUserClaimValues(username, map, profile.getProfileName());
    } catch (UserStoreException e) {
        // Not logging. Already logged.
        throw new UserProfileException(e.getMessage(), e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new UserProfileException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) 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) HttpServletRequest(javax.servlet.http.HttpServletRequest) UserRealm(org.wso2.carbon.user.core.UserRealm) UserStoreException(org.wso2.carbon.user.api.UserStoreException) MessageContext(org.apache.axis2.context.MessageContext)

Example 12 with UserProfileDTO

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

the class UserProfileAdminTestCase method testGetUserProfiles.

@Test(priority = 1, groups = "wso2.is", description = "Check get user profiles")
public void testGetUserProfiles() throws Exception {
    super.init();
    userProfileMgtClient = new UserProfileMgtServiceClient(backendURL, sessionCookie);
    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 : UserProfileMgtServiceClient(org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient) UserProfileDTO(org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 13 with UserProfileDTO

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

the class UserProfileMgtTestCase method testGetUserProfile.

@Test(groups = "wso2.is", description = "Check get user profile")
public void testGetUserProfile() throws Exception {
    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 : 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 14 with UserProfileDTO

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

the class AdminForcedPasswordResetTestCase method setUserClaim.

protected void setUserClaim(String claimURI, String calimValue) throws LogoutAuthenticationExceptionException, RemoteException, UserAdminUserAdminException, UserProfileMgtServiceUserProfileExceptionException {
    userProfileMgtClient = new UserProfileMgtServiceClient(backendURL, sessionCookie);
    UserProfileDTO profile = new UserProfileDTO();
    profile.setProfileName(PROFILE_NAME);
    UserFieldDTO passwordResetClaim = new UserFieldDTO();
    passwordResetClaim.setClaimUri(claimURI);
    passwordResetClaim.setFieldValue(calimValue);
    UserFieldDTO[] fields = new UserFieldDTO[1];
    fields[0] = passwordResetClaim;
    profile.setFieldValues(fields);
    userProfileMgtClient.setUserProfile(TEST_USER_USERNAME, profile);
}
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)

Example 15 with UserProfileDTO

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

the class EntitlementServiceTestCase method testSetUserProfile.

@Test(groups = "wso2.is", description = "Check set user profile")
public void testSetUserProfile() throws RemoteException, UserProfileMgtServiceUserProfileExceptionException {
    UserProfileDTO profile = userProfileMgtClient.getUserProfile("admin", "default");
    UserFieldDTO country = new UserFieldDTO();
    country.setClaimUri("http://wso2.org/claims/country");
    country.setFieldValue("SL");
    UserFieldDTO[] fields = profile.getFieldValues();
    UserFieldDTO[] newfields = new UserFieldDTO[fields.length];
    for (int i = 0; i < fields.length; i++) {
        if (fields[i].getDisplayName().toString().equals("Country")) {
            newfields[i] = country;
        } else {
            newfields[i] = fields[i];
        }
    }
    profile.setFieldValues(newfields);
    userProfileMgtClient.setUserProfile("admin", profile);
}
Also used : 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)

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