diff --git a/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java b/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..0864cc5b3d105f152a2079668899038533f70b94 --- /dev/null +++ b/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2012 THM webMedia + * + * This file is part of ARSnova. + * + * ARSnova is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package de.thm.arsnova; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.DefaultRedirectStrategy; +import org.springframework.security.web.RedirectStrategy; +import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; + +public class LoginAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { + + private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); + private String defaultFailureUrl; + + @Override + public void onAuthenticationFailure(HttpServletRequest request, + HttpServletResponse response, AuthenticationException exception) + throws IOException, ServletException { + + HttpSession session = request.getSession(); + if (session != null && session.getAttribute("ars-referer") != null) { + defaultFailureUrl = (String) session.getAttribute("ars-referer"); + } + + redirectStrategy.sendRedirect(request, response, defaultFailureUrl); + } + + public void setDefaultFailureUrl(String defaultFailureUrl) { + this.defaultFailureUrl = defaultFailureUrl; + } + +} diff --git a/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java b/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java index 08d947c82eb9444359b124e7fa7c65c9f19712f4..9975409349163c3d6b8f9c4084a178d488dbb1b3 100644 --- a/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java +++ b/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2012 THM webMedia + * + * This file is part of ARSnova. + * + * ARSnova is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package de.thm.arsnova; import javax.servlet.http.HttpServletRequest; diff --git a/src/main/webapp/WEB-INF/spring/spring-security.xml b/src/main/webapp/WEB-INF/spring/spring-security.xml index 665e0d504b56cdc87b49bd9e19465e33ce2d5f3c..a53a82159bcce00e07b58294930dacff5cf8528b 100644 --- a/src/main/webapp/WEB-INF/spring/spring-security.xml +++ b/src/main/webapp/WEB-INF/spring/spring-security.xml @@ -127,8 +127,7 @@ <bean id="successHandler" class="de.thm.arsnova.LoginAuthenticationSucessHandler" p:targetUrl="#auth/checkLogin"/> - <bean id="failureHandler" - class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> - <property name="defaultFailureUrl" value="/login.jsp" /> - </bean> + <bean id="failureHandler" class="de.thm.arsnova.LoginAuthenticationFailureHandler" + p:defaultFailureUrl="/index.html" /> + </beans>