电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

Springboot和SpringSecurity4最新整合实例VIP免费

Springboot和SpringSecurity4最新整合实例_第1页
1/16
Springboot和SpringSecurity4最新整合实例_第2页
2/16
Springboot和SpringSecurity4最新整合实例_第3页
3/16
1 Spring boot+Spring Security 4 配置整合实例 本例所覆盖的内容: 1. 使用Spring Security 管理用户身份认证、登录退出 2. 用户密码加密及验证 3. 采用数据库的方式实现 Spring Security 的remember-me 功能 4. 获取登录用户信息。 本例所使用的框架: 1. Spring boot 2. Spring MVC 3. Spring Security 4. Spring Data JPA 5. thymeleaf 说明: 1. 本文针对采用Spring boot 微框架之用户,完全采用Java config,不讨论 xml 配置。 2. 本例代码是完整的,请勿随意删减,否则不能运行。 一、 整合Spring Security 在 pom.xml 中加入如下片段: org.springframework.security spring-security-web org.springframework.security spring-security-config 二、 配置Spring Security 几乎所有配置都在下面这个文件中完成: 2 @Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private CustomUserDetailsService customUserDetailsService;//code1 @Autowired @Qualifier("dataSource1") private DataSource dataSource1; //code2 @Override protected void configure(HttpSecurity http) throws Exception { //允许所有用户访问”/”和”/home” http.authorizeRequests().antMatchers("/", "/home").permitAll() //其他地址的访问均需验证权限 .anyRequest().authenticated() .and() .formLogin() //指定登录页是”/login” .loginPage("/login") .permitAll() //登录成功后可使用loginSuccessHandler()存储用户信息,可选。 .successHandler(loginSuccessHandler())//code3 .and() .logout() //退出登录后的默认网址是”/home” .logoutSuccessUrl("/home") .permitAll() .invalidateHttpSession(true) .and() //登录后记住用户,下次自动登录 //数据库中必须存在名为persistent_logins的表 //建表语句见 code15 .rememberMe() .tokenValiditySeconds(1209600) //指定记住登录信息所使用的数据源 .tokenRepository(tokenRepository());//code4 } @Autowired public void configureGlobal(...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

Springboot和SpringSecurity4最新整合实例

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部