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