use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class HibernateCurrentUserStore method getUserCredentialsByUsername.
@Override
public UserCredentials getUserCredentialsByUsername(String username) {
String hql = "from UserCredentials uc where uc.username = :username";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
query.setString("username", username);
query.setCacheable(true);
return (UserCredentials) query.uniqueResult();
}
use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class HibernateUserCredentialsStore method getUserCredentialsByOpenId.
@Override
public UserCredentials getUserCredentialsByOpenId(String openId) {
Query query = getQuery("from UserCredentials uc where uc.openId = :openId");
query.setString("openId", openId);
return (UserCredentials) query.uniqueResult();
}
use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class HibernateUserCredentialsStore method getUserCredentialsByLdapId.
public UserCredentials getUserCredentialsByLdapId(String ldapId) {
Query query = getQuery("from UserCredentials uc where uc.ldapId = :ldapId");
query.setString("ldapId", ldapId);
return (UserCredentials) query.uniqueResult();
}
use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class AbstractEventService method getFromUrl.
@Override
public EventSearchParams getFromUrl(String program, String programStage, ProgramStatus programStatus, Boolean followUp, String orgUnit, OrganisationUnitSelectionMode orgUnitSelectionMode, String trackedEntityInstance, Date startDate, Date endDate, Date dueDateStart, Date dueDateEnd, Date lastUpdatedStartDate, Date lastUpdatedEndDate, EventStatus status, DataElementCategoryOptionCombo attributeOptionCombo, IdSchemes idSchemes, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, List<Order> orders, List<String> gridOrders, boolean includeAttributes, Set<String> events, Set<String> filters, Set<String> dataElements, boolean includeDeleted) {
UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
EventSearchParams params = new EventSearchParams();
Program pr = programService.getProgram(program);
if (StringUtils.isNotEmpty(program) && pr == null) {
throw new IllegalQueryException("Program is specified but does not exist: " + program);
}
ProgramStage ps = programStageService.getProgramStage(programStage);
if (StringUtils.isNotEmpty(programStage) && ps == null) {
throw new IllegalQueryException("Program stage is specified but does not exist: " + programStage);
}
OrganisationUnit ou = organisationUnitService.getOrganisationUnit(orgUnit);
if (StringUtils.isNotEmpty(orgUnit) && ou == null) {
throw new IllegalQueryException("Org unit is specified but does not exist: " + orgUnit);
}
if (ou != null && !organisationUnitService.isInUserHierarchy(ou)) {
if (!userCredentials.isSuper() && !userCredentials.isAuthorized("F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS")) {
throw new IllegalQueryException("User has no access to organisation unit: " + ou.getUid());
}
}
if (pr != null && !userCredentials.isSuper() && !userCredentials.canAccessProgram(pr)) {
throw new IllegalQueryException("User has no access to program: " + pr.getUid());
}
TrackedEntityInstance tei = entityInstanceService.getTrackedEntityInstance(trackedEntityInstance);
if (StringUtils.isNotEmpty(trackedEntityInstance) && tei == null) {
throw new IllegalQueryException("Tracked entity instance is specified but does not exist: " + trackedEntityInstance);
}
if (events != null && filters != null) {
throw new IllegalQueryException("Event UIDs and filters can not be specified at the same time");
}
if (events == null) {
events = new HashSet<>();
}
if (filters != null) {
if (StringUtils.isNotEmpty(programStage) && ps == null) {
throw new IllegalQueryException("ProgramStage needs to be specified for event filtering to work");
}
for (String filter : filters) {
QueryItem item = getQueryItem(filter);
params.getFilters().add(item);
}
}
if (dataElements != null) {
for (String de : dataElements) {
QueryItem dataElement = getQueryItem(de);
params.getDataElements().add(dataElement);
}
}
params.setProgram(pr);
params.setProgramStage(ps);
params.setOrgUnit(ou);
params.setTrackedEntityInstance(tei);
params.setProgramStatus(programStatus);
params.setFollowUp(followUp);
params.setOrgUnitSelectionMode(orgUnitSelectionMode);
params.setStartDate(startDate);
params.setEndDate(endDate);
params.setDueDateStart(dueDateStart);
params.setDueDateEnd(dueDateEnd);
params.setLastUpdatedStartDate(lastUpdatedStartDate);
params.setLastUpdatedEndDate(lastUpdatedEndDate);
params.setEventStatus(status);
params.setCategoryOptionCombo(attributeOptionCombo);
params.setIdSchemes(idSchemes);
params.setPage(page);
params.setPageSize(pageSize);
params.setTotalPages(totalPages);
params.setSkipPaging(skipPaging);
params.setIncludeAttributes(includeAttributes);
params.setOrders(orders);
params.setGridOrders(gridOrders);
params.setEvents(events);
params.setIncludeDeleted(includeDeleted);
return params;
}
use of org.hisp.dhis.user.UserCredentials in project dhis2-core by dhis2.
the class UpdateUserAccountAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
// ---------------------------------------------------------------------
// Prepare values
// ---------------------------------------------------------------------
email = StringUtils.trimToNull(email);
rawPassword = StringUtils.trimToNull(rawPassword);
User user = userService.getUser(id);
UserCredentials credentials = user.getUserCredentials();
String currentPassword = credentials.getPassword();
if (!credentials.isExternalAuth() && !passwordManager.matches(oldPassword, currentPassword)) {
message = i18n.getString("wrong_password");
return INPUT;
}
// ---------------------------------------------------------------------
// Update userCredentials and user
// ---------------------------------------------------------------------
user.setSurname(surname);
user.setFirstName(firstName);
user.setEmail(email);
user.setPhoneNumber(phoneNumber);
userService.encodeAndSetPassword(user, rawPassword);
userService.updateUserCredentials(credentials);
userService.updateUser(user);
message = i18n.getString("update_user_success");
return SUCCESS;
}
Aggregations