1 /**
2 * Copyright 2005-2015 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.ksb.service;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.springframework.beans.factory.InitializingBean;
20
21 /**
22 * Initializes authenticationService with user credentials.
23 *
24 * @author Kuali Rice Team (rice.collab@kuali.org)
25 */
26 public class BasicAuthenticationCredentials implements InitializingBean {
27
28 private BasicAuthenticationService authenticationService;
29 private String serviceNameSpaceURI;
30 private String localServiceName;
31 private String username;
32 private String password;
33
34 /**
35 * Register the service credentials for the service
36 *
37 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
38 */
39 public void afterPropertiesSet() throws Exception {
40 if (this.validate()) {
41 this.getAuthenticationService().registerServiceCredentials(this);
42 }
43 }
44
45 /**
46 * Gets the BasicAuthenticationService to use
47 *
48 * @return BasicAuthenticationService the BasicAuthenticationService
49 */
50 public BasicAuthenticationService getAuthenticationService() {
51 if (this.authenticationService == null) {
52 this.authenticationService = KSBServiceLocator.getBasicAuthenticationService();
53 }
54 return authenticationService;
55 }
56
57 /**
58 * Sets the authenticationService
59 *
60 * @param authenticationService the BasicAthenticationService to set
61 */
62 public void setAuthenticationService(BasicAuthenticationService authenticationService) {
63 this.authenticationService = authenticationService;
64 }
65
66 /**
67 * Gets the serviceNameSpaceURI
68 *
69 * @return String serviceNameSpaceURI of this BasicAuthenticationCredentials
70 */
71 public String getServiceNameSpaceURI() {
72 return serviceNameSpaceURI;
73 }
74
75 /**
76 * Sets the serviceNameSpaceURI
77 *
78 * @param serviceNameSpaceURI the serviceNameSpaceURI to set
79 */
80 public void setServiceNameSpaceURI(String serviceNameSpaceURI) {
81 this.serviceNameSpaceURI = serviceNameSpaceURI;
82 }
83
84 /**
85 * Gets the localServiceName
86 *
87 * @return String localServiceName of this BasicAuthenticationCredentials
88 */
89 public String getLocalServiceName() {
90 return localServiceName;
91 }
92
93 /**
94 * Sets the localServiceName
95 *
96 * @param localServiceName the localServiceName to set
97 */
98 public void setLocalServiceName(String localServiceName) {
99 this.localServiceName = localServiceName;
100 }
101
102 /**
103 * Gets the username
104 *
105 * @return username the username of this BasicAuthenticationCredentials
106 */
107 public String getUsername() {
108 return username;
109 }
110
111 /**
112 * Sets the username
113 *
114 * @param username the username to set
115 */
116 public void setUsername(String username) {
117 this.username = username;
118 }
119
120 /**
121 * Gets the password
122 *
123 * @return password the password of this BasicAuthenticationCredentials
124 */
125 public String getPassword() {
126 return password;
127 }
128
129 /**
130 * Sets the password
131 *
132 * @param password the password to set
133 */
134 public void setPassword(String password) {
135 this.password = password;
136 }
137
138 /**
139 * Validates authenticationService, serviceNameSpaceURI, localServiceName, username, and password
140 *
141 * @return true if the authentictionSerivce is not null and the serviceNameSpaceURI, localServiceName,
142 * username, and password are not blank
143 */
144 protected boolean validate() {
145 return this.getAuthenticationService() != null &&
146 StringUtils.isNotBlank(this.getServiceNameSpaceURI()) &&
147 StringUtils.isNotBlank(this.getLocalServiceName()) &&
148 StringUtils.isNotBlank(this.getUsername()) &&
149 StringUtils.isNotBlank(this.getPassword());
150 }
151 }