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: * EncryptedElements.java
039: *
040: * Created on February 15, 2006, 3:44 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.PolicyAssertion;
050: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
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.logging.Level;
057: import javax.xml.namespace.QName;
058: import static com.sun.xml.ws.security.impl.policy.Constants.*;
059: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
060:
061: /**
062: *
063: * @author Abhijit Das
064: */
065: public class EncryptedElements extends PolicyAssertion implements
066: com.sun.xml.ws.security.policy.EncryptedElements,
067: SecurityAssertionValidator {
068:
069: private String xpathVersion;
070: private ArrayList<String> targetList;
071: private static List<String> emptyList = Collections.emptyList();
072: private boolean populated = false;
073: private static QName XPathVersion = new QName("XPathVersion");
074: private AssertionFitness fitness = AssertionFitness.IS_VALID;
075:
076: /**
077: * Creates a new instance of EncryptedElements
078: */
079: public EncryptedElements() {
080: }
081:
082: public EncryptedElements(AssertionData name,
083: Collection<PolicyAssertion> nestedAssertions,
084: AssertionSet nestedAlternative) {
085: super (name, nestedAssertions, nestedAlternative);
086: }
087:
088: public String getXPathVersion() {
089: return xpathVersion;
090: }
091:
092: public void setXPathVersion(String version) {
093: this .xpathVersion = version;
094: }
095:
096: public void addTarget(String target) {
097: if (targetList == null) {
098: targetList = new ArrayList<String>();
099: }
100: targetList.add(target);
101: }
102:
103: public void removeTarget(String target) {
104: if (targetList != null) {
105: targetList.remove(target);
106: }
107: }
108:
109: public Iterator<String> getTargets() {
110: populate();
111: if (targetList != null) {
112: return targetList.iterator();
113: }
114: return emptyList.iterator();
115: }
116:
117: public AssertionFitness validate(boolean isServer) {
118: return populate(isServer);
119: }
120:
121: private void populate() {
122: populate(false);
123: }
124:
125: private synchronized AssertionFitness populate(boolean isServer) {
126: if (!populated) {
127: this .xpathVersion = (String) this
128: .getAttributeValue(XPathVersion);
129: if (this .hasNestedAssertions()) {
130: Iterator<PolicyAssertion> it = this
131: .getNestedAssertionsIterator();
132: if (it.hasNext()) {
133: PolicyAssertion assertion = it.next();
134: if (PolicyUtil.isXPath(assertion)) {
135: addTarget(assertion.getValue());
136: } else {
137: if (!assertion.isOptional()) {
138: log_invalid_assertion(assertion, isServer,
139: EncryptedElements);
140: fitness = AssertionFitness.HAS_UNKNOWN_ASSERTION;
141: }
142: }
143: }
144: }
145: populated = true;
146: }
147: return fitness;
148: }
149:
150: }
|