本文共 1935 字,大约阅读时间需要 6 分钟。
import org.apache.shiro.authc.AuthenticationToken;import org.springframework.beans.*;import org.springframework.validation.DataBinder;import java.util.HashMap;import java.util.Map;/** *Version: 1.0 */public class StatelessToken implements AuthenticationToken { private String username; private Map
params; private String clientDigest; public StatelessToken(String username, Map params, String clientDigest) { this.username = username; this.params = params; this.clientDigest = clientDigest; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public Map getParams() { return params; } public void setParams( Map params) { this.params = params; } public String getClientDigest() { return clientDigest; } public void setClientDigest(String clientDigest) { this.clientDigest = clientDigest; } @Override public Object getPrincipal() { return username; } @Override public Object getCredentials() { return clientDigest; } public static void main(String[] args) { } public static void test1() { StatelessToken token = new StatelessToken(null, null, null); BeanWrapperImpl beanWrapper = new BeanWrapperImpl(token); beanWrapper.setPropertyValue(new PropertyValue("username", "hjzgg")); System.out.println(token.getUsername()); } public static void test2() { StatelessToken token = new StatelessToken(null, null, null); DataBinder dataBinder = new DataBinder(token); Map params = new HashMap<>(); params.put("username", "hjzgg"); PropertyValues propertyValues = new MutablePropertyValues(params); dataBinder.bind(propertyValues); System.out.println(token.getUsername()); }}
转载地址:http://qtxqa.baihongyu.com/