Search in sources :

Example 1 with SimpleShiroToken

use of org.nutz.integration.shiro.SimpleShiroToken in project nutzboot by nutzam.

the class UserModule method login.

@Ok("json")
@Fail("http:500")
@POST
@At("/login")
public boolean login(@Param("username") String username, @Param("password") String password, HttpSession session) {
    User user = dao.fetch(User.class, username);
    if (user == null)
        return false;
    Sha256Hash hash = new Sha256Hash(password, user.getSalt());
    if (!hash.toHex().equals(user.getPassword())) {
        return false;
    }
    Subject subject = SecurityUtils.getSubject();
    subject.login(new SimpleShiroToken(user.getId()));
    return true;
}
Also used : User(io.nutz.demo.simple.bean.User) Sha256Hash(org.apache.shiro.crypto.hash.Sha256Hash) SimpleShiroToken(org.nutz.integration.shiro.SimpleShiroToken) Subject(org.apache.shiro.subject.Subject) At(org.nutz.mvc.annotation.At) POST(org.nutz.mvc.annotation.POST) Ok(org.nutz.mvc.annotation.Ok) Fail(org.nutz.mvc.annotation.Fail)

Example 2 with SimpleShiroToken

use of org.nutz.integration.shiro.SimpleShiroToken in project nutzboot by nutzam.

the class SimpleAuthorizingRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    SimpleShiroToken upToken = (SimpleShiroToken) token;
    User user = dao().fetch(User.class, (Long) upToken.getPrincipal());
    if (user == null)
        return null;
    return new SimpleAccount(user.getId(), user.getPassword(), getName());
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) User(io.nutz.demo.simple.bean.User) SimpleShiroToken(org.nutz.integration.shiro.SimpleShiroToken)

Aggregations

User (io.nutz.demo.simple.bean.User)2 SimpleShiroToken (org.nutz.integration.shiro.SimpleShiroToken)2 SimpleAccount (org.apache.shiro.authc.SimpleAccount)1 Sha256Hash (org.apache.shiro.crypto.hash.Sha256Hash)1 Subject (org.apache.shiro.subject.Subject)1 At (org.nutz.mvc.annotation.At)1 Fail (org.nutz.mvc.annotation.Fail)1 Ok (org.nutz.mvc.annotation.Ok)1 POST (org.nutz.mvc.annotation.POST)1