通常在服务层使用spring aop来保护方法调用. 若是在领域层,则使用aspectJ来保护. 固然保护web请求,直接使用web拦截器web
使用SecurityContextPersistenceFilter,能够在不一样的线程中共享SecurityContext,在request结束后清空SecurityContext.spring
验证完用户后,会将用用认证信息传保存到SecurityContextHolder里.数据库
spring security报错信息的本地化.ide
<bean id="messageSource" class="org.spring.framework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="classpath:org/springframework/security/messages"> </bean>
ProviderManager调用AuthenticationProvider来验证用户,如DaoAuthenticationProvider,AnonymousAuthenticationProvider,LdapAuthenticationProvider等.编码
DaoAuthenticationProvider能够经过设置userDetailService,passwordEncoder来实现.加密
in-memory Authentication能够不经过数据库来存储用户信息.spa
经过设置xx来实现.线程
不能直接存储密码字符,也不能直接使用MD5或SHA来加密密码.甚至是一个混淆值.Bcrypt被设计为很是慢以阻碍离线破解. 使用org.springframework.security.bcrypt.BCryptPasswordEncoder是一个好的选择.设计
若是是一个遗留系统,则须要选择原有的密码类型,由于hash是不可逆的.即便值受损害也不会当即暴露.一旦编码,就没法暴露.
使用混淆值能够使攻击速度放慢.