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: /** The contents of this file are subject to the terms
038: * of the Common Development and Distribution License
039: * (the License). You may not use this file except in
040: * compliance with the License.
041: *
042: * You can obtain a copy of the license at
043: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
044: * See the License for the specific language governing
045: * permissions and limitations under the License.
046: *
047: * When distributing Covered Code, include this CDDL
048: * Header Notice in each file and include the License file
049: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
050: * If applicable, add the following below the CDDL Header,
051: * with the fields enclosed by brackets [] replaced by
052: * you own identifying information:
053: * "Portions Copyrighted [year] [name of copyright owner]"
054: *
055: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
056: */package com.sun.xml.ws.security.impl.policy;
057:
058: import com.sun.xml.ws.policy.AssertionSet;
059: import com.sun.xml.ws.policy.NestedPolicy;
060: import com.sun.xml.ws.policy.PolicyAssertion;
061: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
062: import com.sun.xml.ws.security.policy.AlgorithmSuite;
063: import com.sun.xml.ws.security.policy.MessageLayout;
064: import com.sun.xml.ws.security.policy.Token;
065: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
066: import java.util.Collection;
067: import java.util.Iterator;
068: import java.util.logging.Level;
069: import static com.sun.xml.ws.security.impl.policy.Constants.*;
070:
071: /**
072: *
073: * @author K.Venugopal@sun.com
074: */
075:
076: public class AsymmetricBinding extends
077: com.sun.xml.ws.policy.PolicyAssertion implements
078: com.sun.xml.ws.security.policy.AsymmetricBinding,
079: SecurityAssertionValidator {
080:
081: private AssertionFitness fitness = AssertionFitness.IS_VALID;
082: private Token initiatorToken;
083: private Token recipientToken;
084: private AlgorithmSuite algSuite;
085: private boolean includeTimestamp = false;
086: private boolean disableTimestampSigning = false;
087: private boolean contentOnly = true;
088: private MessageLayout layout = MessageLayout.Lax;
089: private String protectionOrder = SIGN_ENCRYPT;
090: private boolean protectToken = false;
091: private boolean protectSignature = false;
092: private boolean populated = false;
093:
094: /**
095: * Creates a new instance of AsymmetricBinding
096: */
097: public AsymmetricBinding() {
098: }
099:
100: public AsymmetricBinding(AssertionData name,
101: Collection<PolicyAssertion> nestedAssertions,
102: AssertionSet nestedAlternative) {
103: super (name, nestedAssertions, nestedAlternative);
104: }
105:
106: public Token getRecipientToken() {
107: populate();
108: return recipientToken;
109: }
110:
111: public Token getInitiatorToken() {
112: populate();
113: return initiatorToken;
114: }
115:
116: public void setAlgorithmSuite(AlgorithmSuite algSuite) {
117: this .algSuite = algSuite;
118: }
119:
120: public AlgorithmSuite getAlgorithmSuite() {
121: populate();
122: if (algSuite == null) {
123: algSuite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
124: logger.log(Level.FINE,
125: "Using Default Algorithm Suite Basic128");
126: }
127: return algSuite;
128: }
129:
130: public void includeTimeStamp(boolean value) {
131: populate();
132: this .includeTimestamp = value;
133: }
134:
135: public boolean isIncludeTimeStamp() {
136: populate();
137: return includeTimestamp;
138: }
139:
140: public boolean isDisableTimestampSigning() {
141: populate();
142: return disableTimestampSigning;
143: }
144:
145: public void setLayout(MessageLayout layout) {
146: this .layout = layout;
147: }
148:
149: public MessageLayout getLayout() {
150: populate();
151: return layout;
152: }
153:
154: public void setInitiatorToken(Token token) {
155: this .initiatorToken = token;
156: }
157:
158: public void setRecipientToken(Token token) {
159: this .recipientToken = token;
160: }
161:
162: public boolean isSignContent() {
163: populate();
164: return contentOnly;
165: }
166:
167: public void setSignContent(boolean contentOnly) {
168: this .contentOnly = contentOnly;
169: }
170:
171: public void setProtectionOrder(String order) {
172: this .protectionOrder = order;
173: }
174:
175: public String getProtectionOrder() {
176: populate();
177: return protectionOrder;
178: }
179:
180: public void setTokenProtection(boolean value) {
181: this .protectToken = value;
182: }
183:
184: public void setSignatureProtection(boolean value) {
185: this .protectSignature = value;
186:
187: }
188:
189: public boolean getTokenProtection() {
190: populate();
191: return protectToken;
192: }
193:
194: public boolean getSignatureProtection() {
195: populate();
196: return protectSignature;
197: }
198:
199: public AssertionFitness validate(boolean isServer) {
200:
201: return populate(isServer);
202:
203: }
204:
205: private void populate() {
206: populate(false);
207: }
208:
209: private synchronized AssertionFitness populate(boolean isServer) {
210: if (!populated) {
211: NestedPolicy policy = this .getNestedPolicy();
212: if (policy == null) {
213: if (logger.isLoggable(Level.FINE)) {
214: logger.log(Level.FINE, "NestedPolicy is null");
215: }
216: populated = true;
217: return fitness;
218: }
219: AssertionSet as = policy.getAssertionSet();
220: Iterator<PolicyAssertion> ast = as.iterator();
221: while (ast.hasNext()) {
222: PolicyAssertion assertion = ast.next();
223: if (PolicyUtil.isInitiatorToken(assertion)) {
224: this .initiatorToken = ((com.sun.xml.ws.security.impl.policy.Token) assertion)
225: .getToken();
226: } else if (PolicyUtil.isRecipientToken(assertion)) {
227: this .recipientToken = ((com.sun.xml.ws.security.impl.policy.Token) assertion)
228: .getToken();
229: } else if (PolicyUtil.isAlgorithmAssertion(assertion)) {
230: this .algSuite = (AlgorithmSuite) assertion;
231: } else if (PolicyUtil.isIncludeTimestamp(assertion)) {
232: this .includeTimestamp = true;
233: } else if (PolicyUtil.isEncryptBeforeSign(assertion)) {
234: this .protectionOrder = ENCRYPT_SIGN;
235: } else if (PolicyUtil.isSignBeforeEncrypt(assertion)) {
236: this .protectionOrder = SIGN_ENCRYPT;
237: } else if (PolicyUtil.isContentOnlyAssertion(assertion)) {
238: this .contentOnly = false;
239: } else if (PolicyUtil.isMessageLayout(assertion)) {
240: layout = ((Layout) assertion).getMessageLayout();
241: } else if (PolicyUtil.isProtectTokens(assertion)) {
242: this .protectToken = true;
243: } else if (PolicyUtil.isEncryptSignature(assertion)) {
244: this .protectSignature = true;
245: } else if (PolicyUtil
246: .disableTimestampSigning(assertion)) {
247: this .disableTimestampSigning = true;
248: } else {
249: if (!assertion.isOptional()) {
250: log_invalid_assertion(assertion, isServer,
251: AsymmetricBinding);
252: fitness = AssertionFitness.HAS_UNKNOWN_ASSERTION;
253: }
254: }
255: }
256: populated = true;
257: }
258: return fitness;
259: }
260: }
|