01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.bus.security.soap;
17:
18: import org.apache.ws.security.WSPasswordCallback;
19: import org.apache.ws.security.WSSecurityException;
20: import org.apache.ws.security.handler.RequestData;
21: import org.apache.ws.security.handler.WSHandlerConstants;
22: import org.codehaus.xfire.security.wss4j.WSS4JOutHandler;
23: import org.kuali.bus.security.credentials.UsernamePasswordCredentials;
24: import org.kuali.rice.security.credentials.Credentials;
25: import org.kuali.rice.security.credentials.CredentialsSource;
26: import org.springframework.util.Assert;
27:
28: import edu.iu.uis.eden.messaging.ServiceInfo;
29:
30: /**
31: *
32: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
33: * @version $Revision: 1.2.16.1.6.1 $ $Date: 2007/10/17 20:32:05 $
34: * @since 0.9
35: *
36: */
37: public class CredentialsOutHandler extends WSS4JOutHandler {
38:
39: private final CredentialsSource credentialsSource;
40:
41: private final ServiceInfo serviceInfo;
42:
43: public CredentialsOutHandler(
44: final CredentialsSource credentialsSource,
45: final ServiceInfo serviceInfo) {
46: Assert.notNull(credentialsSource,
47: "credentialsSource cannot be null.");
48: Assert.notNull(serviceInfo, "serviceInfo cannot be null.");
49: this .credentialsSource = credentialsSource;
50: this .serviceInfo = serviceInfo;
51:
52: final Credentials credentials = this .credentialsSource
53: .getCredentials(this .serviceInfo.getEndpointUrl());
54:
55: Assert.isTrue(
56: credentials instanceof UsernamePasswordCredentials,
57: "Credentials must be of type usernamepassword.");
58:
59: final UsernamePasswordCredentials c = (UsernamePasswordCredentials) credentials;
60: setProperty(WSHandlerConstants.USER, c.getUsername());
61: }
62:
63: public WSPasswordCallback getPassword(final String username,
64: final int doAction, final String clsProp,
65: final String refProp, final RequestData reqData)
66: throws WSSecurityException {
67: final UsernamePasswordCredentials c = (UsernamePasswordCredentials) this .credentialsSource
68: .getCredentials(this .serviceInfo.getEndpointUrl());
69:
70: return new WSPasswordCallback(c.getUsername(), c.getPassword(),
71: null, WSPasswordCallback.USERNAME_TOKEN);
72: }
73: }
|