Search in sources :

Example 1 with Authority

use of com.nixmash.blog.jpa.model.Authority in project nixmash-blog by mintster.

the class AdminController method roleList.

@RequestMapping(value = "/roles", method = GET)
public ModelAndView roleList(Model model) {
    ModelAndView mav = new ModelAndView();
    mav.addObject("roles", userService.getRoles());
    mav.addObject("newRole", new Authority());
    mav.setViewName(ADMIN_ROLES_VIEW);
    return mav;
}
Also used : Authority(com.nixmash.blog.jpa.model.Authority) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 2 with Authority

use of com.nixmash.blog.jpa.model.Authority in project nixmash-blog by mintster.

the class AdminController method updateRole.

// endregion
// region Roles
@RequestMapping(value = "/roles/update/{Id}", method = RequestMethod.POST)
public String updateRole(@Valid @ModelAttribute(value = "authority") RoleDTO roleDTO, BindingResult result, RedirectAttributes attributes, Model model) {
    if (result.hasErrors()) {
        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_ERROR);
        return "redirect:/admin/roles";
    } else {
        Authority authority = userService.getAuthorityById(roleDTO.getId());
        if (authority.isLocked()) {
            webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_IS_LOCKED, roleDTO.getAuthority().toUpperCase());
            return "redirect:/admin/roles";
        } else {
            userService.updateAuthority(roleDTO);
            webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_UPDATED, roleDTO.getAuthority());
            return "redirect:/admin/roles";
        }
    }
}
Also used : Authority(com.nixmash.blog.jpa.model.Authority)

Example 3 with Authority

use of com.nixmash.blog.jpa.model.Authority in project nixmash-blog by mintster.

the class AdminController method addUser.

@RequestMapping(value = "/roles/new", method = RequestMethod.POST)
public String addUser(@Valid RoleDTO roleDTO, BindingResult result, SessionStatus status, RedirectAttributes attributes) {
    if (result.hasErrors()) {
        return ADMIN_ROLES_VIEW;
    } else {
        Authority authority = userService.createAuthority(roleDTO);
        logger.info("Role Added: {}", authority);
        status.setComplete();
        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_ADDED, authority.getAuthority());
        return "redirect:/admin/roles";
    }
}
Also used : Authority(com.nixmash.blog.jpa.model.Authority)

Example 4 with Authority

use of com.nixmash.blog.jpa.model.Authority in project nixmash-blog by mintster.

the class AdminController method deleteRole.

@RequestMapping(value = "/roles/update/{Id}", params = { "deleteRole" }, method = RequestMethod.POST)
public String deleteRole(@Valid @ModelAttribute(value = "authority") RoleDTO roleDTO, BindingResult result, RedirectAttributes attributes, Model model) {
    if (result.hasErrors()) {
        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_ERROR);
        return "redirect:/admin/roles";
    } else {
        Authority authority = userService.getAuthorityById(roleDTO.getId());
        if (authority.isLocked()) {
            webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_IS_LOCKED, roleDTO.getAuthority());
        } else {
            Collection<User> users = userService.getUsersByAuthorityId(roleDTO.getId());
            userService.deleteAuthority(authority, users);
            webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_DELETED, roleDTO.getAuthority(), users.size());
        }
        return "redirect:/admin/roles";
    }
}
Also used : User(com.nixmash.blog.jpa.model.User) Authority(com.nixmash.blog.jpa.model.Authority)

Example 5 with Authority

use of com.nixmash.blog.jpa.model.Authority in project nixmash-blog by mintster.

the class TestUtil method createTestUserDTO.

// UserDTO as passed to userService.create(UserDTO)
public static UserDTO createTestUserDTO(String username, String firstName, String lastName, String email) {
    UserDTO userDTO = new UserDTO();
    userDTO.setFirstName(firstName);
    userDTO.setUsername(username);
    userDTO.setLastName(lastName);
    userDTO.setPassword("password");
    userDTO.setEmail(email);
    userDTO.setSignInProvider(SignInProvider.SITE);
    userDTO.setAuthorities(Lists.newArrayList(new Authority("ROLE_USER")));
    return userDTO;
}
Also used : Authority(com.nixmash.blog.jpa.model.Authority) UserDTO(com.nixmash.blog.jpa.dto.UserDTO)

Aggregations

Authority (com.nixmash.blog.jpa.model.Authority)8 UserDTO (com.nixmash.blog.jpa.dto.UserDTO)3 User (com.nixmash.blog.jpa.model.User)2 SocialUserDTO (com.nixmash.blog.jpa.dto.SocialUserDTO)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1