source: EDIS/tags/ed/tracking-server-vista/src/main/java/gov/va/med/edp/springframework/security/userdetails/vistalink/VistaLinkUserDetailService.java@ 1240

Last change on this file since 1240 was 1240, checked in by George Lilly, 13 years ago

new version from the VA

File size: 5.4 KB
Line 
1package gov.va.med.edp.springframework.security.userdetails.vistalink;
2
3import gov.va.med.edp.springframework.security.userdetails.VistaUserDetails;
4import gov.va.med.edp.springframework.security.userdetails.VistaUserDetailsService;
5import gov.va.med.edp.vistalink.ConnectionFactoryLocator;
6import gov.va.med.edp.vistalink.VistaLinkDaoSupport;
7import gov.va.med.edp.vistalink.VistaLinkTemplate;
8import org.springframework.security.BadCredentialsException;
9import org.springframework.security.GrantedAuthority;
10import org.springframework.security.GrantedAuthorityImpl;
11import org.springframework.dao.DataAccessException;
12import org.springframework.util.StringUtils;
13import org.springframework.util.Assert;
14
15import java.util.ArrayList;
16import java.util.List;
17
18public class VistaLinkUserDetailService extends VistaLinkDaoSupport implements VistaUserDetailsService {
19
20 static final int DEFAULT_TIMEOUT = 600;
21
22 static final String RPC_CONTEXT = "XUS KAAJEE WEB LOGON";
23
24 static final String GET_USER_INFO_RPC = "XUS KAAJEE GET USER INFO";
25 static final String LOGOUT_RPC_NAME = "XUS KAAJEE LOGOUT";
26
27 private String applicationName;
28
29 protected void checkDaoConfig() throws IllegalArgumentException {
30 Assert.hasText(applicationName, "''applicationName' must not be empty");
31 super.checkDaoConfig();
32 }
33
34 protected VistaLinkTemplate createRpcTemplate(ConnectionFactoryLocator connectionFactoryLocator) {
35 VistaLinkTemplate template = super.createRpcTemplate(connectionFactoryLocator);
36 template.setTimeOut(DEFAULT_TIMEOUT);
37 return template;
38 }
39
40 public VistaUserDetails login(String stationNumber, String accessCode, String verifyCode, String remoteAddress) throws BadCredentialsException, DataAccessException {
41 if (!StringUtils.hasLength(stationNumber)) throw new BadCredentialsException("missing station number");
42 if (!StringUtils.hasLength(accessCode)) throw new BadCredentialsException("missing access code");
43 if (!StringUtils.hasLength(verifyCode)) throw new BadCredentialsException("missing verify code");
44 if (!StringUtils.hasLength(remoteAddress)) throw new BadCredentialsException("missing remote address");
45 try {
46 String result = getRpcTemplate().rpc(new VistaLinkAccessVerifyConnectionSpec(stationNumber, accessCode, verifyCode, remoteAddress), stationNumber, null, RPC_CONTEXT, GET_USER_INFO_RPC, createLoginParams(remoteAddress));
47 return createVistaUserDetails(result, accessCode, verifyCode);
48 } catch (DataAccessException e) {
49 throw new BadCredentialsException("couldn't log in", e);
50 }
51 }
52
53 public void logout(VistaUserDetails user) throws DataAccessException {
54 getRpcTemplate().rpcAsUser(user.getLoginStationNumber(), user.getDuz(), RPC_CONTEXT, LOGOUT_RPC_NAME, createLogoutParams(user));
55 }
56
57 private List createLoginParams(String remoteAddress) {
58 List params = new ArrayList();
59 params.add(remoteAddress);
60 params.add(getApplicationName());
61 return params;
62 }
63
64
65 private List createLogoutParams(VistaUserDetails user) {
66 List params = new ArrayList();
67 params.add(user.getSignonLogInternalEntryNumber());
68 return params;
69 }
70
71 /*
72 * Result(0) is the users DUZ.
73 * Result(1) is the user name from the .01 field.
74 * Result(2) is the users full name from the name standard file.
75 * Result(3) is the FAMILY (LAST) NAME (or ^ if null)
76 * Result(4) is the GIVEN (FIRST) NAME (or ^ if null)
77 * Result(5) is the MIDDLE NAME (or ^ if null)
78 * Result(6) is the PREFIX (or ^ if null)
79 * Result(7) is the SUFFIX (or ^ if null)
80 * Result(8) is the DEGREE (or ^ if null)
81 * Result(9) is station # of the division that the user is working in.
82 * Result(10) is the station # of the parent facility for the login division
83 * Result(11) is the station # of the computer system "parent" from the KSP file.
84 * Result(12) is the IEN of the signon log entry
85 * Result(13) = # of permissible divisions
86 * Result(14-n) are the permissible divisions for user login, in the format:
87 * IEN of file 4^Station Name^Station Number^default? (1 or 0)
88 */
89 protected VistaUserDetails createVistaUserDetails(String result, String accessCode, String verifyCode) {
90 String[] results = result.split("\n");
91 VistaUser u = new VistaUser(results[12],
92 results[9],
93 results[0],
94 accessCode,
95 verifyCode,
96 true,
97 true,
98 true,
99 true,
100 new GrantedAuthority[]{new GrantedAuthorityImpl("ROLE_USER")});
101 u.setPersonName(results[1]);
102 u.setDisplayName(results[2]);
103 u.setFamilyName(nullSafeGet(results[3]));
104 u.setGivenName(nullSafeGet(results[4]));
105 u.setMiddleName(nullSafeGet(results[5]));
106 u.setPrefix(nullSafeGet(results[6]));
107 u.setSuffix(nullSafeGet(results[7]));
108 u.setDegree(nullSafeGet(results[8]));
109 return u;
110 }
111
112 private String nullSafeGet(String value) {
113 if (value.equals("^")) return null;
114 return value;
115 }
116
117 public String getApplicationName() {
118 return applicationName;
119 }
120
121 public void setApplicationName(String applicationName) {
122 this.applicationName = applicationName;
123 }
124}
Note: See TracBrowser for help on using the repository browser.