![](/img/trans.png)
[英]Understanding “Access Denied” in spring security with custom authentication
[英]Spring security custom authentication how to access firstname and lastname
我正在使用使用凭据和ipaddress的自定义身份验证,但是,我需要在UI上显示用户的名字和姓氏。 尽管我没有使用UserDetails,而是使用UsernamePasswordAuthenticationToken,但我如何访问名字和姓氏,其中UserDetails bean保存在Details中。
Account account = (Account)accountDao.loadUserByUsername(username);
if(!account.getPassword().equals(password)) {
logger.debug("[USER AUTHENTICATION]Invalid Password:"+password);
return null;
}
logger.warn(String.format("[USER AUTHENTICATION]%s %s",new Object[]{account.getFirstName(),account.getLastName()}));
isAuthenticatedByIP = false;
for(AllowedIPAddress allowedIpAddress:account.getAllowedIPs()){
if(allowedIpAddress.getIpAddress().equals("0.0.0.0")||allowedIpAddress.getIpAddress().equals(userIPAddress)) {
isAuthenticatedByIP = true;
break;
}
}
// Authenticated, the user's IP address matches one in the database
if (isAuthenticatedByIP)
{
logger.debug("[USER AUTHENTICATION]isAuthenticatedByIP is true, IP Addresses match");
UsernamePasswordAuthenticationToken result = null;
result = new UsernamePasswordAuthenticationToken(account.getUsername(), account.getPassword(), account.getAuthorities()) ;
result.setDetails(account);
return result
} else {
logger.warn("[USER AUTHENTICATION]User IP not allowed "+userIPAddress);
}
如何在jsp中获取帐户字段以向用户显示欢迎消息。
在spring mvc中,您可以将自定义userDetail bean设置为会话范围的bean,并在成功登录后在其中设置您的require值,例如firstname,lastname等。您可以在任意位置使用该值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.