Search in sources :

Example 16 with UserCredentials

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

Example 17 with UserCredentials

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

Example 18 with UserCredentials

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;
}
Also used : ArrayList(java.util.ArrayList) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) UserCredentials(org.hisp.dhis.user.UserCredentials)

Example 19 with UserCredentials

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

Example 20 with UserCredentials

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);
}
Also used : User(org.hisp.dhis.user.User) UserCredentials(org.hisp.dhis.user.UserCredentials) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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