SecurityContextLogoutHandler中的Spring启动注销自定义异常

时间:2015-05-24 16:39:49

标签: java spring exception spring-security spring-boot

我想在有人尝试注销的时候在我的Spring启动应用程序上抛出一个自定义异常,我需要在执行注销之前向某人显示一步,我尝试覆盖SecurityContextLogoutHandler中的logout方法,并且重定向到这样的错误页面:

@Component
public class OnLogoutHandler extends SecurityContextLogoutHandler {

    @Autowired
    private JourneyTurnsServices journeyTurnServices;

    @Autowired
    private ClosingCashesServices closingCashesServices;

    public OnLogoutHandler() {

    }

    @Override
    public void logout(HttpServletRequest request,
            HttpServletResponse response, Authentication authentication) {
        try {
            JourneyTurn currentTurn = journeyTurnServices.checkActiveJourney();

            if (closingCashesServices.checkClosingCashRealized(currentTurn)) {
                super.logout(request, response, authentication);
                return;
            } else {
                response.sendRedirect("/logoutUnclosedCashError");
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

这有效,但是我想知道是否还有另一种方式,因为我觉得我已经离开了框架,我认为这就像一个黑客

0 个答案:

没有答案