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: * X509Token.java
039: *
040: * Created on January 5, 2006, 3:53 PM
041: *
042: * To change this template, choose Tools | Template Manager
043: * and open the template in the editor.
044: */
045:
046: package com.sun.xml.ws.security.impl.policy;
047:
048: import com.sun.xml.ws.policy.AssertionSet;
049: import com.sun.xml.ws.policy.NestedPolicy;
050: import com.sun.xml.ws.policy.PolicyAssertion;
051: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
052: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
053: import java.util.Collection;
054: import java.util.HashSet;
055: import java.util.Set;
056: import java.util.UUID;
057: import java.util.logging.Level;
058: import static com.sun.xml.ws.security.impl.policy.Constants.*;
059: import javax.xml.namespace.QName;
060:
061: /**
062: *
063: * @author K.Venugopal@sun.com Abhijit.Das@Sun.Com
064: */
065:
066: public class X509Token extends PolicyAssertion implements
067: com.sun.xml.ws.security.policy.X509Token, Cloneable,
068: SecurityAssertionValidator {
069:
070: private static QName itQname = new QName(
071: Constants.SECURITY_POLICY_NS, Constants.IncludeToken);
072: private String includeToken = Token.INCLUDE_ALWAYS;
073: private AssertionFitness fitness = AssertionFitness.IS_VALID;
074: private boolean populated = false;
075: private String tokenType = null;
076: private HashSet<String> referenceType = null;
077:
078: /**
079: * Creates a new instance of X509Token
080: */
081: private String id = null;
082: private boolean reqDK = false;
083:
084: private boolean isServer = false;
085:
086: public X509Token() {
087: UUID uid = UUID.randomUUID();
088: id = uid.toString();
089: referenceType = new HashSet<String>();
090: }
091:
092: public X509Token(AssertionData name,
093: Collection<PolicyAssertion> nestedAssertions,
094: AssertionSet nestedAlternative) {
095: super (name, nestedAssertions, nestedAlternative);
096:
097: UUID uid = UUID.randomUUID();
098: id = uid.toString();
099: referenceType = new HashSet<String>();
100: }
101:
102: public void addTokenReferenceType(String tokenRefType) {
103: referenceType.add(tokenRefType);
104: }
105:
106: public void setTokenType(String tokenType) {
107: this .tokenType = tokenType;
108: }
109:
110: public String getTokenType() {
111: populate();
112: return tokenType;
113: }
114:
115: public Set getTokenRefernceType() {
116: populate();
117: return referenceType;
118: }
119:
120: public String getIncludeToken() {
121: populate();
122: return includeToken;
123: }
124:
125: public void setIncludeToken(String type) {
126: includeToken = type;
127: }
128:
129: public String getTokenId() {
130: return id;
131: }
132:
133: public boolean isRequireDerivedKeys() {
134: populate();
135: return reqDK;
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: if (this .getAttributeValue(itQname) != null) {
149: this .includeToken = this .getAttributeValue(itQname);
150: }
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 assertionSet = policy.getAssertionSet();
160: for (PolicyAssertion assertion : assertionSet) {
161: if (PolicyUtil.isTokenReferenceType(assertion)) {
162: referenceType.add(assertion.getName()
163: .getLocalPart().intern());
164: } else if (PolicyUtil.isTokenType(assertion)) {
165: tokenType = assertion.getName().getLocalPart();
166: } else if (PolicyUtil.isRequireDerivedKeys(assertion)) {
167: reqDK = true;
168: } else {
169: if (!assertion.isOptional()) {
170: log_invalid_assertion(assertion, isServer,
171: "X509Token");
172: fitness = AssertionFitness.HAS_UNKNOWN_ASSERTION;
173: }
174: }
175: }
176:
177: populated = true;
178: }
179: return fitness;
180: }
181:
182: public Object clone() throws CloneNotSupportedException {
183: throw new UnsupportedOperationException("Fix me");
184: //return new X509Token(this.nestedPolicy,getAttributes(),id);
185: }
186: }
|