Spring 安全框架

公有接口

public interface AuthenticationManager {
public Authentication authenticate(Authentication authentication)
throws AuthenticationException;
}

The idea of ProviderManager is to enable you to authenticate users against multiple
identity management sources. Rather than relying on itself to perform
authentication, ProviderManager steps one by one through a collection of authentication
providers, until one of them successfully authenticates the user (or until it
runs out of providers).

数据库验证(两个实现)

■ DaoAuthenticationProvider   实现时获得用户名和密码
■ PasswordDaoAuthenticationProvider 委托给DAO来实现安全验证

<bean id="authenticationProvider" class="net.sf.acegisecurity.
providers.dao.DaoAuthenticationProvider">
<property name="authenticationDao">
<ref bean="authenticationDao"/>
</property>
</bean>

2个实现

InMemoryDaoImpl 和 JdbcDaoImpl.

<bean id="authenticationDao"
class="net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>

When JdbcDaoImpl looks up user information, it will use “SELECT username,
password, enabled FROM users WHERE username = ?” as its query.

通过usersByUserNameQuery.方法来实现

配置信息

<bean id="authenticationDao"
class="net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="usersByUserNameQuery">
<value>SELECT login, password
FROM student WHERE login=?</value>
</property>
</bean>

<bean id="authenticationDao"
class="net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="usersByUserNameQuery">
<value>SELECT login, password
FROM student WHERE login=?</value>
</property>
</bean>

In the case of JdbcDaoImpl, the MappingSqlQuery given in the usersByUser-
NameMapping is expected to convert a ResultSet (resulting from running the user
query) into a net.sf.acegisecurity.UserDetails object.

public class UsersByUsernameMapping extends MappingSqlQuery {
protected UsersByUsernameMapping(DataSource dataSource) {
super(dataSource, usersByUsernameQuery);
declareParameter(new SqlParameter(Types.VARCHAR));
compile();
}
protected Object mapRow(ResultSet rs, int rownum)
throws SQLException {
String username = rs.getString(1);
String password = rs.getString(2);
UserDetails user = new User(username, password, true,
new GrantedAuthority[]
{new GrantedAuthorityImpl("HOLDER")});
return user;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值