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