001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.security.impl.policyconv;
038:
039: import com.sun.xml.ws.security.policy.AlgorithmSuite;
040: import com.sun.xml.wss.impl.MessageConstants;
041: import com.sun.xml.wss.impl.policy.mls.Parameter;
042: import com.sun.xml.wss.impl.policy.mls.SignatureTarget;
043: import javax.xml.crypto.dsig.CanonicalizationMethod;
044: import javax.xml.namespace.QName;
045: import com.sun.xml.ws.security.impl.policy.Constants;
046:
047: /**
048: *
049: * @author K.Venugopal@sun.com
050: */
051: public class SignatureTargetCreator {
052: private boolean enforce = false;
053: private AlgorithmSuite algorithmSuite = null;
054: private boolean contentOnly = false;
055:
056: /**
057: * Creates a new instance of SignatureTargetCreator
058: */
059: public SignatureTargetCreator(boolean enforce,
060: AlgorithmSuite algorithmSuite, boolean contentOnly) {
061: this .enforce = enforce;
062: this .algorithmSuite = algorithmSuite;
063: }
064:
065: public SignatureTarget newURISignatureTarget(String uid) {
066: if (uid != null) {
067: SignatureTarget target = new SignatureTarget();
068: target.setType(SignatureTarget.TARGET_TYPE_VALUE_URI);
069: target.setDigestAlgorithm(algorithmSuite
070: .getDigestAlgorithm());
071: target.setValue("#" + uid);
072: addEXC14n(target);
073: target.setEnforce(enforce);
074: return target;
075: }
076: return null;
077: }
078:
079: public SignatureTarget newXpathSignatureTarget(String xpathTarget) {
080: SignatureTarget target = new SignatureTarget();
081: target.setType(SignatureTarget.TARGET_TYPE_VALUE_XPATH);
082: target.setDigestAlgorithm(algorithmSuite.getDigestAlgorithm());
083: addEXC14n(target);
084: target.setValue(xpathTarget);
085: target.setContentOnly(contentOnly);
086: target.setEnforce(enforce);
087: return target;
088: }
089:
090: public SignatureTarget newQNameSignatureTarget(QName name) {
091: SignatureTarget target = new SignatureTarget();
092: target.setType(SignatureTarget.TARGET_TYPE_VALUE_QNAME);
093: target.setDigestAlgorithm(algorithmSuite.getDigestAlgorithm());
094: target.setContentOnly(contentOnly);
095: target.setEnforce(enforce);
096: target.setQName(name);
097: addEXC14n(target);
098: return target;
099: }
100:
101: public void addEXC14n(SignatureTarget target) {
102: SignatureTarget.Transform tr = target.newSignatureTransform();
103: if (algorithmSuite != null
104: && algorithmSuite.getAdditionalProps().contains(
105: Constants.InclusiveC14N)) {
106: tr.setTransform(CanonicalizationMethod.INCLUSIVE);
107: } else {
108: tr.setTransform(CanonicalizationMethod.EXCLUSIVE);
109: }
110:
111: if (algorithmSuite != null
112: && algorithmSuite
113: .getAdditionalProps()
114: .contains(
115: Constants.InclusiveC14NWithCommentsForTransforms)) {
116: tr
117: .setTransform(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS);
118: } else if (algorithmSuite != null
119: && algorithmSuite
120: .getAdditionalProps()
121: .contains(
122: Constants.ExclusiveC14NWithCommentsForTransforms)) {
123: tr
124: .setTransform(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS);
125: }
126: target.addTransform(tr);
127: }
128:
129: public void addSTRTransform(SignatureTarget target) {
130: SignatureTarget.Transform tr = target.newSignatureTransform();
131: tr.setTransform(MessageConstants.STR_TRANSFORM_URI);
132: target.addTransform(tr);
133: tr.setAlgorithmParameters(new Parameter(
134: "CanonicalizationMethod",
135: CanonicalizationMethod.EXCLUSIVE));
136: }
137: }
|