1 | package gov.va.med.edp.springframework.security.providers.vistalink;
|
---|
2 |
|
---|
3 | import gov.va.med.edp.springframework.security.userdetails.VistaUserDetails;
|
---|
4 | import org.springframework.security.GrantedAuthority;
|
---|
5 | import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
---|
6 | import org.springframework.util.StringUtils;
|
---|
7 |
|
---|
8 | public class VistaAuthenticationToken extends UsernamePasswordAuthenticationToken {
|
---|
9 |
|
---|
10 | static final String UNAUTHENTICATED = "UNAUTHENTICATED";
|
---|
11 | private static final String SEP = ";";
|
---|
12 |
|
---|
13 | private String accessCode;
|
---|
14 | private String verifyCode;
|
---|
15 |
|
---|
16 | public VistaAuthenticationToken(String stationNumber, String accessCode, String verifyCode, String remoteAddress) {
|
---|
17 | super(UNAUTHENTICATED + "@" + stationNumber, (StringUtils.hasLength(accessCode) && StringUtils.hasLength(verifyCode) && StringUtils.hasLength(remoteAddress) ? accessCode + SEP + verifyCode + SEP + remoteAddress : null));
|
---|
18 | this.accessCode = StringUtils.hasLength(accessCode) ? accessCode : null;
|
---|
19 | this.verifyCode = StringUtils.hasLength(verifyCode) ? verifyCode : null;
|
---|
20 | super.setDetails(StringUtils.hasLength(remoteAddress) ? remoteAddress : null);
|
---|
21 | }
|
---|
22 |
|
---|
23 | public VistaAuthenticationToken(VistaUserDetails user, String accessCode, String verifyCode, String remoteAddress, GrantedAuthority[] authorities) {
|
---|
24 | super(user, (StringUtils.hasLength(accessCode) && StringUtils.hasLength(verifyCode) && StringUtils.hasLength(remoteAddress) ? accessCode + SEP + verifyCode + SEP + remoteAddress : null), authorities);
|
---|
25 | this.accessCode = StringUtils.hasLength(accessCode) ? accessCode : null;
|
---|
26 | this.verifyCode = StringUtils.hasLength(verifyCode) ? verifyCode : null;
|
---|
27 | super.setDetails(StringUtils.hasLength(remoteAddress) ? remoteAddress : null);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public VistaUserDetails getVistaUserDetails() {
|
---|
31 | if (isAuthenticated())
|
---|
32 | return (VistaUserDetails) getPrincipal();
|
---|
33 | return null;
|
---|
34 | }
|
---|
35 |
|
---|
36 | public String getDuz() {
|
---|
37 | if (isAuthenticated())
|
---|
38 | return getVistaUserDetails().getDuz();
|
---|
39 | return null;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public String getStationNumber() {
|
---|
43 | if (isAuthenticated())
|
---|
44 | return getVistaUserDetails().getLoginStationNumber();
|
---|
45 | else
|
---|
46 | return ((String) getPrincipal()).substring(((String) getPrincipal()).lastIndexOf("@") + 1);
|
---|
47 | }
|
---|
48 |
|
---|
49 | public String getAccessCode() {
|
---|
50 | return accessCode;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public String getVerifyCode() {
|
---|
54 | return verifyCode;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public String getRemoteAddress() {
|
---|
58 | return (String) getDetails();
|
---|
59 | }
|
---|
60 |
|
---|
61 | public void setDetails(Object details) {
|
---|
62 | // NOOP
|
---|
63 | }
|
---|
64 | }
|
---|