Giter Site home page Giter Site logo

Comments (9)

Smith-Cruise avatar Smith-Cruise commented on May 20, 2024

可以参考我这个写法
https://github.com/Eagle-OJ/eagle-oj-api/blob/master/eagle-oj-web/src/main/java/com/eagleoj/web/controller/exception/GlobalExceptionController.java

使用@ExceptionHandler(ShiroException.class)进行捕捉

from spring-boot-shiro.

whyalwaysmea avatar whyalwaysmea commented on May 20, 2024

尝试还是无法被ExceptionController所捕获呢?
我就是直接使用的该项目中的代码,因为该项目中也是用了@ExceptionHandler(ShiroException.class)进行捕捉的。 不知道你所说的那个项目代码哪里和这个有不一样呢?

from spring-boot-shiro.

Smith-Cruise avatar Smith-Cruise commented on May 20, 2024

你参考下我的吧
https://github.com/Smith-Cruise/Spring-Boot-Shiro/blob/master/src/main/java/org/inlighting/controller/ExceptionController.java
比如@RestControllerAdvice这些注解你加了吗

from spring-boot-shiro.

whyalwaysmea avatar whyalwaysmea commented on May 20, 2024

添加了的,我试了一下你的demo,即使我乱输入一个token,是提示Unauthorized。按理来说应该是在MyRealm中跑token invalid异常。
我觉得是MyRealm 中抛出的异常,在JWTFilter中被catch了,然后就会走response401该方法。 所以MyRealm中的自定义异常似乎没有多大的作用了。
不知道我这样理解对不对,希望可以讨论一下,谢谢。(^__^)

from spring-boot-shiro.

whyalwaysmea avatar whyalwaysmea commented on May 20, 2024

如果在JWTFilter中的isAccessAllowed方法里不catch, 还是不会走ExceptionController 。

from spring-boot-shiro.

Smith-Cruise avatar Smith-Cruise commented on May 20, 2024

我明天看看,最近比较忙。实在不行可以先像我一样catch下。

from spring-boot-shiro.

Smith-Cruise avatar Smith-Cruise commented on May 20, 2024

看了下,的确没有什么好的办法,因为JWTFilter执行的时候SpringBoot的Controller都还没启动,所以无法捕捉异常,感觉还是URL redirect才是最好的办法了。

from spring-boot-shiro.

whyalwaysmea avatar whyalwaysmea commented on May 20, 2024

是的,所以我现在将异常捕捉之后,把异常信息一起带到了401里面,然后通过401接口返回去

from spring-boot-shiro.

Smith-Cruise avatar Smith-Cruise commented on May 20, 2024

好吧

from spring-boot-shiro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.