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.policy;
038:
039: import com.sun.xml.ws.policy.AssertionSet;
040: import com.sun.xml.ws.policy.NestedPolicy;
041: import com.sun.xml.ws.policy.PolicyAssertion;
042: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
043: import com.sun.xml.ws.security.policy.AlgorithmSuiteValue;
044: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
045: import java.util.Collection;
046: import java.util.HashSet;
047: import java.util.Iterator;
048: import java.util.Set;
049: import java.util.logging.Level;
050: import static com.sun.xml.ws.security.impl.policy.Constants.*;
051:
052: /**
053: *
054: * @author K.Venugopal@sun.com Abhijit.das@Sun.com
055: */
056:
057: public class AlgorithmSuite extends
058: com.sun.xml.ws.policy.PolicyAssertion implements
059: com.sun.xml.ws.security.policy.AlgorithmSuite,
060: SecurityAssertionValidator {
061:
062: private AssertionFitness fitness = AssertionFitness.IS_VALID;
063: private AlgorithmSuiteValue value;
064: private HashSet<String> props = new HashSet<String>();
065: private boolean populated = false;
066: private boolean isValid = true;
067:
068: /**
069: * Creates a new instance of AlgorithmSuite
070: */
071: public AlgorithmSuite() {
072: }
073:
074: public AlgorithmSuite(AssertionData name,
075: Collection<PolicyAssertion> nestedAssertions,
076: AssertionSet nestedAlternative) {
077: super (name, nestedAssertions, nestedAlternative);
078: }
079:
080: public Set getAdditionalProps() {
081: return props;
082: }
083:
084: public void setAdditionalProps(Set properties) {
085: }
086:
087: public void setType(AlgorithmSuiteValue value) {
088: this .value = value;
089: populated = true;
090: }
091:
092: public AlgorithmSuiteValue getType() {
093: populate();
094: return value;
095: }
096:
097: public String getDigestAlgorithm() {
098: populate();
099: return value.getDigAlgorithm();
100: }
101:
102: public String getEncryptionAlgorithm() {
103: populate();
104: return value.getEncAlgorithm();
105: }
106:
107: public String getSymmetricKeyAlgorithm() {
108: populate();
109: return value.getSymKWAlgorithm();
110: }
111:
112: public String getAsymmetricKeyAlgorithm() {
113: populate();
114: return value.getAsymKWAlgorithm();
115: }
116:
117: public String getSignatureKDAlogrithm() {
118: populate();
119: return value.getSigKDAlgorithm();
120: }
121:
122: public String getEncryptionKDAlogrithm() {
123: populate();
124: return value.getEncKDAlgorithm();
125: }
126:
127: public int getMinSKLAlgorithm() {
128: populate();
129: return value.getMinSKLAlgorithm();
130: }
131:
132: public String getSymmetricKeySignatureAlgorithm() {
133: return com.sun.xml.ws.security.policy.Constants.HMAC_SHA1;
134: }
135:
136: public String getAsymmetricKeySignatureAlgorithm() {
137: return com.sun.xml.ws.security.policy.Constants.RSA_SHA1;
138: }
139:
140: private void populate() {
141: populate(false);
142: }
143:
144: private synchronized AssertionFitness populate(boolean isServer) {
145:
146: if (!populated) {
147: NestedPolicy policy = this .getNestedPolicy();
148: if (policy == null) {
149: if (logger.isLoggable(Level.FINE)) {
150: logger.log(Level.FINE, "NestedPolicy is null");
151: }
152: if (this .value == null) {
153: this .value = AlgorithmSuiteValue.Basic128;
154: }
155: return fitness;
156: }
157: AssertionSet as = policy.getAssertionSet();
158:
159: Iterator<PolicyAssertion> ast = as.iterator();
160: while (ast.hasNext()) {
161: PolicyAssertion assertion = ast.next();
162: if (this .value == null) {
163: AlgorithmSuiteValue av = PolicyUtil
164: .isValidAlgorithmSuiteValue(assertion);
165: if (av != null) {
166: this .value = av;
167: continue;
168: }
169: }
170: if (PolicyUtil.isInclusiveC14N(assertion)) {
171: this .props.add(Constants.InclusiveC14N);
172: } else if (PolicyUtil.isXPath(assertion)) {
173: this .props.add(Constants.XPath);
174: } else if (PolicyUtil.isXPathFilter20(assertion)) {
175: this .props.add(Constants.XPathFilter20);
176: } else if (PolicyUtil.isSTRTransform10(assertion)) {
177: this .props.add(Constants.STRTransform10);
178: } else if (PolicyUtil
179: .isInclusiveC14NWithComments(assertion)) {
180: if (PolicyUtil
181: .isInclusiveC14NWithCommentsForTransforms(assertion)) {
182: this .props
183: .add(Constants.InclusiveC14NWithCommentsForTransforms);
184: }
185: if (PolicyUtil
186: .isInclusiveC14NWithCommentsForCm(assertion)) {
187: this .props
188: .add(Constants.InclusiveC14NWithCommentsForCm);
189: }
190: } else if (PolicyUtil
191: .isExclusiveC14NWithComments(assertion)) {
192: if (PolicyUtil
193: .isExclusiveC14NWithCommentsForTransforms(assertion)) {
194: this .props
195: .add(Constants.ExclusiveC14NWithCommentsForTransforms);
196: }
197: if (PolicyUtil
198: .isExclusiveC14NWithCommentsForCm(assertion)) {
199: this .props
200: .add(Constants.ExclusiveC14NWithCommentsForCm);
201: }
202: } else {
203: if (!assertion.isOptional()) {
204: log_invalid_assertion(assertion, isServer,
205: AlgorithmSuite);
206: fitness = AssertionFitness.HAS_UNKNOWN_ASSERTION;
207: }
208: }
209: }
210: if (this .value == null) {
211: this .value = AlgorithmSuiteValue.Basic128;
212: }
213: populated = true;
214: }
215: return fitness;
216: }
217:
218: public String getComputedKeyAlgorithm() {
219: return com.sun.xml.ws.security.policy.Constants.PSHA1;
220: }
221:
222: public int getMaxSymmetricKeyLength() {
223: return MAX_SKL;
224: }
225:
226: public int getMinAsymmetricKeyLength() {
227: return MIN_AKL;
228: }
229:
230: public int getMaxAsymmetricKeyLength() {
231: return MAX_AKL;
232: }
233:
234: public AssertionFitness validate(boolean isServer) {
235: return populate(isServer);
236: }
237: }
|