1 | package gov.va.med.edp.springframework.security.ui.vistalink;
|
---|
2 |
|
---|
3 | import gov.va.med.edp.springframework.security.providers.vistalink.VistaAuthenticationToken;
|
---|
4 | import org.springframework.security.Authentication;
|
---|
5 | import org.springframework.security.AuthenticationException;
|
---|
6 | import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
|
---|
7 |
|
---|
8 | import javax.servlet.http.HttpServletRequest;
|
---|
9 |
|
---|
10 | public class VistaAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
|
---|
11 |
|
---|
12 | public static final String STATION_NUMBER_KEY = "j_stationNumber";
|
---|
13 | public static final String ACCESS_CODE_KEY = "j_access";
|
---|
14 | public static final String VERIFY_CODE_KEY = "j_verify";
|
---|
15 |
|
---|
16 | public Authentication attemptAuthentication(HttpServletRequest request) throws AuthenticationException {
|
---|
17 | String stationNumber = obtainStationNumber(request);
|
---|
18 | String accessCode = obtainAccessCode(request);
|
---|
19 | String verifyCode = obtainVerifyCode(request);
|
---|
20 | String remoteAddress = obtainRemoteAddress(request);
|
---|
21 |
|
---|
22 | if (accessCode == null) {
|
---|
23 | accessCode = "";
|
---|
24 | }
|
---|
25 |
|
---|
26 | if (verifyCode == null) {
|
---|
27 | verifyCode = "";
|
---|
28 | }
|
---|
29 |
|
---|
30 | // accessCode = accessCode.trim();
|
---|
31 |
|
---|
32 | VistaAuthenticationToken authRequest = new VistaAuthenticationToken(stationNumber, accessCode, verifyCode, remoteAddress);
|
---|
33 |
|
---|
34 | // Place the last username attempted into HttpSession for views
|
---|
35 | // request.getSession().setAttribute(ACEGI_SECURITY_LAST_USERNAME_KEY, accessCode);
|
---|
36 |
|
---|
37 | // Allow subclasses to set the "details" property
|
---|
38 | setDetails(request, authRequest);
|
---|
39 |
|
---|
40 | logger.debug("Attempting authentication with token: " + authRequest);
|
---|
41 | return this.getAuthenticationManager().authenticate(authRequest);
|
---|
42 | }
|
---|
43 |
|
---|
44 | protected String obtainStationNumber(HttpServletRequest request) {
|
---|
45 | return request.getParameter(STATION_NUMBER_KEY);
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected String obtainAccessCode(HttpServletRequest request) {
|
---|
49 | return request.getParameter(ACCESS_CODE_KEY);
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected String obtainVerifyCode(HttpServletRequest request) {
|
---|
53 | return request.getParameter(VERIFY_CODE_KEY);
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected String obtainRemoteAddress(HttpServletRequest request) {
|
---|
57 | return request.getRemoteAddr();
|
---|
58 | }
|
---|
59 | }
|
---|