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.SignedParts;
040: import com.sun.xml.ws.security.policy.AlgorithmSuite;
041: import com.sun.xml.ws.security.policy.Header;
042: import com.sun.xml.ws.security.policy.SignedElements;
043: import com.sun.xml.wss.impl.policy.mls.SignaturePolicy;
044: import com.sun.xml.wss.impl.policy.mls.SignatureTarget;
045: import com.sun.xml.wss.impl.policy.mls.Target;
046: import java.util.HashSet;
047: import java.util.Iterator;
048: import javax.xml.namespace.QName;
049:
050: /**
051: *
052: * @author K.Venugopal@sun.com
053: */
054: public class IntegrityAssertionProcessor {
055:
056: private AlgorithmSuite algorithmSuite = null;
057: private boolean contentOnly = false;
058:
059: private boolean seenBody = false;
060: private HashSet<Header> signParts = new HashSet<Header>();
061: private boolean allHeaders = false;
062: private boolean ENFORCE = false;
063: private SignatureTargetCreator targetCreator = null;
064:
065: /** Creates a new instance of IntegrityAssertionProcessor */
066:
067: public IntegrityAssertionProcessor(AlgorithmSuite algorithmSuite,
068: boolean contentOnly) {
069: this .algorithmSuite = algorithmSuite;
070: this .contentOnly = contentOnly;
071: targetCreator = new SignatureTargetCreator(false,
072: algorithmSuite, contentOnly);
073: }
074:
075: public SignatureTargetCreator getTargetCreator() {
076: return targetCreator;
077: }
078:
079: public void process(SignedParts signedParts,
080: SignaturePolicy.FeatureBinding binding) {
081: Iterator tv = signedParts.getHeaders();
082: if (SecurityPolicyUtil.isSignedPartsEmpty(signedParts)) {
083: if (!allHeaders) {
084: SignatureTarget target = targetCreator
085: .newURISignatureTarget("");
086: target.setValue(SignatureTarget.ALL_MESSAGE_HEADERS);
087: target.isSOAPHeadersOnly(true);
088: binding.addTargetBinding(target);
089: target.setContentOnly(contentOnly);
090: allHeaders = true;
091: }
092: if (!seenBody) {
093: SignatureTarget target = targetCreator
094: .newQNameSignatureTarget(Target.BODY_QNAME);
095: binding.addTargetBinding(target);
096: target.setContentOnly(contentOnly);
097: seenBody = true;
098: }
099: } else {
100: while (tv.hasNext()) {
101: Header ht = (Header) tv.next();
102: if (!allHeaders && !seenSignTarget(ht)) {
103: SignatureTarget target = targetCreator
104: .newQNameSignatureTarget(new QName(ht
105: .getURI(), ht.getLocalName()));
106: target.isSOAPHeadersOnly(true);
107: target.setContentOnly(contentOnly);
108: binding.addTargetBinding(target);
109: }
110: }
111: if (signedParts.hasBody()) {
112: if (!seenBody) {
113: SignatureTarget target = targetCreator
114: .newQNameSignatureTarget(Target.BODY_QNAME);
115: target.setContentOnly(contentOnly);
116: binding.addTargetBinding(target);
117: seenBody = true;
118: }
119: }
120: }
121: }
122:
123: public void process(SignedElements signedElements,
124: SignaturePolicy.FeatureBinding binding) {
125: Iterator<String> itr = signedElements.getTargets();
126: while (itr.hasNext()) {
127: String xpathTarget = itr.next();
128: SignatureTarget target = targetCreator
129: .newXpathSignatureTarget(xpathTarget);
130: target.setContentOnly(contentOnly);
131: // target.setXPathVersion(signedElements.)
132: binding.addTargetBinding(target);
133: }
134: }
135:
136: private boolean seenSignTarget(Header name) {
137: // Iterator<Header> itr = signParts.iterator();
138: // while(itr.hasNext()){
139: // Header header = itr.next();
140: // if(header.getLocalName().equals(name.getLocalName()) && header.getURI().equals(name.getURI())){
141: // return true;
142: // }
143: // }
144: if (signParts.contains(name)) {
145: return true;
146: }
147: signParts.add(name);
148: return false;
149: }
150:
151: public void process(QName targetName,
152: SignaturePolicy.FeatureBinding binding) {
153: SignatureTarget target = targetCreator
154: .newQNameSignatureTarget(targetName);
155: binding.addTargetBinding(target);
156: }
157: }
|