要了解Acegi,首先要了解以下几个重要概念:
public void getSecurityContextInformations() {
SecurityContext sc = SecurityContextHolder.getContext();
Authentication auth = sc.getAuthentication();
Object principal = auth.getPrincipal();
if (principal instanceof UserDetails) {
//用户密码
String password = ((UserDetails) principal).getPassword();
//用户名称
String username = ((UserDetails) principal).getUsername();
//用户权限
GrantedAuthority[] authorities = ((UserDetails) principal).getAuthorities();
for (int i = 0; i < authorities.length; i++) {
String authority = authorities[i].getAuthority();
}
}
Object details = auth.getDetails();
if (details instanceof WebAuthenticationDetails) {
//用户session id
String SessionId = ((WebAuthenticationDetails) details).getSessionId();
}
}