001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.kuali.rice.config.xfire;
018:
019: import java.util.Properties;
020:
021: import org.apache.log4j.Logger;
022: import org.apache.ws.security.components.crypto.Crypto;
023: import org.apache.ws.security.components.crypto.Merlin;
024: import org.apache.ws.security.handler.RequestData;
025: import org.apache.ws.security.handler.WSHandlerConstants;
026: import org.codehaus.xfire.MessageContext;
027: import org.codehaus.xfire.fault.XFireFault;
028: import org.codehaus.xfire.security.wss4j.WSS4JInHandler;
029: import org.kuali.rice.config.wss4j.CryptoPasswordCallbackHandler;
030: import org.kuali.rice.core.Core;
031: import org.kuali.rice.exceptions.RiceRuntimeException;
032: import org.kuali.rice.util.ClassLoaderUtils;
033:
034: import edu.iu.uis.eden.messaging.ServiceInfo;
035:
036: /**
037: *
038: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
039: */
040: public class WorkflowXFireWSS4JInHandler extends WSS4JInHandler {
041:
042: private static final Logger LOG = Logger
043: .getLogger(WorkflowXFireWSS4JInHandler.class);
044: private ServiceInfo serviceInfo;
045:
046: public WorkflowXFireWSS4JInHandler(ServiceInfo serviceInfo) {
047: this .serviceInfo = serviceInfo;
048: this .setProperty(WSHandlerConstants.ACTION,
049: WSHandlerConstants.SIGNATURE);
050: this .setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
051: CryptoPasswordCallbackHandler.class.getName());
052: this .setProperty(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");
053: this .setProperty(WSHandlerConstants.USER, Core
054: .getCurrentContextConfig().getKeystoreAlias());
055: }
056:
057: @Override
058: public Crypto loadSignatureCrypto(RequestData reqData) {
059: try {
060: return new Merlin(getMerlinProperties(), ClassLoaderUtils
061: .getDefaultClassLoader());
062: } catch (Exception e) {
063: throw new RiceRuntimeException(e);
064: }
065: }
066:
067: @Override
068: public Crypto loadDecryptionCrypto(RequestData reqData) {
069: return loadSignatureCrypto(reqData);
070: }
071:
072: protected Properties getMerlinProperties() {
073: Properties props = new Properties();
074: props.put("org.apache.ws.security.crypto.merlin.keystore.type",
075: "jks");
076: props
077: .put(
078: "org.apache.ws.security.crypto.merlin.keystore.password",
079: Core.getCurrentContextConfig()
080: .getKeystorePassword());
081: props.put(
082: "org.apache.ws.security.crypto.merlin.alias.password",
083: Core.getCurrentContextConfig().getKeystorePassword());
084: props.put(
085: "org.apache.ws.security.crypto.merlin.keystore.alias",
086: Core.getCurrentContextConfig().getKeystoreAlias());
087: props.put("org.apache.ws.security.crypto.merlin.file", Core
088: .getCurrentContextConfig().getKeystoreFile());
089:
090: if (LOG.isDebugEnabled()) {
091: LOG.debug("Using keystore location "
092: + Core.getCurrentContextConfig().getKeystoreFile());
093: }
094: return props;
095: }
096:
097: @Override
098: public void invoke(MessageContext context) throws XFireFault {
099: if (getServiceInfo().getServiceDefinition().getBusSecurity()) {
100: super .invoke(context);
101: }
102: }
103:
104: public ServiceInfo getServiceInfo() {
105: return serviceInfo;
106: }
107:
108: public void setServiceInfo(ServiceInfo serviceInfo) {
109: this.serviceInfo = serviceInfo;
110: }
111:
112: }
|