use of org.apache.shiro.samples.sprhib.model.User in project shiro by apache.
the class DefaultUserService method createUser.
public void createUser(String username, String email, String password) {
User user = new User();
user.setUsername(username);
user.setEmail(email);
user.setPassword(new Sha256Hash(password).toHex());
userDAO.createUser(user);
}
use of org.apache.shiro.samples.sprhib.model.User in project shiro by apache.
the class ManageUsersController method showEditUserForm.
@RequestMapping(value = "/editUser", method = RequestMethod.GET)
@RequiresPermissions("user:edit")
public String showEditUserForm(Model model, @RequestParam Long userId, @ModelAttribute EditUserCommand command) {
User user = userService.getUser(userId);
command.setUserId(userId);
command.setUsername(user.getUsername());
command.setEmail(user.getEmail());
return "editUser";
}
use of org.apache.shiro.samples.sprhib.model.User in project shiro by apache.
the class ManageUsersController method editUser.
@RequestMapping(value = "/editUser", method = RequestMethod.POST)
@RequiresPermissions("user:edit")
public String editUser(Model model, @RequestParam Long userId, @ModelAttribute EditUserCommand command, BindingResult errors) {
editUserValidator.validate(command, errors);
if (errors.hasErrors()) {
return "editUser";
}
User user = userService.getUser(userId);
command.updateUser(user);
userService.updateUser(user);
return "redirect:/s/manageUsers";
}
use of org.apache.shiro.samples.sprhib.model.User in project shiro by apache.
the class SampleRealm method doGetAuthorizationInfo.
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Long userId = (Long) principals.fromRealm(getName()).iterator().next();
User user = userDAO.getUser(userId);
if (user != null) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
for (Role role : user.getRoles()) {
info.addRole(role.getName());
info.addStringPermissions(role.getPermissions());
}
return info;
} else {
return null;
}
}
use of org.apache.shiro.samples.sprhib.model.User in project shiro by apache.
the class SampleRealm method doGetAuthenticationInfo.
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
User user = userDAO.findUser(token.getUsername());
if (user != null) {
return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), getName());
} else {
return null;
}
}
Aggregations