use of org.wso2.carbon.user.core.profile.ProfileConfigurationManager 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;
}
use of org.wso2.carbon.user.core.profile.ProfileConfigurationManager 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;
}
use of org.wso2.carbon.user.core.profile.ProfileConfigurationManager in project carbon-identity-framework by wso2.
the class UserProfileAdmin method getAvailableProfileConfiguration.
private String[] getAvailableProfileConfiguration(ProfileConfigurationManager profileAdmin) throws UserStoreException {
ProfileConfiguration[] configurations;
String[] profileNames = new String[0];
try {
configurations = (ProfileConfiguration[]) profileAdmin.getAllProfiles();
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new UserStoreException(e);
}
if (configurations != null) {
profileNames = new String[configurations.length];
for (int i = 0; i < configurations.length; i++) {
profileNames[i] = configurations[i].getProfileName();
}
}
return profileNames;
}
use of org.wso2.carbon.user.core.profile.ProfileConfigurationManager 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