13 |
Home Page
14 |
Anyone can view this page.
15 | <% if (request.getUserPrincipal() != null) { %>
16 |
Your are logged as: <%= request.getUserPrincipal().getName() %>
17 | <% } %>
18 |
19 | You can currently access "/secure" URLs.
20 |
21 |
Go to a secured page (bob/secret)
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/java/com/example/security/captcha/CaptchaAuthenticationDetails.java:
--------------------------------------------------------------------------------
1 | package com.example.security.captcha;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 |
7 | import nl.captcha.Captcha;
8 |
9 | import org.springframework.web.util.WebUtils;
10 |
11 | public class CaptchaAuthenticationDetails implements Serializable {
12 |
13 | private static final long serialVersionUID = 8047091036777813803L;
14 |
15 | private final String answer;
16 | private final Captcha captcha;
17 |
18 | public CaptchaAuthenticationDetails(HttpServletRequest req) {
19 | this.answer = req.getParameter("j_captcha");
20 | this.captcha = (Captcha) WebUtils.getSessionAttribute(req, "captcha");
21 | }
22 |
23 | public String getAnswer() {
24 | return answer;
25 | }
26 |
27 | public Captcha getCaptcha() {
28 | return captcha;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/example/web/AuthenticationResultListener.java:
--------------------------------------------------------------------------------
1 | package com.example.web;
2 |
3 | import java.util.concurrent.atomic.AtomicInteger;
4 |
5 | import javax.servlet.http.HttpSession;
6 |
7 | import org.springframework.context.ApplicationListener;
8 | import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
9 | import org.springframework.web.context.request.RequestContextHolder;
10 | import org.springframework.web.context.request.ServletRequestAttributes;
11 |
12 | public class AuthenticationResultListener implements
13 | ApplicationListener