use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class UserObjectBundleHook method postCreate.
@Override
public void postCreate(IdentifiableObject persistedObject, ObjectBundle bundle) {
if (!User.class.isInstance(persistedObject) || !bundle.hasExtras(persistedObject, "uc"))
return;
User user = (User) persistedObject;
final UserCredentials userCredentials = (UserCredentials) bundle.getExtras(persistedObject, "uc");
if (!StringUtils.isEmpty(userCredentials.getPassword())) {
userService.encodeAndSetPassword(userCredentials, userCredentials.getPassword());
}
preheatService.connectReferences(userCredentials, bundle.getPreheat(), bundle.getPreheatIdentifier());
sessionFactory.getCurrentSession().save(userCredentials);
user.setUserCredentials(userCredentials);
sessionFactory.getCurrentSession().update(user);
bundle.removeExtras(persistedObject, "uc");
}
use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class UserController method validateInviteUser.
/**
* Validates whether a user can be invited / created.
*
* @param user the user.
*/
private boolean validateInviteUser(User user, User currentUser) throws WebMessageException {
if (!validateCreateUser(user, currentUser)) {
return false;
}
UserCredentials credentials = user.getUserCredentials();
if (credentials == null) {
throw new WebMessageException(WebMessageUtils.conflict("User credentials is not present"));
}
credentials.setUserInfo(user);
String valid = securityService.validateInvite(user.getUserCredentials());
if (valid != null) {
throw new WebMessageException(WebMessageUtils.conflict(valid + ": " + user.getUserCredentials()));
}
return true;
}
use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class DefaultDataApprovalLevelService method subsetUserDataApprovalLevels.
/**
* Returns the subset of approval levels that the user is allowed to access.
*
* @param approvalLevels the approval levels to test.
* @return the subset of approval levels to which the user has access.
*/
private List<DataApprovalLevel> subsetUserDataApprovalLevels(List<DataApprovalLevel> approvalLevels) {
UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
int lowestNumberOrgUnitLevel = getCurrentUsersLowestNumberOrgUnitLevel();
boolean canSeeAllDimensions = CollectionUtils.isEmpty(categoryService.getCoDimensionConstraints(userCredentials)) && CollectionUtils.isEmpty(categoryService.getCogDimensionConstraints(userCredentials));
List<DataApprovalLevel> userDataApprovalLevels = new ArrayList<>();
boolean addLevel = false;
for (DataApprovalLevel approvalLevel : approvalLevels) {
if (!addLevel && approvalLevel.getOrgUnitLevel() >= lowestNumberOrgUnitLevel) {
CategoryOptionGroupSet cogs = approvalLevel.getCategoryOptionGroupSet();
addLevel = securityService.canRead(approvalLevel) && cogs == null ? canSeeAllDimensions : (securityService.canRead(cogs) && !CollectionUtils.isEmpty(categoryService.getCategoryOptionGroups(cogs)));
}
if (addLevel) {
userDataApprovalLevels.add(approvalLevel);
}
}
return userDataApprovalLevels;
}
use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class DhisConvenienceTest method createUserCredentials.
public static UserCredentials createUserCredentials(char uniqueCharacter, User user) {
UserCredentials credentials = new UserCredentials();
credentials.setName("UserCredentials" + uniqueCharacter);
credentials.setUsername("Username" + uniqueCharacter);
credentials.setPassword("Password" + uniqueCharacter);
credentials.setUserInfo(user);
user.setUserCredentials(credentials);
return credentials;
}
use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class UserSettingController method getUserSettingsByUser.
@RequestMapping(method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public Map<String, Serializable> getUserSettingsByUser(@RequestParam(required = false) String user, @RequestParam(required = false, defaultValue = "true") boolean useFallback, HttpServletRequest request, HttpServletResponse response) throws WebMessageException, IOException {
UserCredentials credentials = userService.getUserCredentialsByUsername(user);
User us = credentials != null ? credentials.getUser() : null;
if (us == null) {
us = currentUserService.getCurrentUser();
}
return userSettingService.getUserSettingsWithFallbackByUserAsMap(us, USER_SETTING_NAMES, useFallback);
}
Aggregations