Search in sources :

Example 6 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class AccountSettingsController method displayAccountSettingsPage.

/**
 * This method displays the form for an authenticated user
 *
 * @param model
 * @return
 */
@RequestMapping(value = TgolKeyStore.ACCOUNT_SETTINGS_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayAccountSettingsPage(Model model) {
    User user = getCurrentUser();
    if (this.forbiddenUserList.contains(user.getEmail1())) {
        throw new ForbiddenPageException();
    }
    secondaryLevelMenuDisplayer.setModifiableReferentialsForUserToModel(user, model);
    return prepateDataAndReturnCreateUserView(model, user, TgolKeyStore.ACCOUNT_SETTINGS_VIEW_NAME);
}
Also used : User(org.asqatasun.entity.user.User) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class UserManagementController method displayDeleteUserPage.

/**
 * @param userId
 * @param request
 * @param response
 * @param model
 * @return The pages audit set-up form page
 */
@RequestMapping(value = TgolKeyStore.DELETE_USER_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserPage(@RequestParam(TgolKeyStore.USER_ID_KEY) String userId, HttpServletRequest request, HttpServletResponse response, Model model) {
    Long lUserId;
    try {
        lUserId = Long.valueOf(userId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenUserException();
    }
    User userToDelete = userDataService.read(lUserId);
    if (userToDelete == null || getCurrentUser().getId().equals(userToDelete.getId())) {
        return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    }
    model.addAttribute(TgolKeyStore.USER_NAME_TO_DELETE_KEY, userToDelete.getEmail1());
    request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, userToDelete.getId());
    return TgolKeyStore.DELETE_USER_VIEW_NAME;
}
Also used : User(org.asqatasun.entity.user.User) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Secured(org.springframework.security.access.annotation.Secured)

Example 8 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class UserManagementController method submitCreateUserForm.

/**
 * A new user can be created from the main form that can be accessed without
 * being authentified. In this case, we check the validity of the filled-in
 * url and we prevent the new users to be activated and created with admin
 * privileges.
 * On the other side, if the user is created from the admin interface, it can
 * be set with activation and admin privileges info but the check of the url
 * is useless cause the field has been removed from the form.
 *
 * @param createUserCommand
 * @param result
 * @param model
 * @param successViewName
 * @param errorViewName
 * @param successMessageKey
 * @return
 * @throws Exception
 */
private String submitCreateUserForm(CreateUserCommand createUserCommand, BindingResult result, Model model, String successViewName, String errorViewName, String successMessageKey) throws Exception {
    // We check whether the form is valid
    createUserFormValidator.validate(createUserCommand, result);
    // If the form has some errors, we display it again with errors' details
    if (result.hasErrors()) {
        return displayFormWithErrors(model, createUserCommand, errorViewName);
    }
    User user = createUser(createUserCommand, true, true);
    model.addAttribute(TgolKeyStore.USER_LIST_KEY, userDataService.findAll());
    model.addAttribute(successMessageKey, user.getEmail1());
    return successViewName;
}
Also used : User(org.asqatasun.entity.user.User)

Example 9 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class UserManagementController method displayDeleteUserAuditsPage.

/**
 * @param userId
 * @param request
 * @param response
 * @param model
 * @return
 */
@RequestMapping(value = TgolKeyStore.DELETE_USER_AUDITS_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserAuditsPage(@RequestParam(TgolKeyStore.USER_ID_KEY) String userId, HttpServletRequest request, HttpServletResponse response, Model model) {
    Long lUserId;
    try {
        lUserId = Long.valueOf(userId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenUserException();
    }
    User userToDelete = userDataService.read(lUserId);
    model.addAttribute(TgolKeyStore.USER_NAME_TO_DELETE_KEY, userToDelete.getEmail1());
    request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, userToDelete.getId());
    return TgolKeyStore.DELETE_AUDITS_VIEW_NAME;
}
Also used : User(org.asqatasun.entity.user.User) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Secured(org.springframework.security.access.annotation.Secured)

Example 10 with User

use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.

the class UserManagementController method createUser.

/**
 * Create a user entit
 * @param createUserCommand
 * @return
 * @throws Exception
 */
private User createUser(CreateUserCommand createUserCommand, boolean allowActivation, boolean allowAdmin) throws Exception {
    User user = userDataService.create();
    user.setEmail1(createUserCommand.getEmail());
    user.setFirstName(createUserCommand.getFirstName());
    user.setName(createUserCommand.getLastName());
    user.setPhoneNumber(createUserCommand.getPhoneNumber());
    user.setPassword(MD5Encoder.MD5(createUserCommand.getPassword()));
    user.setWebUrl1(createUserCommand.getSiteUrl());
    if (allowActivation) {
        user.setAccountActivation(createUserCommand.getActivated());
    } else {
        user.setAccountActivation(false);
    }
    if (allowAdmin && createUserCommand.getAdmin()) {
        user.setRole(createUserCommandFactory.getAdminRole());
    } else {
        user.setRole(createUserCommandFactory.getUserRole());
    }
    userDataService.saveOrUpdate(user);
    return user;
}
Also used : User(org.asqatasun.entity.user.User)

Aggregations

User (org.asqatasun.entity.user.User)40 Secured (org.springframework.security.access.annotation.Secured)14 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Contract (org.asqatasun.entity.contract.Contract)5 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)5 Test (org.junit.Test)5 NoResultException (javax.persistence.NoResultException)4 Query (javax.persistence.Query)4 CreateUserCommand (org.asqatasun.webapp.command.CreateUserCommand)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)4 Model (org.springframework.ui.Model)4 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 BindingResult (org.springframework.validation.BindingResult)4 List (java.util.List)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 ArrayList (java.util.ArrayList)1 OptionElement (org.asqatasun.entity.option.OptionElement)1