Search in sources :

Example 1 with User

use of sample.data.User in project gs-spring-security-3.2 by rwinch.

the class MessageController method create.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView create(@Valid MessageForm messageForm, BindingResult result, RedirectAttributes redirect) {
    User to = userRepository.findByEmail(messageForm.getToEmail());
    if (to == null) {
        result.rejectValue("toEmail", "toEmail", "User not found");
    }
    if (result.hasErrors()) {
        return new ModelAndView("messages/compose");
    }
    Message message = new Message();
    message.setSummary(messageForm.getSummary());
    message.setText(messageForm.getText());
    message.setTo(to);
    message = messageRepository.save(message);
    redirect.addFlashAttribute("globalMessage", "Message added successfully");
    return new ModelAndView("redirect:/{message.id}", "message.id", message.getId());
}
Also used : CurrentUser(sample.security.CurrentUser) User(sample.data.User) Message(sample.data.Message) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with User

use of sample.data.User in project gs-spring-security-3.2 by rwinch.

the class SecurityTests method setup.

@Before
public void setup() {
    // NOTE: Could also load rob from UserRepository if we wanted
    rob = new User();
    rob.setId(0L);
    rob.setEmail("rob@example.com");
    rob.setFirstName("Rob");
    rob.setLastName("Winch");
    mvc = MockMvcBuilders.webAppContextSetup(context).addFilters(springSecurityFilterChain).build();
}
Also used : User(sample.data.User) Before(org.junit.Before)

Example 3 with User

use of sample.data.User in project gs-spring-security-3.2 by rwinch.

the class MessagePermissionEvaluator method hasPermission.

/* (non-Javadoc)
	 * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
	 */
@Override
public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
    if (authentication == null) {
        return false;
    }
    Message message = (Message) targetDomainObject;
    if (message == null) {
        return true;
    }
    User currentUser = (User) authentication.getPrincipal();
    return currentUser.getId().equals(message.getTo().getId());
}
Also used : User(sample.data.User) Message(sample.data.Message)

Aggregations

User (sample.data.User)3 Message (sample.data.Message)2 Before (org.junit.Before)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 CurrentUser (sample.security.CurrentUser)1