Spring security 获取用户主体的自定义属性
我有一个自定义的用户详细信息对象,它的名字是其中的一部分。下面的用户名可以使用,但我希望第二个用户名可以使用。如何访问此自定义属性Spring security 获取用户主体的自定义属性,spring-security,principal,Spring Security,Principal,我有一个自定义的用户详细信息对象,它的名字是其中的一部分。下面的用户名可以使用,但我希望第二个用户名可以使用。如何访问此自定义属性 <security:authentication property="principal.username" /> <security:authentication property="principal.firstname" /> 我猜想您尝试了上述方法,但无效 检查自定义用户详细信息类,以确保“firstname”属性的getter和
<security:authentication property="principal.username" />
<security:authentication property="principal.firstname" />
我猜想您尝试了上述方法,但无效
检查自定义用户详细信息类,以确保“firstname”属性的getter和setter方法的大小写正确。对我有效。以下是我的测试代码:- CustomUserDetails类
public class CustomUserDetails implements UserDetails {
public String getFirstName() {
return "hello";
}
...
}
JSP中的自定义标记
public class CustomUserDetails implements UserDetails {
public String getFirstName() {
return "hello";
}
...
}
以下标记返回hello
<security:authentication property="principal.firstName" />
。。。这样做:-
...
return new UserDetails() {
// adding extra method here will not work
public String getFirstName() {
return "hello";
}
public String getUsername() {
return "test";
}
...
};
...
// this class implements UserDetails and contains getFirstName()
CustomUserDetails csd = new CustomUserDetails();
csd.set...(...)
...
return csd;