easytests.auth.handlers.AuthenticationFailureHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
c 0
b 0
f 0
loc 20
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AuthenticationFailureHandler(String,String) 0 3 1
A onAuthenticationFailure(HttpServletRequest,HttpServletResponse,AuthenticationException) 0 12 3
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