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.security.policy.SecurityAssertionValidator;
043: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
044: import java.util.Collection;
045: import java.util.Collections;
046: import java.util.HashSet;
047: import java.util.Set;
048: import java.util.logging.Level;
049: import java.util.Iterator;
050: import java.util.Map;
051: import java.util.UUID;
052: import javax.xml.namespace.QName;
053: import static com.sun.xml.ws.security.impl.policy.Constants.*;
054:
055: /**
056: *
057: * @author K.Venugopal@sun.com
058: */
059:
060: public class SecureConversationToken extends PolicyAssertion implements
061: com.sun.xml.ws.security.policy.SecureConversationToken,
062: SecurityAssertionValidator {
063: private static QName itQname = new QName(
064: Constants.SECURITY_POLICY_NS, Constants.IncludeToken);
065: private NestedPolicy bootstrapPolicy = null;
066: private String id = null;
067: protected String includeToken = Token.INCLUDE_ALWAYS;
068: private boolean populated = false;
069: private PolicyAssertion rdKey = null;
070: private Set<String> referenceType = null;
071: private Issuer issuer = null;
072: private String tokenType = null;
073: private AssertionFitness fitness = AssertionFitness.IS_VALID;
074:
075: /**
076: * Creates a new instance of SecureConversationToken
077: */
078: public SecureConversationToken() {
079: UUID uid = UUID.randomUUID();
080: id = uid.toString();
081: }
082:
083: public SecureConversationToken(AssertionData name,
084: Collection<PolicyAssertion> nestedAssertions,
085: AssertionSet nestedAlternative) {
086: super (name, nestedAssertions, nestedAlternative);
087: UUID uid = UUID.randomUUID();
088: id = uid.toString();
089: }
090:
091: public Set getTokenRefernceTypes() {
092: populate();
093: if (referenceType == null) {
094: return Collections.emptySet();
095: }
096: return referenceType;
097: }
098:
099: public boolean isRequireDerivedKeys() {
100: populate();
101: if (rdKey != null) {
102: return true;
103: }
104: return false;
105: }
106:
107: public String getTokenType() {
108: populate();
109: return this .tokenType;
110: }
111:
112: public Issuer getIssuer() {
113: populate();
114: return issuer;
115: }
116:
117: public String getIncludeToken() {
118: populate();
119: return includeToken;
120: }
121:
122: public void setIncludeToken(String type) {
123: Map<QName, String> attrs = this .getAttributes();
124: QName itQname = new QName(Constants.SECURITY_POLICY_NS,
125: Constants.IncludeToken);
126: attrs.put(itQname, type);
127: }
128:
129: public NestedPolicy getBootstrapPolicy() {
130: populate();
131: return bootstrapPolicy;
132: }
133:
134: public String getTokenId() {
135: return id;
136: }
137:
138: public AssertionFitness validate(boolean isServer) {
139: return populate(isServer);
140: }
141:
142: private void populate() {
143: populate(false);
144: }
145:
146: private synchronized AssertionFitness populate(boolean isServer) {
147: if (!populated) {
148: String tmp = getAttributeValue(itQname);
149: if (tmp != null)
150: includeToken = tmp;
151: NestedPolicy policy = this .getNestedPolicy();
152: if (policy == null) {
153: if (logger.getLevel() == Level.FINE) {
154: logger.log(Level.FINE, "NestedPolicy is null");
155: }
156: populated = true;
157: return fitness;
158: }
159: AssertionSet as = policy.getAssertionSet();
160: Iterator<PolicyAssertion> paItr = as.iterator();
161: while (paItr.hasNext()) {
162: PolicyAssertion assertion = paItr.next();
163: if (PolicyUtil.isBootstrapPolicy(assertion)) {
164: bootstrapPolicy = assertion.getNestedPolicy();
165: } else if (PolicyUtil.isRequireDerivedKeys(assertion)) {
166: rdKey = assertion;
167: } else if (PolicyUtil
168: .isRequireExternalUriReference(assertion)) {
169: if (referenceType == null) {
170: referenceType = new HashSet<String>();
171: }
172: referenceType.add(assertion.getName()
173: .getLocalPart().intern());
174: } else if (PolicyUtil
175: .isSC10SecurityContextToken(assertion)) {
176: tokenType = assertion.getName().getLocalPart();
177: } else {
178: if (!assertion.isOptional()) {
179: log_invalid_assertion(assertion, isServer,
180: SecureConversationToken);
181: fitness = AssertionFitness.HAS_UNKNOWN_ASSERTION;
182: }
183:
184: }
185: }
186: if (this .hasNestedAssertions()) {
187: Iterator<PolicyAssertion> it = this
188: .getNestedAssertionsIterator();
189: while (it.hasNext()) {
190: PolicyAssertion assertion = it.next();
191: if (PolicyUtil.isIssuer(assertion)) {
192: issuer = (Issuer) assertion;
193: }
194: }
195: }
196: populated = true;
197: }
198: return fitness;
199: }
200: }
|