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.policyconv;
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.impl.policy.PolicyUtil;
044: import com.sun.xml.ws.security.policy.AsymmetricBinding;
045: import com.sun.xml.ws.security.policy.Issuer;
046: import com.sun.xml.ws.security.policy.SecureConversationToken;
047: import com.sun.xml.ws.security.policy.SupportingTokens;
048: import com.sun.xml.ws.security.policy.SymmetricBinding;
049: import com.sun.xml.ws.security.policy.Token;
050: import com.sun.xml.wss.impl.policy.mls.MessagePolicy;
051: import java.util.ArrayList;
052: import java.util.Collection;
053: import java.util.Collections;
054: import java.util.Iterator;
055: import java.util.List;
056: import java.util.Set;
057:
058: /**
059: *
060: * @author K.Venugopal@sun.com
061: */
062: public class SCTokenWrapper extends PolicyAssertion implements
063: SecureConversationToken {
064:
065: private SecureConversationToken scToken = null;
066: private MessagePolicy messagePolicy = null;
067: private List<PolicyAssertion> tokenList = null;
068: private boolean cached = false;
069:
070: /** Creates a new instance of SCTokenWrapper */
071: public SCTokenWrapper(PolicyAssertion scToken, MessagePolicy mp) {
072: super (AssertionData.createAssertionData(scToken.getName(),
073: scToken.getValue(), scToken.getAttributes()),
074: getNestedAssertions(scToken), (scToken
075: .getNestedPolicy() == null ? null : scToken
076: .getNestedPolicy().getAssertionSet()));
077: this .scToken = (SecureConversationToken) scToken;
078: this .messagePolicy = mp;
079: }
080:
081: private static Collection<PolicyAssertion> getNestedAssertions(
082: PolicyAssertion scToken) {
083: if (scToken.hasNestedAssertions()) {
084: Iterator<PolicyAssertion> itr = scToken
085: .getNestedAssertionsIterator();
086: if (itr.hasNext()) {// will have only one assertion set. TODO:Cross check with marek.
087: return Collections.singletonList(itr.next());
088: }
089: }
090: return null;
091:
092: }
093:
094: public SecureConversationToken getSecureConversationToken() {
095: return scToken;
096: }
097:
098: public void setSecureConversationToken(
099: SecureConversationToken scToken) {
100: this .scToken = scToken;
101: }
102:
103: public MessagePolicy getMessagePolicy() {
104: return messagePolicy;
105: }
106:
107: public void setMessagePolicyp(MessagePolicy mp) {
108: this .messagePolicy = mp;
109: }
110:
111: public boolean isRequireDerivedKeys() {
112: return this .scToken.isRequireDerivedKeys();
113: }
114:
115: public String getTokenType() {
116: return this .scToken.getTokenType();
117: }
118:
119: public Issuer getIssuer() {
120: return this .scToken.getIssuer();
121: }
122:
123: public NestedPolicy getBootstrapPolicy() {
124: return this .scToken.getBootstrapPolicy();
125: }
126:
127: public String getIncludeToken() {
128: return this .scToken.getIncludeToken();
129: }
130:
131: public String getTokenId() {
132: return this .scToken.getTokenId();
133: }
134:
135: public List<PolicyAssertion> getIssuedTokens() {
136: if (!cached) {
137: if (this .hasNestedPolicy()) {
138: tokenList = getTokens(this .getNestedPolicy());
139: cached = true;
140: }
141: }
142: return tokenList;
143: }
144:
145: private ArrayList<PolicyAssertion> getTokens(NestedPolicy policy) {
146: ArrayList<PolicyAssertion> tokenList = new ArrayList<PolicyAssertion>();
147: AssertionSet assertionSet = policy.getAssertionSet();
148: for (PolicyAssertion pa : assertionSet) {
149: if (PolicyUtil.isBootstrapPolicy(pa)) {
150: NestedPolicy np = pa.getNestedPolicy();
151: AssertionSet bpSet = np.getAssertionSet();
152: for (PolicyAssertion assertion : bpSet) {
153: if (PolicyUtil.isAsymmetricBinding(assertion)) {
154: AsymmetricBinding sb = (AsymmetricBinding) assertion;
155: addToken(sb.getInitiatorToken(), tokenList);
156: addToken(sb.getRecipientToken(), tokenList);
157: } else if (PolicyUtil.isSymmetricBinding(assertion)) {
158: SymmetricBinding sb = (SymmetricBinding) assertion;
159: Token token = sb.getProtectionToken();
160: if (token != null) {
161: addToken(token, tokenList);
162: } else {
163: addToken(sb.getEncryptionToken(), tokenList);
164: addToken(sb.getSignatureToken(), tokenList);
165: }
166: } else if (PolicyUtil.isSupportingTokens(assertion)) {
167: SupportingTokens st = (SupportingTokens) assertion;
168: Iterator itr = st.getTokens();
169: while (itr.hasNext()) {
170: addToken((Token) itr.next(), tokenList);
171: }
172: }
173: }
174: }
175:
176: }
177: return tokenList;
178: }
179:
180: private void addToken(Token token, ArrayList<PolicyAssertion> list) {
181: if (PolicyUtil.isIssuedToken((PolicyAssertion) token)) {
182: list.add((PolicyAssertion) token);
183: }
184: }
185:
186: public Set getTokenRefernceTypes() {
187: return this .scToken.getTokenRefernceTypes();
188: }
189:
190: public void addBootstrapPolicy(NestedPolicy policy) {
191: }
192: }
|