SpringSecurity学习2
从数据库或者其他数据源加载用户数据
1.ApplicationContext.xml配置,根据密码是加密过和使用salt的,则在<authentication-provider>中需要配置<password-encoder>和<salt-source>
?
<beans:property name="userPropertyToUse" value="salt" /> salt在UserDetail获取getSalt()方法的返回值
?
?
2.实现UserDetailService
?
package lan.model;import org.springframework.security.core.GrantedAuthority; public class Role implements GrantedAuthority { private static final long serialVersionUID = -2431947985974407523L; private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String getAuthority() { return name; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Role other = (Role) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; }}?