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);
}
}
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.");
}
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.");
}
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);
}
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);
}
Aggregations