View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.ksb.security.soap;
18  
19  import java.util.Properties;
20  
21  //import javax.xml.ws.handler.MessageContext;
22  
23  import org.apache.cxf.binding.soap.SoapMessage;
24  import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
25  import org.apache.log4j.Logger;
26  import org.apache.ws.security.components.crypto.Crypto;
27  import org.apache.ws.security.components.crypto.Merlin;
28  import org.apache.ws.security.handler.RequestData;
29  import org.apache.ws.security.handler.WSHandlerConstants;
30  import org.kuali.rice.core.config.ConfigContext;
31  import org.kuali.rice.core.exception.RiceRuntimeException;
32  import org.kuali.rice.core.util.ClassLoaderUtils;
33  import org.kuali.rice.ksb.config.wss4j.CryptoPasswordCallbackHandler;
34  import org.kuali.rice.ksb.messaging.ServiceInfo;
35  
36  
37  /**
38   *
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   */
41  
42  //TODO: Replace this class with cxf wss4j in interceptor
43  public class CXFWSS4JInInterceptor extends WSS4JInInterceptor{
44  
45  	private static final Logger LOG = Logger.getLogger(CXFWSS4JInInterceptor.class);
46  	private ServiceInfo serviceInfo;
47  
48  	public CXFWSS4JInInterceptor(ServiceInfo serviceInfo) {
49  		this.serviceInfo = serviceInfo;
50  		this.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
51  		this.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, CryptoPasswordCallbackHandler.class.getName());
52  		this.setProperty(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");
53  		this.setProperty(WSHandlerConstants.USER, ConfigContext.getCurrentContextConfig().getKeystoreAlias());
54  	}
55  
56  	@Override
57  	public Crypto loadSignatureCrypto(RequestData reqData) {
58  		try {
59  			return new Merlin(getMerlinProperties(), ClassLoaderUtils.getDefaultClassLoader());
60  		} catch (Exception e) {
61  			throw new RiceRuntimeException(e);
62  		}
63  	}
64  
65  	@Override
66  	public Crypto loadDecryptionCrypto(RequestData reqData) {
67  		return loadSignatureCrypto(reqData);
68  	}
69  
70  	protected Properties getMerlinProperties() {
71  		Properties props = new Properties();
72  		props.put("org.apache.ws.security.crypto.merlin.keystore.type", "jks");
73  		props.put("org.apache.ws.security.crypto.merlin.keystore.password", ConfigContext.getCurrentContextConfig().getKeystorePassword());
74  		props.put("org.apache.ws.security.crypto.merlin.alias.password", ConfigContext.getCurrentContextConfig().getKeystorePassword());
75  		props.put("org.apache.ws.security.crypto.merlin.keystore.alias", ConfigContext.getCurrentContextConfig().getKeystoreAlias());
76  		props.put("org.apache.ws.security.crypto.merlin.file", ConfigContext.getCurrentContextConfig().getKeystoreFile());
77  
78  		if (LOG.isDebugEnabled()) {
79  			LOG.debug("Using keystore location " + ConfigContext.getCurrentContextConfig().getKeystoreFile());
80  		}
81  		return props;
82  	}
83  
84  	/**
85  	 * This overridden method will not apply security headers if bus security is disabled.
86  	 * 
87  	 * @see org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor#handleMessage(org.apache.cxf.binding.soap.SoapMessage)
88  	 */
89  	@Override
90  	public void handleMessage(SoapMessage mc)  {
91  		if (getServiceInfo().getServiceDefinition().getBusSecurity()) {
92  			super.handleMessage(mc);
93  		}
94  	}
95  
96  	public ServiceInfo getServiceInfo() {
97  		return serviceInfo;
98  	}
99  
100 	public void setServiceInfo(ServiceInfo serviceInfo) {
101 		this.serviceInfo = serviceInfo;
102 	}
103 
104 }