onAuthenticationFailure(HttpServletRequest,HttpServletResponse,AuthenticationException)   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 12
rs 9.8
c 0
b 0
f 0
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