Search in sources :

Example 1 with UserCredentials

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();
}
Also used : Query(org.hibernate.Query) UserCredentials(org.hisp.dhis.user.UserCredentials)

Example 2 with UserCredentials

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();
}
Also used : Query(org.hibernate.Query) UserCredentials(org.hisp.dhis.user.UserCredentials)

Example 3 with UserCredentials

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();
}
Also used : Query(org.hibernate.Query) UserCredentials(org.hisp.dhis.user.UserCredentials)

Example 4 with UserCredentials

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) QueryItem(org.hisp.dhis.common.QueryItem) Program(org.hisp.dhis.program.Program) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) UserCredentials(org.hisp.dhis.user.UserCredentials) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 5 with UserCredentials

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;
}
Also used : User(org.hisp.dhis.user.User) UserCredentials(org.hisp.dhis.user.UserCredentials)

Aggregations

UserCredentials (org.hisp.dhis.user.UserCredentials)29 User (org.hisp.dhis.user.User)15 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 Query (org.hibernate.Query)4 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)4 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)3 DataSet (org.hisp.dhis.dataset.DataSet)3 UserGroup (org.hisp.dhis.user.UserGroup)3 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)2 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 Program (org.hisp.dhis.program.Program)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 List (java.util.List)1