1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.service.impl;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import javax.xml.namespace.QName;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.kuali.rice.ksb.service.BasicAuthenticationConnectionCredentials;
28 import org.kuali.rice.ksb.service.BasicAuthenticationCredentials;
29 import org.kuali.rice.ksb.service.BasicAuthenticationService;
30
31
32
33
34
35
36
37
38 public class BasicAuthenticationServiceImpl implements BasicAuthenticationService {
39
40 private Map<QName, List<BasicAuthenticationCredentials>> serviceCredentialsMap;
41 private Map<QName, BasicAuthenticationConnectionCredentials> connectionCredentialsMap;
42
43
44
45
46 public BasicAuthenticationServiceImpl() {
47 this.serviceCredentialsMap = Collections.synchronizedMap(
48 new HashMap<QName, List<BasicAuthenticationCredentials>>());
49 this.connectionCredentialsMap = Collections.synchronizedMap(
50 new HashMap<QName, BasicAuthenticationConnectionCredentials>());
51 }
52
53 public boolean checkServiceAuthentication(String serviceNameSpaceURI, QName serviceName, String username,
54 String password) {
55 List<BasicAuthenticationCredentials> credentialsList = serviceCredentialsMap.get(serviceName);
56 if (credentialsList != null) {
57 synchronized (credentialsList) {
58 for (BasicAuthenticationCredentials credentials : credentialsList) {
59 if (StringUtils.equals(username, credentials.getUsername()) && StringUtils.equals(
60 serviceNameSpaceURI, credentials.getServiceNameSpaceURI())) {
61 return StringUtils.equals(password, credentials.getPassword());
62 }
63 }
64 }
65 }
66 return false;
67 }
68
69 public String getPasswordForService(String serviceNameSpaceURI, QName serviceName, String username) {
70 List<BasicAuthenticationCredentials> credentialsList = serviceCredentialsMap.get(serviceName);
71 if (credentialsList != null) {
72 synchronized (credentialsList) {
73 for (BasicAuthenticationCredentials credentials : credentialsList) {
74 if (StringUtils.equals(username, credentials.getUsername()) && StringUtils.equals(
75 serviceNameSpaceURI, credentials.getServiceNameSpaceURI())) {
76 return credentials.getPassword();
77 }
78 }
79 }
80 }
81 return null;
82 }
83
84 public BasicAuthenticationConnectionCredentials getConnectionCredentials(String serviceNameSpaceURI,
85 String serviceName) {
86 return connectionCredentialsMap.get(new QName(serviceNameSpaceURI, serviceName));
87 }
88
89 public void registerServiceCredentials(BasicAuthenticationCredentials credentials) {
90 synchronized (serviceCredentialsMap) {
91 QName serviceName = new QName(credentials.getServiceNameSpaceURI(), credentials.getLocalServiceName());
92 List<BasicAuthenticationCredentials> credentialsList = serviceCredentialsMap.get(serviceName);
93 if (credentialsList == null) {
94 credentialsList = Collections.synchronizedList(new ArrayList<BasicAuthenticationCredentials>());
95 serviceCredentialsMap.put(serviceName, credentialsList);
96 }
97 credentialsList.add(credentials);
98 }
99 }
100
101 public void registerConnectionCredentials(BasicAuthenticationConnectionCredentials credentials) {
102 synchronized (connectionCredentialsMap) {
103 connectionCredentialsMap.put(new QName(credentials.getServiceNameSpaceURI(),
104 credentials.getLocalServiceName()), credentials);
105 }
106 }
107
108 }