Java tutorial
/******************************************************************************* * Copyright (c) 2005, 2014 springside.github.io * * Licensed under the Apache License, Version 2.0 (the "License"); *******************************************************************************/ package com.citylife.backend.shiro; import javax.annotation.PostConstruct; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.authc.SimpleAuthenticationInfo; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.subject.PrincipalCollection; public class ShiroDbRealm extends AuthorizingRealm { public static final String HASH_ALGORITHM = "SHA-1"; public static final int HASH_INTERATIONS = 1024; /** * ?,. */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { //token???? UsernamePasswordToken upToken = (UsernamePasswordToken) token; //??? String tel = upToken.getUsername(); String password = String.valueOf(upToken.getPassword()); //TODO ?????info?AuthenticationException SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(tel, password.toCharArray(), getName()); System.out.println("?,."); return info; } /** * ?, ???. */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { // ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal(); // User user = userService.findByUserName(shiroUser.loginName); // String userName = (String) getAvailablePrincipal(principals); //TODO ????info // SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); // info.setStringPermissions(set?); // info.setRoles(set?); // info.setObjectPermissions(set?); // System.out.println(userName + " : aaaaa: " + user.getUsername()); System.out.println("?, ???."); return null; } /** * PasswordHash. */ @PostConstruct public void initCredentialsMatcher() { // HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(HASH_ALGORITHM); // matcher.setHashIterations(HASH_INTERATIONS); // setCredentialsMatcher(matcher); System.out.println("PasswordHash."); } }