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.policy.PolicyException;
040: import com.sun.xml.ws.security.policy.Binding;
041: import com.sun.xml.ws.security.policy.EndorsingSupportingTokens;
042: import com.sun.xml.ws.security.policy.SignedEndorsingSupportingTokens;
043: import com.sun.xml.ws.security.policy.SignedSupportingTokens;
044: import com.sun.xml.ws.security.policy.SupportingTokens;
045: import com.sun.xml.ws.security.policy.Token;
046: import com.sun.xml.ws.security.policy.TransportBinding;
047: import com.sun.xml.wss.impl.policy.mls.AuthenticationTokenPolicy;
048: import com.sun.xml.wss.impl.policy.mls.EncryptionPolicy;
049: import com.sun.xml.wss.impl.policy.mls.SignaturePolicy;
050: import com.sun.xml.wss.impl.policy.mls.SignatureTarget;
051: import com.sun.xml.wss.impl.policy.mls.TimestampPolicy;
052: import com.sun.xml.wss.impl.policy.mls.WSSPolicy;
053: import java.util.Iterator;
054: import javax.xml.crypto.dsig.CanonicalizationMethod;
055:
056: /**
057: *
058: * @author K.Venugopal@sun.com
059: */
060: public class TransportBindingProcessor extends BindingProcessor {
061: private TransportBinding binding = null;
062: private TimestampPolicy tp = null;
063:
064: /** Creates a new instance of TransportBindingProcessor */
065: public TransportBindingProcessor(TransportBinding binding,
066: boolean isServer, boolean isIncoming,
067: XWSSPolicyContainer container) {
068: this .binding = binding;
069: this .container = container;
070: this .isIncoming = isIncoming;
071: this .isServer = isServer;
072: iAP = new IntegrityAssertionProcessor(binding
073: .getAlgorithmSuite(), false);
074: eAP = new EncryptionAssertionProcessor(binding
075: .getAlgorithmSuite(), false);
076: this .tokenProcessor = new TokenProcessor(isServer, isIncoming,
077: pid);
078: }
079:
080: public void process() throws PolicyException {
081: container.setPolicyContainerMode(binding.getLayout());
082: if (binding.isIncludeTimeStamp()) {
083: tp = new TimestampPolicy();
084: tp.setUUID(pid.generateID());
085: container.insert(tp);
086: }
087: }
088:
089: public void processSupportingTokens(SupportingTokens tokens)
090: throws PolicyException {
091: Iterator itr = tokens.getTokens();
092: while (itr.hasNext()) {
093: Token token = (Token) itr.next();
094: WSSPolicy policy = tokenProcessor.getWSSToken(token);
095: AuthenticationTokenPolicy atp = new AuthenticationTokenPolicy();
096: atp.setFeatureBinding(policy);
097: container.insert(atp);
098: }
099: }
100:
101: public void processSupportingTokens(SignedSupportingTokens sst)
102: throws PolicyException {
103: Iterator itr = sst.getTokens();
104: while (itr.hasNext()) {
105: Token token = (Token) itr.next();
106: WSSPolicy policy = tokenProcessor.getWSSToken(token);
107: AuthenticationTokenPolicy atp = new AuthenticationTokenPolicy();
108: atp.setFeatureBinding(policy);
109: container.insert(atp);
110: }
111: }
112:
113: public void processSupportingTokens(EndorsingSupportingTokens est)
114: throws PolicyException {
115: Iterator itr = est.getTokens();
116: while (itr.hasNext()) {
117: Token token = (Token) itr.next();
118: SignaturePolicy sp = new SignaturePolicy();
119: SignaturePolicy.FeatureBinding spFB = (com.sun.xml.wss.impl.policy.mls.SignaturePolicy.FeatureBinding) sp
120: .getFeatureBinding();
121: //spFB.setCanonicalizationAlgorithm(CanonicalizationMethod.EXCLUSIVE);
122: SecurityPolicyUtil.setCanonicalizationMethod(spFB, binding
123: .getAlgorithmSuite());
124: sp.setUUID(pid.generateID());
125: tokenProcessor.addKeyBinding(sp, token, false);
126: // container.insert(sp.getKeyBinding());
127:
128: if (tp != null) {
129: SignatureTarget target = iAP.getTargetCreator()
130: .newURISignatureTarget(tp.getUUID());
131: SecurityPolicyUtil.setName(target, tp);
132: // there is no primary signature in Transport Binding
133: //spFB.isEndorsingSignature(true);
134: spFB.addTargetBinding(target);
135:
136: container.insert(sp);
137: }
138:
139: }
140: }
141:
142: public void processSupportingTokens(
143: SignedEndorsingSupportingTokens set) throws PolicyException {
144: Iterator itr = set.getTokens();
145: while (itr.hasNext()) {
146: Token token = (Token) itr.next();
147: SignaturePolicy sp = new SignaturePolicy();
148: sp.setUUID(pid.generateID());
149: SignaturePolicy.FeatureBinding spFB = (com.sun.xml.wss.impl.policy.mls.SignaturePolicy.FeatureBinding) sp
150: .getFeatureBinding();
151: //spFB.setCanonicalizationAlgorithm(CanonicalizationMethod.EXCLUSIVE);
152: SecurityPolicyUtil.setCanonicalizationMethod(spFB, binding
153: .getAlgorithmSuite());
154: tokenProcessor.addKeyBinding(sp, token, false);
155:
156: //protect primary signature
157:
158: if (tp != null) {
159: SignatureTarget target = iAP.getTargetCreator()
160: .newURISignatureTarget(tp.getUUID());
161: SecurityPolicyUtil.setName(target, tp);
162: //SignaturePolicy.FeatureBinding spFB = (SignaturePolicy.FeatureBinding)sp.getFeatureBinding();
163: //spFB.isEndorsingSignature(true);
164: spFB.addTargetBinding(target);
165: container.insert(sp);
166: }
167: }
168: }
169:
170: protected EncryptionPolicy getSecondaryEncryptionPolicy()
171: throws PolicyException {
172: throw new UnsupportedOperationException();
173: }
174:
175: protected Binding getBinding() {
176: return binding;
177: }
178:
179: protected void close() {
180:
181: }
182: }
|