|
1
|
|
|
package easytests.auth.handlers; |
|
2
|
|
|
|
|
3
|
|
|
import easytests.auth.helpers.SessionLoginStoreHelper; |
|
4
|
|
|
import java.io.IOException; |
|
5
|
|
|
import javax.servlet.ServletException; |
|
6
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
7
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
8
|
|
|
import javax.servlet.http.HttpSession; |
|
9
|
|
|
import org.springframework.security.core.AuthenticationException; |
|
10
|
|
|
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @author malinink |
|
15
|
|
|
*/ |
|
16
|
|
|
public class AuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { |
|
17
|
|
|
private String usernameParameter; |
|
18
|
|
|
|
|
19
|
|
|
public AuthenticationFailureHandler(String defaultFailureUrl, String usernameParameter) { |
|
20
|
|
|
super(defaultFailureUrl); |
|
21
|
|
|
this.usernameParameter = usernameParameter; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
@Override |
|
25
|
|
|
public void onAuthenticationFailure( |
|
26
|
|
|
HttpServletRequest request, HttpServletResponse response, |
|
27
|
|
|
AuthenticationException exception) |
|
28
|
|
|
throws IOException, ServletException { |
|
29
|
|
|
super.onAuthenticationFailure(request, response, exception); |
|
30
|
|
|
|
|
31
|
|
|
final HttpSession session = request.getSession(false); |
|
32
|
|
|
final SessionLoginStoreHelper sessionLoginStoreHelper = new SessionLoginStoreHelper(session); |
|
33
|
|
|
if (sessionLoginStoreHelper.exists() || this.isAllowSessionCreation()) { |
|
34
|
|
|
final String login = request.getParameter(this.usernameParameter); |
|
35
|
|
|
sessionLoginStoreHelper.setLogin(login); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|