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.PolicyAssertion;
041: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
042: import com.sun.xml.ws.security.policy.Lifetime;
043: import java.util.Collection;
044: import java.util.Iterator;
045: import static com.sun.xml.ws.security.impl.policy.Constants.*;
046: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
047:
048: /**
049: *
050: * @author K.Venugopal@sun.com Abhijit.Das@Sun.COM
051: */
052: public class RequestSecurityTokenTemplate extends PolicyAssertion
053: implements
054: com.sun.xml.ws.security.policy.RequestSecurityTokenTemplate,
055: SecurityAssertionValidator {
056:
057: private boolean populated = false;
058: private AssertionFitness fitness = AssertionFitness.IS_VALID;
059: String tokenType;
060: String requestType;
061: Lifetime lifeTime;
062: String authenticationType;
063: private String keyType;
064: private int keySize;
065: private String sigAlgo;
066: private String encAlgo;
067: private String canonAlgo;
068: private boolean isProofEncRequired = false;
069: private String computedKeyAlgo;
070: private boolean isEncRequired = false;
071: private String signWith;
072: private String encryptWith;
073:
074: /**
075: * Creates a new instance of RequestSecurityTokenTemplate
076: */
077: public RequestSecurityTokenTemplate() {
078: }
079:
080: public RequestSecurityTokenTemplate(AssertionData name,
081: Collection<PolicyAssertion> nestedAssertions,
082: AssertionSet nestedAlternative) {
083: super (name, nestedAssertions, nestedAlternative);
084: }
085:
086: public String getTokenType() {
087: populate();
088: return tokenType;
089: }
090:
091: public String getRequestType() {
092: populate();
093: return this .requestType;
094: }
095:
096: public Lifetime getLifetime() {
097: populate();
098: return lifeTime;
099: }
100:
101: public String getAuthenticationType() {
102: populate();
103: return authenticationType;
104: }
105:
106: public String getKeyType() {
107: populate();
108: return keyType;
109: }
110:
111: public int getKeySize() {
112: populate();
113: return keySize;
114: }
115:
116: public String getSignatureAlgorithm() {
117: populate();
118: return sigAlgo;
119: }
120:
121: public String getEncryptionAlgorithm() {
122: populate();
123: return encAlgo;
124: }
125:
126: public String getCanonicalizationAlgorithm() {
127: populate();
128: return canonAlgo;
129: }
130:
131: public boolean getProofEncryptionRequired() {
132: populate();
133: return isProofEncRequired;
134: }
135:
136: public String getComputedKeyAlgorithm() {
137: populate();
138: return computedKeyAlgo;
139: }
140:
141: public boolean getEncryptionRequired() {
142: populate();
143: return isEncRequired;
144: }
145:
146: public String getSignWith() {
147: populate();
148: return signWith;
149: }
150:
151: public String getEncryptWith() {
152: populate();
153: return encryptWith;
154: }
155:
156: public String getTrustVersion() {
157: throw new UnsupportedOperationException();
158: }
159:
160: public AssertionFitness validate(boolean isServer) {
161: return populate(isServer);
162: }
163:
164: private void populate() {
165: populate(false);
166: }
167:
168: private synchronized AssertionFitness populate(boolean isServer) {
169: if (!populated) {
170: if (this .hasNestedAssertions()) {
171:
172: Iterator<PolicyAssertion> it = this
173: .getNestedAssertionsIterator();
174: while (it.hasNext()) {
175: PolicyAssertion assertion = (PolicyAssertion) it
176: .next();
177: //TODO: Support all RequestSecurityTokenTemplate elements
178: if (PolicyUtil.isKeyType(assertion)) {
179: this .keyType = assertion.getValue();
180: } else if (PolicyUtil.isKeySize(assertion)) {
181: this .keySize = Integer.valueOf(assertion
182: .getValue());
183: } else if (PolicyUtil.isEncryption(assertion)) {
184: this .isEncRequired = true;
185: } else if (PolicyUtil.isProofEncryption(assertion)) {
186: this .isProofEncRequired = true;
187: } else if (PolicyUtil.isLifeTime(assertion)) {
188: this .lifeTime = (Lifetime) assertion;
189: } else if (PolicyUtil.isSignWith(assertion)) {
190: this .signWith = assertion.getValue();
191: } else if (PolicyUtil.isTrustTokenType(assertion)) {
192: this .tokenType = assertion.getValue();
193: } else if (PolicyUtil.isRequestType(assertion)) {
194: this .tokenType = assertion.getValue();
195: } else if (PolicyUtil
196: .isAuthenticationType(assertion)) {
197: this .tokenType = assertion.getValue();
198: } else if (PolicyUtil
199: .isSignatureAlgorithm(assertion)) {
200: this .tokenType = assertion.getValue();
201: } else if (PolicyUtil
202: .isEncryptionAlgorithm(assertion)) {
203: this .tokenType = assertion.getValue();
204: } else if (PolicyUtil
205: .isCanonicalizationAlgorithm(assertion)) {
206: this .tokenType = assertion.getValue();
207: } else if (PolicyUtil
208: .isComputedKeyAlgorithm(assertion)) {
209: this .tokenType = assertion.getValue();
210: } else if (PolicyUtil.isProofEncryption(assertion)) {
211: isProofEncRequired = true;
212: } else if (PolicyUtil.isEncryption(assertion)) {
213: isEncRequired = true;
214: } else if (PolicyUtil.isClaimsElement(assertion)) {
215: // Valid assertion.
216: } else if (PolicyUtil.isEntropyElement(assertion)) {
217: // Valid assertion.
218: } else {
219: if (!assertion.isOptional()) {
220: log_invalid_assertion(assertion, isServer,
221: RequestSecurityTokenTemplate);
222: fitness = AssertionFitness.HAS_UNKNOWN_ASSERTION;
223: }
224: }
225:
226: }
227: }
228: populated = true;
229: }
230: return fitness;
231: }
232: }
|