1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.security.soap;
17
18 import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
19 import org.apache.ws.security.WSPasswordCallback;
20 import org.apache.ws.security.WSSecurityException;
21 import org.apache.ws.security.handler.RequestData;
22 import org.apache.ws.security.handler.WSHandlerConstants;
23 import org.kuali.rice.core.api.security.credentials.Credentials;
24 import org.kuali.rice.core.api.security.credentials.CredentialsSource;
25 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
26 import org.kuali.rice.ksb.security.credentials.UsernamePasswordCredentials;
27 import org.springframework.util.Assert;
28
29
30
31
32
33
34
35
36 public class CredentialsOutHandler extends WSS4JOutInterceptor {
37
38 private final CredentialsSource credentialsSource;
39
40 private final ServiceConfiguration serviceConfiguration;
41
42 public CredentialsOutHandler(final CredentialsSource credentialsSource,
43 final ServiceConfiguration serviceConfiguration) {
44 Assert.notNull(credentialsSource, "credentialsSource cannot be null.");
45 Assert.notNull(serviceConfiguration, "serviceConfiguration cannot be null.");
46 this.credentialsSource = credentialsSource;
47 this.serviceConfiguration = serviceConfiguration;
48
49 final Credentials credentials = this.credentialsSource
50 .getCredentials(this.serviceConfiguration.getEndpointUrl().toString());
51
52 Assert.isTrue(credentials instanceof UsernamePasswordCredentials,
53 "Credentials must be of type usernamepassword.");
54
55 final UsernamePasswordCredentials c = (UsernamePasswordCredentials) credentials;
56 setProperty(WSHandlerConstants.USER, c.getUsername());
57 }
58
59 public WSPasswordCallback getPassword(final String username,
60 final int doAction, final String clsProp, final String refProp,
61 final RequestData reqData) throws WSSecurityException {
62 final UsernamePasswordCredentials c = (UsernamePasswordCredentials) this.credentialsSource
63 .getCredentials(this.serviceConfiguration.getEndpointUrl().toString());
64
65 return new WSPasswordCallback(c.getUsername(), c.getPassword(), null,
66 WSPasswordCallback.USERNAME_TOKEN);
67 }
68 }
69