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 BasicAuthenticationConnectionCredentials getConnectionCredentials(String serviceNameSpaceURI,
70 String serviceName) {
71 return connectionCredentialsMap.get(new QName(serviceNameSpaceURI, serviceName));
72 }
73
74 public void registerServiceCredentials(BasicAuthenticationCredentials credentials) {
75 synchronized (serviceCredentialsMap) {
76 QName serviceName = new QName(credentials.getServiceNameSpaceURI(), credentials.getLocalServiceName());
77 List<BasicAuthenticationCredentials> credentialsList = serviceCredentialsMap.get(serviceName);
78 if (credentialsList == null) {
79 credentialsList = Collections.synchronizedList(new ArrayList<BasicAuthenticationCredentials>());
80 serviceCredentialsMap.put(serviceName, credentialsList);
81 }
82 credentialsList.add(credentials);
83 }
84 }
85
86 public void registerConnectionCredentials(BasicAuthenticationConnectionCredentials credentials) {
87 synchronized (connectionCredentialsMap) {
88 connectionCredentialsMap.put(new QName(credentials.getServiceNameSpaceURI(),
89 credentials.getLocalServiceName()), credentials);
90 }
91 }
92
93 }