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.AlgorithmSuite;
044: import com.sun.xml.ws.security.policy.Token;
045: import java.util.ArrayList;
046: import java.util.Collection;
047: import java.util.Collections;
048: import java.util.Iterator;
049: import java.util.List;
050: import java.util.logging.Level;
051: import static com.sun.xml.ws.security.impl.policy.Constants.*;
052:
053: /**
054: *
055: * @author K.Venugopal@sun.com
056: */
057: public class SupportingTokens extends PolicyAssertion implements
058: com.sun.xml.ws.security.policy.SupportingTokens {
059:
060: private AlgorithmSuite algSuite;
061: private List<com.sun.xml.ws.security.policy.SignedParts> spList = new ArrayList<com.sun.xml.ws.security.policy.SignedParts>(
062: 1);
063: private List<com.sun.xml.ws.security.policy.EncryptedParts> epList = new ArrayList<com.sun.xml.ws.security.policy.EncryptedParts>(
064: 1);
065: private List<com.sun.xml.ws.security.policy.SignedElements> seList = new ArrayList<com.sun.xml.ws.security.policy.SignedElements>(
066: 1);
067: private List<com.sun.xml.ws.security.policy.EncryptedElements> eeList = new ArrayList<com.sun.xml.ws.security.policy.EncryptedElements>(
068: 1);;
069: private boolean isServer = false;
070: private List<Token> _tokenList;
071: private boolean populated;
072:
073: /**
074: * Creates a new instance of SupportingTokens
075: */
076: public SupportingTokens() {
077: }
078:
079: public SupportingTokens(AssertionData name,
080: Collection<PolicyAssertion> nestedAssertions,
081: AssertionSet nestedAlternative) {
082: super (name, nestedAssertions, nestedAlternative);
083:
084: }
085:
086: public void setAlgorithmSuite(AlgorithmSuite algSuite) {
087: this .algSuite = algSuite;
088: }
089:
090: public AlgorithmSuite getAlgorithmSuite() {
091: populate();
092: return algSuite;
093: }
094:
095: public void addToken(Token token) {
096: if (_tokenList == null) {
097: _tokenList = new ArrayList<Token>();
098: //Workaround - workaround to remove duplicate UsernameToken : uncomment this
099: //_tokenList.add(token);
100: }
101: //Workaround - comment
102: _tokenList.add(token);
103: }
104:
105: public Iterator getTokens() {
106: populate();
107: if (_tokenList != null) {
108: return _tokenList.iterator();
109: }
110: return Collections.emptyList().iterator();
111: }
112:
113: private synchronized void populate() {
114:
115: if (!populated) {
116: NestedPolicy policy = this .getNestedPolicy();
117: if (policy == null) {
118: if (logger.getLevel() == Level.FINE) {
119: logger.log(Level.FINE, "NestedPolicy is null");
120: }
121: populated = true;
122: return;
123: }
124: AssertionSet as = policy.getAssertionSet();
125: Iterator<PolicyAssertion> ast = as.iterator();
126: while (ast.hasNext()) {
127: PolicyAssertion assertion = ast.next();
128: if (PolicyUtil.isAlgorithmAssertion(assertion)) {
129: this .algSuite = (AlgorithmSuite) assertion;
130: } else if (PolicyUtil.isToken(assertion)) {
131: addToken((Token) assertion);
132: //this._tokenList.add((Token)assertion);
133: } else if (PolicyUtil.isSignedParts(assertion)) {
134: spList.add((SignedParts) assertion);
135: } else if (PolicyUtil.isSignedElements(assertion)) {
136: seList.add((SignedElements) assertion);
137: } else if (PolicyUtil.isEncryptParts(assertion)) {
138: epList.add((EncryptedParts) assertion);
139: } else if (PolicyUtil.isEncryptedElements(assertion)) {
140: eeList.add((EncryptedElements) assertion);
141: } else {
142: if (!assertion.isOptional()) {
143: if (logger.getLevel() == Level.SEVERE) {
144: logger
145: .log(
146: Level.SEVERE,
147: "SP0100.invalid.security.assertion",
148: new Object[] { assertion,
149: "SupportingTokens" });
150: }
151: if (isServer) {
152: throw new UnsupportedPolicyAssertion(
153: "Policy assertion "
154: + assertion
155: + " is not supported under SupportingTokens assertion");
156: }
157: }
158: }
159: }
160: populated = true;
161: }
162: }
163:
164: public String getIncludeToken() {
165: return "";
166: }
167:
168: public void setIncludeToken(String type) {
169: }
170:
171: public String getTokenId() {
172: return "";
173: }
174:
175: public Iterator<com.sun.xml.ws.security.policy.SignedParts> getSignedParts() {
176: populate();
177: return spList.iterator();
178: }
179:
180: public Iterator<com.sun.xml.ws.security.policy.SignedElements> getSignedElements() {
181: populate();
182: return seList.iterator();
183: }
184:
185: public Iterator<com.sun.xml.ws.security.policy.EncryptedParts> getEncryptedParts() {
186: populate();
187: return epList.iterator();
188: }
189:
190: public Iterator<com.sun.xml.ws.security.policy.EncryptedElements> getEncryptedElements() {
191: populate();
192: return eeList.iterator();
193: }
194:
195: }
|