use of io.nutz.demo.simple.bean.User in project nutzboot by nutzam.
the class SimpleAuthorizingRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// null usernames are invalid
if (principals == null) {
throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
}
long userId = ((Number) principals.getPrimaryPrincipal()).longValue();
User user = dao().fetch(User.class, userId);
if (user == null)
return null;
SimpleAuthorizationInfo auth = new SimpleAuthorizationInfo();
auth.addRole(user.getName());
auth.addStringPermission("user:list");
return auth;
}
use of io.nutz.demo.simple.bean.User in project nutzboot by nutzam.
the class MainLauncher method newUser.
protected static User newUser(String name, String password) {
User user = new User();
user.setName(name);
user.setSalt(R.UU32());
user.setPassword(new Sha256Hash(password, user.getSalt()).toHex());
user.setCreateTime(new Date());
return user;
}
use of io.nutz.demo.simple.bean.User 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());
}
use of io.nutz.demo.simple.bean.User in project nutzboot by nutzam.
the class MainLauncher method init.
public void init() {
ZMoCo co = zmodb.cc("user", true);
ZMo mo = ZMo.me();
co.insert(mo.toDoc(new User("apple", 40, "北京")));
co.insert(mo.toDoc(new User("apple", 40, "北京")));
co.insert(mo.toDoc(new User("ball", 30, "未知")));
co.insert(mo.toDoc(new User("cat", 50, "温哥华")));
co.insert(mo.toDoc(new User("fox", 51, "纽约")));
co.insert(mo.toDoc(new User("bra", 25, "济南")));
co.insert(mo.toDoc(new User("lina", 50, "深圳")));
}
use of io.nutz.demo.simple.bean.User 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;
}
Aggregations