shiro中LoginUrl与UnauthorizedUrl的作用

一 描述

1.如shiroconfig的filter

haha.html放到templates目录下,无法通过页面直接访问

需要配置一下走后台跳转

1.2 用户未登录直接访问index页面

 

 

1.3 结论

1.loginUrl:没有登录的用户,请求某个资源页面(这里是index.html)时,自动跳转到制定的haha.html页面。

2.unauthorizedUrl:登录成功的用户,访问了没有被授权的资源,自动跳转到制定的页面。

3.map.put("/**", "authc")使得所有请求都需要认证才能请求成功,否则就跳转至setLoginUrl中指定的页面,同时为了使登录页面可以在未登陆时请求成功,需要用代码map.put("/login.html","anon")进行设置。

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot与Shiro的结合可以实现灵活可扩展的权限管理系统。以下是一些可能的设计和实现方案: 1. 集成Shiro 首先,需要在pom.xml文件添加Shiro的依赖: ``` <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.4.2</version> </dependency> ``` 然后,需要在Spring Boot应用程序的配置文件添加Shiro的配置信息: ``` shiro: filterChainDefinitions: /login = anon /logout = logout /** = authc securityManager: loginUrl: /login successUrl: /home unauthorizedUrl: /unauthorized realms: - name: myRealm authenticationCacheName: authenticationCache authorizationCacheName: authorizationCache ``` 在这个配置,filterChainDefinitions指定了URL的访问规则,securityManager指定了登录、成功和未授权的URL,realms指定了数据源。 2. 定义Realm 定义Realm来实现Shiro的认证和授权功能。Realm是Shiro的核心组件之一,它是一个安全数据源,用于验证用户的身份和授权用户的访问权限。可以通过实现Realm接口来定义自己的Realm,也可以使用Shiro提供的现有的Realm实现。 自定义Realm需要实现doGetAuthenticationInfo和doGetAuthorizationInfo两个方法,分别用于身份验证和授权。 3. 集成Spring Security 另一种方案是使用Spring Security来实现权限管理。Spring Security是Spring框架的一个安全框架,它提供了身份验证、授权和其他安全功能。 集成Spring Security需要在pom.xml文件添加Spring Security的依赖: ``` <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>5.5.0</version> </dependency> ``` 然后,需要在应用程序的配置文件添加Spring Security的配置信息: ``` @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private DataSource dataSource; @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/user/**").hasRole("USER") .antMatchers("/login/**").permitAll() .and().formLogin(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.jdbcAuthentication().dataSource(dataSource) .usersByUsernameQuery("select username, password, enabled from users where username=?") .authoritiesByUsernameQuery("select username, authority from authorities where username=?"); } } ``` 在这个配置,configure方法用于配置HttpSecurity,authorizeRequests方法用于定义URL的访问规则,formLogin方法用于指定登录页面。configure方法用于配置AuthenticationManagerBuilder,jdbcAuthentication方法用于指定数据源和查询用户信息和角色信息的SQL语句。 总之,Spring Boot与Shiro或Spring Security的集成可以实现灵活可扩展的权限管理系统,可以根据具体业务需求选择适合的方案。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值