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.security.wss4j.WSS4JOutHandler;
028: import org.kuali.rice.config.wss4j.CryptoPasswordCallbackHandler;
029: import org.kuali.rice.core.Core;
030: import org.kuali.rice.exceptions.RiceRuntimeException;
031: import org.kuali.rice.util.ClassLoaderUtils;
032:
033: import edu.iu.uis.eden.messaging.ServiceInfo;
034:
035: /**
036: *
037: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
038: */
039: public class WorkflowXFireWSS4JOutHandler extends WSS4JOutHandler {
040:
041: private static final Logger LOG = Logger
042: .getLogger(WorkflowXFireWSS4JOutHandler.class);
043:
044: private ServiceInfo serviceInfo;
045:
046: public WorkflowXFireWSS4JOutHandler(ServiceInfo serviceInfo) {
047: this .setProperty(WSHandlerConstants.ACTION,
048: WSHandlerConstants.SIGNATURE);
049: this .setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
050: CryptoPasswordCallbackHandler.class.getName());
051: this .setProperty(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");
052: this .setProperty(WSHandlerConstants.USER, Core
053: .getCurrentContextConfig().getKeystoreAlias());
054: this .serviceInfo = serviceInfo;
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:
095: return props;
096: }
097:
098: @Override
099: public void invoke(MessageContext context) throws Exception {
100: if (getServiceInfo().getServiceDefinition().getBusSecurity()) {
101: super .invoke(context);
102: }
103: }
104:
105: public ServiceInfo getServiceInfo() {
106: return serviceInfo;
107: }
108:
109: public void setServiceInfo(ServiceInfo serviceInfo) {
110: this.serviceInfo = serviceInfo;
111: }
112:
113: }
|