Package: DirectoryServerManagerClient

DirectoryServerManagerClient

nameinstructionbranchcomplexitylinemethod
DirectoryServerManagerClient(String, String, ConfigurationContext)
M: 46 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
addServicePrinciple(String, String, String)
M: 87 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getPasswordConformanceRegularExpression()
M: 36 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getServiceNameConformanceRegularExpression()
M: 36 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
isKDCEnabled()
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
listServicePrinciples(String)
M: 48 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
removeServicePrinciple(String)
M: 42 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
updatePassword(String, String, String)
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3: *
4: * WSO2 Inc. licenses this file to you under the Apache License,
5: * Version 2.0 (the "License"); you may not use this file except
6: * in compliance with the License.
7: * You may obtain a copy of the License at
8: *
9: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing,
12: * software distributed under the License is distributed on an
13: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14: * KIND, either express or implied. See the License for the
15: * specific language governing permissions and limitations
16: * under the License.
17: */
18:
19: package org.wso2.carbon.directory.server.manager.ui;
20:
21: import org.apache.axis2.AxisFault;
22: import org.apache.axis2.client.Options;
23: import org.apache.axis2.client.ServiceClient;
24: import org.apache.axis2.context.ConfigurationContext;
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27: import org.wso2.carbon.directory.common.stub.types.ServerPrinciple;
28: import org.wso2.carbon.directory.server.manager.stub.DirectoryServerManagerDirectoryServerManagerExceptionException;
29: import org.wso2.carbon.directory.server.manager.stub.DirectoryServerManagerStub;
30:
31: import java.rmi.RemoteException;
32:
33: /**
34: * A client which communicates with back-end DirectoryServerManager to create/query and delete
35: * server principles.
36: */
37: @SuppressWarnings({"UnusedDeclaration"})
38: public class DirectoryServerManagerClient {
39:
40: public static final String SERVER_MANAGER_CLIENT = "org.wso2.carbon.directory.server.manager";
41: private static final Log log = LogFactory.getLog(DirectoryServerManagerClient.class);
42: private static final String SERVER_MANAGER_SERVICE = "DirectoryServerManager";
43: protected DirectoryServerManagerStub stub = null;
44: private String passwordRegularExpression;
45: private String serviceNameRegularExpression;
46:
47: public DirectoryServerManagerClient(String cookie, String url,
48: ConfigurationContext configContext) throws ServerManagerClientException {
49: try {
50: stub = new DirectoryServerManagerStub(configContext, url + SERVER_MANAGER_SERVICE);
51: ServiceClient client = stub._getServiceClient();
52: Options option = client.getOptions();
53: option.setManageSession(true);
54: option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
55: } catch (AxisFault e) {
56: log.error("Unable to instantiate DirectoryServerManagerClient.", e);
57: throw new ServerManagerClientException(ServerManagerClientException.INIT_SERVICE_PRINCIPLE_ERROR, e);
58: }
59: }
60:
61: public void addServicePrinciple(String serverName, String serverDescription, String password)
62: throws ServerManagerClientException {
63: try {
64:
65:• if (stub.isExistingServicePrinciple(serverName)) {
66: log.error("Error adding service principle. Service name already exists.");
67: throw new ServerManagerClientException(ServerManagerClientException.SERVICE_PRINCIPLE_ALREADY_EXISTS);
68: }
69:
70: stub.addServer(serverName, serverDescription, password);
71: } catch (RemoteException e) {
72: StringBuilder stb = new StringBuilder();
73: stb.append("Server Name - ").append(serverName).append(" Description - ").append(serverDescription);
74: log.error("Error adding service principle. Could not reach back-end service. " + stb.toString(), e);
75: throw new ServerManagerClientException(ServerManagerClientException.ADD_SERVICE_PRINCIPLES_ERROR, e);
76: } catch (DirectoryServerManagerDirectoryServerManagerExceptionException e) {
77: StringBuilder stb = new StringBuilder();
78: stb.append("Server Name - ").append(serverName).append(" Description - ").append(serverDescription);
79: log.error("An error occurred while adding a service principle. " + stb.toString(), e);
80: throw new ServerManagerClientException(ServerManagerClientException.ADD_SERVICE_PRINCIPLES_ERROR, e);
81: }
82: }
83:
84: public ServerPrinciple[] listServicePrinciples(String filter) throws ServerManagerClientException {
85: try {
86: ServerPrinciple[] principles = stub.listServicePrinciples(filter);
87:• if (principles == null) {
88: return new ServerPrinciple[0];
89: } else {
90: return principles;
91: }
92: } catch (RemoteException e) {
93: log.error("Error listing service principles. Could not reach back-end service. Filter - " + filter, e);
94: throw new ServerManagerClientException(ServerManagerClientException.LIST_SERVICE_PRINCIPLES_ERROR, e);
95: } catch (DirectoryServerManagerDirectoryServerManagerExceptionException e) {
96: log.error("An error occurred while listing service principles. Filter - " + filter, e);
97: throw new ServerManagerClientException(ServerManagerClientException.LIST_SERVICE_PRINCIPLES_ERROR, e);
98: }
99: }
100:
101: public void updatePassword(String servicePrinciple, String oldPassword, String newPassword)
102: throws ServerManagerClientException {
103:
104: try {
105: stub.changePassword(servicePrinciple, oldPassword, newPassword);
106: } catch (RemoteException e) {
107: log.error("Could not reach back-end service. Error updating password for service principle - "
108: + servicePrinciple, e);
109: throw new ServerManagerClientException(ServerManagerClientException.CHANGE_SERVICE_PRINCIPLES_ERROR, e);
110: } catch (DirectoryServerManagerDirectoryServerManagerExceptionException e) {
111: log.error("An error occurred while updating service principle's password. Service principle - "
112: + servicePrinciple, e);
113: throw new ServerManagerClientException(ServerManagerClientException.CHANGE_SERVICE_PRINCIPLES_ERROR, e);
114: }
115: }
116:
117: public void removeServicePrinciple(String servicePrinciple) throws ServerManagerClientException {
118: try {
119: stub.removeServer(servicePrinciple);
120: } catch (RemoteException e) {
121: log.error("Could not reach back-end service. Error deleting service principle - " + servicePrinciple, e);
122: throw new ServerManagerClientException(ServerManagerClientException.REMOVE_SERVICE_PRINCIPLES_ERROR, e);
123: } catch (DirectoryServerManagerDirectoryServerManagerExceptionException e) {
124: log.error("An error occurred while deleting service principle - "
125: + servicePrinciple, e);
126: throw new ServerManagerClientException(ServerManagerClientException.REMOVE_SERVICE_PRINCIPLES_ERROR, e);
127: }
128: }
129:
130: public String getPasswordConformanceRegularExpression() throws ServerManagerClientException {
131:
132:• if (this.passwordRegularExpression != null) {
133: return this.passwordRegularExpression;
134: }
135:
136: try {
137: this.passwordRegularExpression = stub.getPasswordConformanceRegularExpression();
138: return this.passwordRegularExpression;
139: } catch (RemoteException e) {
140: log.error("Could not reach back-end service. Error retrieving password format. ", e);
141: throw new ServerManagerClientException(ServerManagerClientException.PASSWORD_FORMAT_RETRIEVING_ERROR, e);
142: } catch (DirectoryServerManagerDirectoryServerManagerExceptionException e) {
143: log.error("An error occurred while retrieving password format.", e);
144: throw new ServerManagerClientException(ServerManagerClientException.PASSWORD_FORMAT_RETRIEVING_ERROR, e);
145: }
146: }
147:
148: public String getServiceNameConformanceRegularExpression() throws ServerManagerClientException {
149:
150:• if (this.serviceNameRegularExpression != null) {
151: return this.serviceNameRegularExpression;
152: }
153:
154: try {
155: this.serviceNameRegularExpression = stub.getServiceNameConformanceRegularExpression();
156: return this.serviceNameRegularExpression;
157: } catch (RemoteException e) {
158: log.error("Could not reach back-end service. Error retrieving service name format. ", e);
159: throw new ServerManagerClientException(ServerManagerClientException.NAME_FORMAT_RETRIEVING_ERROR, e);
160: } catch (DirectoryServerManagerDirectoryServerManagerExceptionException e) {
161: log.error("An error occurred while retrieving service name format.", e);
162: throw new ServerManagerClientException(ServerManagerClientException.NAME_FORMAT_RETRIEVING_ERROR, e);
163: }
164: }
165:
166: public boolean isKDCEnabled() {
167:
168: try {
169: return stub.isKDCEnabled();
170: } catch (RemoteException e) {
171: log.error("Could not reach back-end service. Error checking whether KDC is enabled. ", e);
172: } catch (DirectoryServerManagerDirectoryServerManagerExceptionException e) {
173: log.error("An error occurred while checking whether KDC is enabled.", e);
174: }
175:
176: return false;
177: }
178: }