weixin_42049892 2019-06-29 19:35 采纳率: 0%
浏览 646

ssm+cas+shiro+maven重定向问题,报错Caused by: java.io.FileNotFoundException

ssm+cas+shiro+maven多次重定向问题,报错Caused by: java.io.FileNotFoundException,追踪源码发现是conn.getInputStream()执行时报的错, this.getResponseCode()=410,410代表删除了文件.。怎么解决

重定向问题,加“/”不能解决该问题啊。loginUrl设置为http://127.0.0.1:9000/cas-shiro-ehcache2/login?service=http://127.0.0.1:9001/cas_shiro_redis_ssm/weblogin/,/weblogin=casFilter,加个“/”,只是跳过了casFilter,然后http://http://127.0.0.1:9001/cas_shiro_redis_ssm/weblogin?ticket=ST-21-rY7ndd2byXqAQ3fXdphO-cas01.example.org没有对应的页面肯定要调到错误页面的。问题我也遇到了解决不了,我的报错:Caused by: java.io.FileNotFoundException: http://127.0.0.1:9000/cas-shiro-ehcache2/login/serviceValidate?ticket=ST-45-2ucmZxknZmSIncboScar-cas01.example.org&service=http%3A%2F%2F127.0.0.1%3A9001%2Fcas_shiro_redis_ssm%2Fweblogin%2F
,我追踪源码查到in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
conn.getInputStream()执行时报的错,意思是从cas服务器查找不到生成的 ticket文件: http://127.0.0.1:9000/cas-shiro-ehcache2/login/serviceValidate?ticket=ST-45-2ucmZxknZmSIncboScar-cas01.example.org&service=http%3A%2F%2F127.0.0.1%3A9001%2Fcas_shiro_redis_ssm%2Fweblogin%2F,请求代码应该是var33 = this.getResponseCode()=410,410代表删除了文件。可是我下载的别人的源码和别人的cas服务器没问题,cas服务器我也和别人的调换试过,还是不行,说明我的代码写的有问题,不知道咋改,怎样才能不出现410.我下载的别人的demo运行正常。奇怪

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-10 16:15
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    这个问题是由Apache Shiro框架在处理登录验证过程中遇到的问题导致的。

    Apache Shiro使用Spring Security进行身份验证,并且在处理登录失败时会抛出一个AuthenticationException异常。在这个异常中,Shiro会尝试从session中获取用户信息,但是由于网络连接问题(例如,HTTP状态码为410),这可能会导致AuthenticationException被抛出。

    为了解决这个问题,你可以考虑以下几种方法:

    1. 重新配置你的登录流程以避免依赖于HTTP状态码。
    2. 在你的应用程序中添加一个超时功能,以便当连接超过一定时间后自动断开连接。
    3. 尝试使用其他方式来传递登录凭证,比如通过URL参数或者Cookie等。

    此外,你也可以考虑在Shiro中添加一些日志记录,以便更清晰地理解发生的问题以及如何解决它。以下是一个简单的示例,展示了如何在Shiro中添加一条日志消息:

    ShiroConfig shiroConfig = new ShiroConfig();
    shiroConfig.setLoginUrl("/login");
    shiroConfig.setUnauthorizedUrl("/unauthorized");
    
    // 添加日志记录
    shiroConfig.setLogWriter(new ConsoleLogWriter());
    shiroConfig.setSecurityManager(new BasicSecurityManager());
    
    // 注册新的过滤器
    FilterRegistration filterRegistration = FilterRegistrationBuilder.filter(
            new ShiroFilterFactoryBean()
                    .setSecurityManager(new CustomShiroSecurityManager())
    ).addUrlPatterns("/**").build();
    
    // 注册过滤器
    filterRegistration.addFilterBefore(filterRegistration, "com.servlet.FilterChain");
    
    ShiroProperties shiroProperties = new ShiroProperties();
    shiroProperties.setRealm(realm);
    shiroProperties.setCache(cache);
    
    ShiroConfig config = new ShiroConfig(shiroProperties);
    HttpSecurity httpSecurity = HttpSecurity.httpBasic().and().csrf().disable();
    if (StringUtils.hasText(token)) {
        httpSecurity.oauth2ResourceServer().jwt().jwtAccessTokenValiditySeconds(60 * 60 * 24 * 7)
                .jwtRefreshTokenValiditySeconds(60 * 60 * 24 * 7).realmName("My Realm")
                .tokenStore(new InMemoryTokenStore()).and();
    }
    
    SecurityWebFilterChain chain = httpSecurity.build();
    chain.exceptionHandling().authenticationEntryPoint(entryPoint).and().authorizeRequests().antMatchers("/").permitAll()
            .anyRequest().authenticated();
    
    SecurityContextHolder.getContext().setAuthentication(authentication);
    

    这段代码创建了一个自定义的安全管理器,它将捕获所有未经授权的访问并将其转发到未授权路径。同时,它还会打印出一条日志消息,以帮助诊断问题。

    希望这些信息对你有所帮助!

    评论

报告相同问题?