001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.security.wss4j;
019:
020: import java.net.URI;
021: import java.util.HashMap;
022: import java.util.HashSet;
023: import java.util.Map;
024: import java.util.Set;
025:
026: import javax.xml.namespace.QName;
027:
028: import org.apache.cxf.binding.soap.SoapMessage;
029: import org.apache.cxf.binding.soap.interceptor.SoapInterceptor;
030: import org.apache.cxf.interceptor.Fault;
031: import org.apache.cxf.message.Message;
032: import org.apache.cxf.phase.PhaseInterceptor;
033: import org.apache.ws.security.WSConstants;
034: import org.apache.ws.security.handler.WSHandler;
035:
036: public abstract class AbstractWSS4JInterceptor extends WSHandler
037: implements SoapInterceptor, PhaseInterceptor<SoapMessage> {
038:
039: private static final Set<QName> HEADERS = new HashSet<QName>();
040: static {
041: HEADERS.add(new QName(WSConstants.WSSE_NS, "Security"));
042: HEADERS.add(new QName(WSConstants.WSSE11_NS, "Security"));
043: HEADERS.add(new QName(WSConstants.ENC_NS, "EncryptedData"));
044: }
045:
046: private Map<String, Object> properties = new HashMap<String, Object>();
047: private Set<String> before = new HashSet<String>();
048: private Set<String> after = new HashSet<String>();
049: private String phase;
050: private String id;
051:
052: public AbstractWSS4JInterceptor() {
053: super ();
054: id = getClass().getName();
055: }
056:
057: public Set<URI> getRoles() {
058: return null;
059: }
060:
061: public void handleFault(SoapMessage message) {
062: }
063:
064: public void postHandleMessage(SoapMessage message) throws Fault {
065: }
066:
067: public String getPhase() {
068: return phase;
069: }
070:
071: public void setPhase(String phase) {
072: this .phase = phase;
073: }
074:
075: public Object getOption(String key) {
076: return properties.get(key);
077: }
078:
079: public void setProperty(String key, String value) {
080: properties.put(key, value);
081: }
082:
083: public String getPassword(Object msgContext) {
084: return (String) ((Message) msgContext)
085: .getContextualProperty("password");
086: }
087:
088: public Object getProperty(Object msgContext, String key) {
089: Object obj = ((Message) msgContext).getContextualProperty(key);
090: if (obj == null) {
091: obj = getOption(key);
092: }
093: return obj;
094: }
095:
096: public void setPassword(Object msgContext, String password) {
097: ((Message) msgContext).put("password", password);
098: }
099:
100: public void setProperty(Object msgContext, String key, Object value) {
101: ((Message) msgContext).put(key, value);
102: }
103:
104: public String getId() {
105: return id;
106: }
107:
108: public void setId(String id) {
109: this .id = id;
110: }
111:
112: public Set<QName> getUnderstoodHeaders() {
113: return HEADERS;
114: }
115:
116: public Map getProperties() {
117: return properties;
118: }
119:
120: public void setProperties(Map<String, Object> properties) {
121: this .properties = properties;
122: }
123:
124: public Set<String> getAfter() {
125: return after;
126: }
127:
128: public void setAfter(Set<String> after) {
129: this .after = after;
130: }
131:
132: public Set<String> getBefore() {
133: return before;
134: }
135:
136: public void setBefore(Set<String> before) {
137: this.before = before;
138: }
139: }
|