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: /*
038: * SecurityContextToken.java
039: */
040:
041: package com.sun.xml.ws.security.impl.policy;
042:
043: import com.sun.xml.ws.policy.AssertionSet;
044: import com.sun.xml.ws.policy.NestedPolicy;
045: import com.sun.xml.ws.policy.PolicyAssertion;
046: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
047: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
048: import java.util.Collection;
049: import java.util.Collections;
050: import java.util.HashSet;
051: import java.util.Iterator;
052: import java.util.List;
053: import java.util.Set;
054: import java.util.UUID;
055: import java.util.logging.Level;
056: import static com.sun.xml.ws.security.impl.policy.Constants.*;
057: import javax.xml.namespace.QName;
058:
059: /**
060: *
061: * @author Mayank.Mishra@Sun.com
062: */
063: public class SecurityContextToken extends PolicyAssertion implements
064: com.sun.xml.ws.security.policy.SecurityContextToken,
065: SecurityAssertionValidator {
066: private String id;
067: private List<String> tokenRefType;
068: private boolean populated = false;
069: private String tokenType;
070: private String includeTokenType = Token.INCLUDE_ALWAYS;
071: private PolicyAssertion rdKey = null;
072: private Set<String> referenceType = null;
073: private static QName itQname = new QName(
074: Constants.SECURITY_POLICY_NS, Constants.IncludeToken);
075: private AssertionFitness fitness = AssertionFitness.IS_VALID;
076:
077: /** Creates a new instance of SecurityContextToken */
078: public SecurityContextToken(AssertionData name,
079: Collection<PolicyAssertion> nestedAssertions,
080: AssertionSet nestedAlternative) {
081: super (name, nestedAssertions, nestedAlternative);
082: UUID id = UUID.randomUUID();
083: this .id = id.toString();
084: }
085:
086: public String getTokenType() {
087: populate();
088: return tokenType;
089: }
090:
091: public Iterator getTokenRefernceType() {
092: if (tokenRefType != null) {
093: return tokenRefType.iterator();
094: } else {
095: return Collections.emptyList().iterator();
096: }
097: }
098:
099: public boolean isRequireDerivedKeys() {
100: populate();
101: if (rdKey != null) {
102: return true;
103: }
104: return false;
105: }
106:
107: public String getIncludeToken() {
108: populate();
109: return includeTokenType;
110: }
111:
112: public String getTokenId() {
113: return id;
114: }
115:
116: public AssertionFitness validate(boolean isServer) {
117: return populate(isServer);
118: }
119:
120: private void populate() {
121: populate(false);
122: }
123:
124: private synchronized AssertionFitness populate(boolean isServer) {
125: if (!populated) {
126: NestedPolicy policy = this .getNestedPolicy();
127: if (this .getAttributeValue(itQname) != null) {
128: includeTokenType = this .getAttributeValue(itQname);
129: }
130: if (policy == null) {
131: if (logger.getLevel() == Level.FINE) {
132: logger.log(Level.FINE, "NestedPolicy is null");
133: }
134: populated = true;
135: return fitness;
136: }
137: AssertionSet as = policy.getAssertionSet();
138: Iterator<PolicyAssertion> paItr = as.iterator();
139:
140: while (paItr.hasNext()) {
141: PolicyAssertion assertion = paItr.next();
142: if (PolicyUtil.isSecurityContextTokenType(assertion)) {
143: tokenType = assertion.getName().getLocalPart()
144: .intern();
145: } else if (PolicyUtil.isRequireDerivedKeys(assertion)) {
146: rdKey = assertion;
147: } else if (PolicyUtil
148: .isRequireExternalUriReference(assertion)) {
149: if (referenceType == null) {
150: referenceType = new HashSet<String>();
151: }
152: referenceType.add(assertion.getName()
153: .getLocalPart().intern());
154: } else {
155: if (!assertion.isOptional()) {
156: if (logger.getLevel() == Level.SEVERE) {
157: logger
158: .log(
159: Level.SEVERE,
160: "SP0100.invalid.security.assertion",
161: new Object[] { assertion,
162: "SecurityContextToken" });
163: }
164: if (isServer) {
165: throw new UnsupportedPolicyAssertion(
166: "Policy assertion "
167: + assertion
168: + " is not supported under SecurityContextToken assertion");
169: }
170: }
171: }
172: }
173: populated = true;
174: }
175: return fitness;
176: }
177:
178: }
|