This project has retired. For details please refer to its
Attic page.
AuthHandler xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.server.impl.webservices;
2021import java.util.HashMap;
22import java.util.Map;
23import java.util.Set;
2425import javax.xml.bind.JAXBElement;
26import javax.xml.namespace.QName;
27import javax.xml.ws.handler.MessageContext;
28import javax.xml.ws.handler.MessageContext.Scope;
2930import com.sun.xml.ws.api.handler.MessageHandler;
31import com.sun.xml.ws.api.handler.MessageHandlerContext;
32import com.sun.xml.ws.api.message.Header;
33import com.sun.xml.ws.api.message.HeaderList;
34import com.sun.xml.ws.api.message.Message;
3536/**37 * This class tries to extract a user name and a password from a UsernameToken.38 */39publicclassAuthHandlerextendsAbstractUsernameTokenAuthHandler implements MessageHandler<MessageHandlerContext> {
4041public Set<QName> getHeaders() {
42return HEADERS;
43 }
4445publicvoid close(MessageContext context) {
46 }
4748publicboolean handleFault(MessageHandlerContext context) {
49returntrue;
50 }
5152publicboolean handleMessage(MessageHandlerContext context) {
53 Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
54if (outboundProperty.booleanValue()) {
55// we are only looking at inbound messages56returntrue;
57 }
5859 Map<String, String> callContextMap = null;
6061try {
62// read the header63 Message msg = context.getMessage();
64 HeaderList hl = msg.getHeaders();
65 Header securityHeader = hl.get(WSSE_SECURITY, true);
6667 JAXBElement<SecurityHeaderType> sht = securityHeader.readAsJAXB(WSSE_CONTEXT.createUnmarshaller());
6869 callContextMap = extractUsernamePassword(sht);
70 } catch (Exception e) {
71// something went wrong, e.g. a part of the SOAP header wasn't set72 }
7374// add user and password to context75if (callContextMap == null) {
76 callContextMap = new HashMap<String, String>();
77 }
7879 context.put(AbstractService.CALL_CONTEXT_MAP, callContextMap);
80 context.setScope(AbstractService.CALL_CONTEXT_MAP, Scope.APPLICATION);
8182returntrue;
83 }
84 }