Search in sources :

Example 11 with User

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

the class UserManagementController method displayDeleteUserConfirmation.

/**
 * @param request
 * @param response
 * @param model
 * @return The pages audit set-up form page
 */
@RequestMapping(value = TgolKeyStore.DELETE_USER_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserConfirmation(HttpServletRequest request, HttpServletResponse response, Model model) {
    Object userId = request.getSession().getAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
    Long lUserId;
    if (userId instanceof Long) {
        lUserId = (Long) userId;
    } else {
        try {
            lUserId = Long.valueOf(userId.toString());
        } catch (NumberFormatException nfe) {
            throw new ForbiddenUserException();
        }
    }
    User user = getCurrentUser();
    User userToDelete = userDataService.read(lUserId);
    if (userToDelete == null || user.getId().equals(userToDelete.getId())) {
        return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    }
    for (Contract contract : userToDelete.getContractSet()) {
        deleteAllAuditsFromContract(contract);
    }
    userDataService.delete(userToDelete.getId());
    request.getSession().removeAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
    request.getSession().setAttribute(TgolKeyStore.DELETED_USER_NAME_KEY, userToDelete.getEmail1());
    return TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME;
}
Also used : User(org.asqatasun.entity.user.User) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured)

Example 12 with User

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

the class HomeController method displayHomePage.

@RequestMapping(value = TgolKeyStore.HOME_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayHomePage(Model model) {
    User user = getCurrentUser();
    model.addAttribute(TgolKeyStore.CONTRACT_LIST_KEY, contractSortCommandHelper.prepareContractInfo(user, null, displayOptionFieldsBuilderList, model));
    return TgolKeyStore.HOME_VIEW_NAME;
}
Also used : User(org.asqatasun.entity.user.User) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with User

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

the class UserDAO method isAccountActivated.

public boolean isAccountActivated(String email) {
    Query query = entityManager.createQuery("SELECT u FROM " + getEntityClass().getName() + " u" + " WHERE u.email = :email");
    query.setParameter("email", email);
    try {
        return ((User) query.getSingleResult()).isAccountActivated();
    } catch (NoResultException e) {
        return false;
    }
}
Also used : User(org.asqatasun.entity.user.User) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 14 with User

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

the class UserManagementControllerTest method testSubmitAddUserForm.

/**
 * Test of submitAddUserForm method, of class UserManagementController.
 */
@Test
public void testSubmitAddUserForm() throws Exception {
    setUpMockRoleDataService();
    setUpMockUserDataService(true, false, false);
    setUpMockAuthenticationContext();
    // Finally the form is conform and the admin page is returned
    CreateUserCommand createUserCommand = createUserCommandFactory.getNewCreateUserCommand();
    createUserCommand.setSiteUrl("http://www.newSite.com/");
    createUserCommand.setEmail("newUser@test.com");
    createUserCommand.setPassword("P4sSw0rD");
    createUserCommand.setConfirmPassword("P4sSw0rD");
    BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    Model model = new ExtendedModelMap();
    String result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
    assertEquals(ADMIN_VIEW_NAME, result);
    assertFalse(bindingResult.hasErrors());
    assertTrue(bindingResult.getFieldErrors().isEmpty());
    assertEquals(2, model.asMap().size());
    assertEquals("newUser@test.com", model.asMap().get(ADDED_USER_NAME_KEY));
    assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) User(org.asqatasun.entity.user.User) Model(org.springframework.ui.Model) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with User

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

the class UserManagementControllerTest method testSubmitEditCurrentUserForm.

/**
 * Test of submitEditUserForm method, of class UserManagementController.
 */
@Test
public void testSubmitEditCurrentUserForm() throws Exception {
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, true);
    setUpMockAuthenticationContext();
    // Finally the form is conform and the admin page is returned
    CreateUserCommand createUserCommand = createUserCommandFactory.getNewCreateUserCommand();
    createUserCommand.setEmail("admin@test.com");
    createUserCommand.setLastName("newName");
    createUserCommand.setFirstName("newFirstName");
    createUserCommand.setPhoneNumber("0102030405");
    createUserCommand.setActivated(false);
    createUserCommand.setAdmin(false);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, 4L);
    BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    Model model = new ExtendedModelMap();
    String result = instance.submitEditUserForm(createUserCommand, bindingResult, request, model);
    assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
    assertFalse(bindingResult.hasErrors());
    assertTrue(bindingResult.getFieldErrors().isEmpty());
    assertEquals(2, model.asMap().size());
    assertEquals("admin@test.com", model.asMap().get(TgolKeyStore.UPDATED_USER_NAME_KEY));
    assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) User(org.asqatasun.entity.user.User) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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