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());
}
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();
}
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());
}
Aggregations