Search in sources :

Example 1 with UserProfileDTO

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

the class UserProfileAdmin method getProfileFieldsForInternalStore.

public UserProfileDTO getProfileFieldsForInternalStore() throws UserProfileException {
    UserFieldDTO[] datas;
    UserProfileDTO profile = new UserProfileDTO();
    String[] availableProfileConfigurations = new String[0];
    try {
        UserRealm realm = getUserRealm();
        Claim[] claims = getClaimsToEnterData(realm);
        ProfileConfigurationManager profileAdmin = realm.getProfileConfigurationManager();
        if (profileAdmin != null) {
            availableProfileConfigurations = getAvailableProfileConfiguration(profileAdmin);
        }
        String[] claimUris = new String[claims.length];
        for (int i = 0; i < claims.length; i++) {
            claimUris[i] = claims[i].getClaimUri();
        }
        datas = new UserFieldDTO[claims.length];
        for (int j = 0; j < claims.length; j++) {
            UserFieldDTO data = new UserFieldDTO();
            Claim claim = claims[j];
            String claimUri = claim.getClaimUri();
            data.setClaimUri(claimUri);
            data.setDisplayName(claim.getDisplayTag());
            data.setRegEx(claim.getRegEx());
            data.setRequired(claim.isRequired());
            data.setDisplayOrder(claim.getDisplayOrder());
            data.setRegEx(claim.getRegEx());
            data.setCheckedAttribute(claim.isCheckedAttribute());
            data.setReadOnly(claim.isReadOnly());
            datas[j] = data;
        }
    } catch (Exception e) {
        // Not logging. Already logged.
        throw new UserProfileException(e.getMessage(), e);
    }
    profile.setFieldValues(datas);
    profile.setProfileConfigurations(availableProfileConfigurations);
    return profile;
}
Also used : ProfileConfigurationManager(org.wso2.carbon.user.core.profile.ProfileConfigurationManager) UserRealm(org.wso2.carbon.user.core.UserRealm) Claim(org.wso2.carbon.user.api.Claim) 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)

Example 2 with UserProfileDTO

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

the class UserProfileAdmin method getUserProfile.

public UserProfileDTO getUserProfile(String username, String profileName) throws UserProfileException {
    UserProfileDTO profile = new UserProfileDTO();
    String[] availableProfileConfigurations = new String[0];
    String profileConfig = null;
    try {
        if (username == null || profileName == null) {
            throw new UserProfileException("Invalid input parameters");
        }
        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 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;
            }
        }
        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();
        String[] profileNames = null;
        if (secUserStoreManager != null) {
            profileNames = secUserStoreManager.getProfileNames(username);
        } else {
            profileNames = userStoreManager.getProfileNames(username);
        }
        boolean found = false;
        if (profileNames != null && profileNames.length > 0) {
            for (int i = 0; i < profileNames.length; i++) {
                if (profileName.equals(profileNames[i])) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            return null;
        }
        if (profileAdmin != null) {
            availableProfileConfigurations = getAvailableProfileConfiguration(profileAdmin);
        }
        Claim[] claims = getClaimsToEnterData(realm);
        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;
        Map<String, String> valueMap = userStoreManager.getUserClaimValues(username, claimUris, profileName);
        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.setReadOnly(claim.isReadOnly());
                data.setCheckedAttribute(claim.isCheckedAttribute());
                userFields.add(data);
            }
        }
        profile.setProfileName(profileName);
        profile.setProfileConfigurations(availableProfileConfigurations);
        profileConfig = valueMap.get(UserCoreConstants.PROFILE_CONFIGURATION);
        if (profileConfig == null) {
            profileConfig = UserCoreConstants.DEFAULT_PROFILE_CONFIGURATION;
        }
        if (isReadOnly) {
            profileConfig = "readonly";
        }
        profile.setProfileConifuration(profileConfig);
        profile.setFieldValues(userFields.toArray(new UserFieldDTO[userFields.size()]));
    } catch (Exception e) {
        log.error(String.format("An error occurred while getting the user profile '%s' of the user '%s'", profileName, username), e);
        throw new UserProfileException(e.getMessage(), e);
    }
    return profile;
}
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) HttpServletRequest(javax.servlet.http.HttpServletRequest) ProfileConfigurationManager(org.wso2.carbon.user.core.profile.ProfileConfigurationManager) UserRealm(org.wso2.carbon.user.core.UserRealm) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) MessageContext(org.apache.axis2.context.MessageContext) Claim(org.wso2.carbon.user.api.Claim)

Example 3 with UserProfileDTO

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

the class UserInformationRecoveryServiceTestCase method testSendRecoveryNotification.

@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(groups = "wso2.is", description = "Check recovery notification sending", dependsOnMethods = "testVerifyUser")
public void testSendRecoveryNotification() throws Exception {
    UserProfileDTO profile = profileClient.getUserProfile("user11", "default");
    UserFieldDTO email = new UserFieldDTO();
    email.setFieldValue("testuser@wso2.com");
    email.setClaimUri("http://wso2.org/claims/emailaddress");
    UserFieldDTO[] params = new UserFieldDTO[1];
    params[0] = email;
    profile.setFieldValues(params);
    profileClient.setUserProfile("user11", profile);
    VerificationBean bean = infoRecoveryClient.sendRecoveryNotification("user11", confKey, "EMAIL");
    Assert.assertNotNull(bean, "Notification sending has failed with null return");
// Assert.assertTrue(bean.getVerified(), "Notification sending has failed for user11");
// confKey = bean.getKey();
}
Also used : VerificationBean(org.wso2.carbon.identity.mgt.stub.beans.VerificationBean) UserFieldDTO(org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO) UserProfileDTO(org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 4 with UserProfileDTO

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

the class EntitlementServiceTestCase method testGetDecisionDenyState.

@Test(groups = "wso2.is", dependsOnMethods = { "testGetDecisionByAttributes" }, description = "Check get decision deny state")
public void testGetDecisionDenyState() throws Exception {
    UserProfileDTO profile = userProfileMgtClient.getUserProfile("admin", "default");
    UserFieldDTO country = new UserFieldDTO();
    country.setClaimUri("http://wso2.org/claims/country");
    country.setFieldValue("USA");
    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);
    Thread.sleep(5000);
    String decision = entitlementServiceClient.getDecisionByAttributes("admin", "http://localhost:8280/services/echo/", "read", null);
    log.info(decision);
    Assert.assertTrue(decision.contains("Deny"), "Entitlement service get decision 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 5 with UserProfileDTO

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

the class OAuth2ServiceJWTGrantTestCase method addNewUserWithClaims.

/**
 * Add a new with 3 user claims.
 *
 * @throws RemoteException                                    Remote Exception.
 * @throws UserAdminUserAdminException                        User Admin User Admin Exception.
 * @throws UserProfileMgtServiceUserProfileExceptionException User Profile Mgt Service User Profile Exception.
 */
private void addNewUserWithClaims() throws RemoteException, UserAdminUserAdminException, UserProfileMgtServiceUserProfileExceptionException {
    String profileName = "default";
    String adminRoleName = "admin";
    String countryLocalClaimUri = "http://wso2.org/claims/country";
    String givenNameLocalClaimUri = "http://wso2.org/claims/givenname";
    userManagementClient.addUser(JWT_USER, JWT_USER, new String[] { adminRoleName }, profileName);
    UserProfileDTO profile = new UserProfileDTO();
    profile.setProfileName(profileName);
    UserFieldDTO country = new UserFieldDTO();
    country.setClaimUri(countryLocalClaimUri);
    country.setFieldValue(COUNTRY_CLAIM_VALUE);
    UserFieldDTO givenname = new UserFieldDTO();
    givenname.setClaimUri(givenNameLocalClaimUri);
    givenname.setFieldValue(JWT_USER);
    UserFieldDTO email = new UserFieldDTO();
    email.setClaimUri(EMAIL_LOCAL_CLAIM_URI);
    email.setFieldValue(EMAIL_CLAIM_VALUE);
    UserFieldDTO[] fields = new UserFieldDTO[3];
    fields[0] = country;
    fields[1] = givenname;
    fields[2] = email;
    profile.setFieldValues(fields);
    userProfileMgtServiceClient.setUserProfile(JWT_USER, profile);
}
Also used : UserFieldDTO(org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO) UserProfileDTO(org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO)

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