spring security和shiro的安全处理

spring security和shiro的安全处理,第1张

spring security和shiro的安全处理 spring security和shiro的安全处理

文章目录
  • spring security和shiro的安全处理
    • 依赖
    • 视图配置
    • 用户认证和授权
    • 注销及权限控制
    • 记住我及首页地址

依赖
 
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
        
        
            org.springframework.security
            spring-security-web
            5.1.4.RELEASE
        
        
        
            org.springframework.security
            spring-security-config
            5.1.4.RELEASE
        
        
        
            org.thymeleaf
            thymeleaf-spring5
            3.0.11.RELEASE
        
    

视图配置
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		// 浏览器访问的地址
//		String urlPath = "/auth/to/reg.html";
		// 要跳转的视图页面的名称,会加载配置文件中的视图前后缀
//		String viewName = "register";
		registry.addViewController("/vip1").setViewName("vip1/test1.html");
	}
	// 这是拦截器,如果定制拦截器就是重写这个方法
    
}

用户认证和授权
@EnableWebSecurity
public class MySecurity extends WebSecurityConfigurerAdapter {
	@Override
	protected void configure(HttpSecurity http) throws Exception {
			http.authorizeRequests().antMatchers("/").permitAll()
					.antMatchers("/a").hasRole("vip1")
					.antMatchers("/vip1
	@Override
	protected void configure(AuthenticationManagerBuilder auth) throws Exception {
		auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder())
				.withUser("hjx").password(new BCryptPasswordEncoder().encode("123")).roles("common")
				.and()
				.withUser("root").password(new BCryptPasswordEncoder().encode("123")).roles("vip1","vip2","vip3");
	}

}

注销及权限控制 记住我及首页地址

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5685609.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存