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: * KerberosToken.java
038: *
039: * Created on April 19, 2006, 3:17 PM
040: *
041: * To change this template, choose Tools | Template Manager
042: * and open the template in the editor.
043: */
044:
045: package com.sun.xml.ws.security.impl.policy;
046:
047: import com.sun.xml.ws.policy.AssertionSet;
048: import com.sun.xml.ws.policy.NestedPolicy;
049: import com.sun.xml.ws.policy.PolicyAssertion;
050: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
051: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
052: import java.util.ArrayList;
053: import java.util.Collection;
054: import java.util.Collections;
055: import java.util.Iterator;
056: import java.util.List;
057: import java.util.UUID;
058: import java.util.logging.Level;
059: import javax.xml.namespace.QName;
060: import static com.sun.xml.ws.security.impl.policy.Constants.*;
061:
062: /**
063: *
064: * @author mayank.mishra@Sun.com
065: */
066: public class KerberosToken extends PolicyAssertion implements
067: com.sun.xml.ws.security.policy.KerberosToken,
068: SecurityAssertionValidator {
069: private AssertionFitness fitness = AssertionFitness.IS_VALID;
070: private String id;
071: private List<String> tokenRefType;
072: private boolean populated = false;
073: private QName itQname;
074: private String includeTokenType;
075: private PolicyAssertion rdKey = null;
076: private String tokenType;
077: private boolean isServer = false;
078:
079: /** Creates a new instance of KerberosToken */
080: public KerberosToken(AssertionData name,
081: Collection<PolicyAssertion> nestedAssertions,
082: AssertionSet nestedAlternative) {
083: super (name, nestedAssertions, nestedAlternative);
084: UUID id = UUID.randomUUID();
085: this .id = id.toString();
086: }
087:
088: public String getTokenType() {
089: populate();
090: return tokenType;
091: }
092:
093: public Iterator getTokenRefernceType() {
094: if (tokenRefType != null) {
095: return tokenRefType.iterator();
096: } else {
097: return Collections.emptyList().iterator();
098: }
099: }
100:
101: public boolean isRequireDerivedKeys() {
102: populate();
103: if (rdKey != null) {
104: return true;
105: }
106: return false;
107: }
108:
109: public String getIncludeToken() {
110: populate();
111: return includeTokenType;
112: }
113:
114: public String getTokenId() {
115: return id;
116: }
117:
118: public AssertionFitness validate(boolean isServer) {
119: return populate(isServer);
120: }
121:
122: private void populate() {
123: populate(false);
124: }
125:
126: private synchronized AssertionFitness populate(boolean isServer) {
127: if (!populated) {
128: NestedPolicy policy = this .getNestedPolicy();
129: includeTokenType = this .getAttributeValue(itQname);
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.isKerberosTokenType(assertion)) {
143: tokenType = assertion.getName().getLocalPart()
144: .intern();
145: } else if (PolicyUtil.isRequireDerivedKeys(assertion)) {
146: rdKey = assertion;
147: } else if (PolicyUtil.isRequireKeyIR(assertion)) {
148: if (tokenRefType == null) {
149: tokenRefType = new ArrayList<String>();
150: }
151: tokenRefType.add(assertion.getName().getLocalPart()
152: .intern());
153: } else {
154: if (!assertion.isOptional()) {
155: log_invalid_assertion(assertion, isServer,
156: KerberosToken);
157: fitness = AssertionFitness.HAS_UNKNOWN_ASSERTION;
158: }
159: }
160: }
161: populated = true;
162: }
163: return fitness;
164: }
165:
166: }
|