Search in sources :

Example 1 with User

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);
}
Also used : User(org.apache.shiro.samples.sprhib.model.User) Sha256Hash(org.apache.shiro.crypto.hash.Sha256Hash)

Example 2 with 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";
}
Also used : User(org.apache.shiro.samples.sprhib.model.User) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with User

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";
}
Also used : User(org.apache.shiro.samples.sprhib.model.User) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with User

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;
    }
}
Also used : Role(org.apache.shiro.samples.sprhib.model.Role) User(org.apache.shiro.samples.sprhib.model.User) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo)

Example 5 with User

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;
    }
}
Also used : User(org.apache.shiro.samples.sprhib.model.User)

Aggregations

User (org.apache.shiro.samples.sprhib.model.User)5 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1 Sha256Hash (org.apache.shiro.crypto.hash.Sha256Hash)1 Role (org.apache.shiro.samples.sprhib.model.Role)1