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