1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.server.impl.webservices;
20
21 import com.sun.xml.ws.api.handler.MessageHandler;
22 import com.sun.xml.ws.api.handler.MessageHandlerContext;
23 import com.sun.xml.ws.api.message.Header;
24 import com.sun.xml.ws.api.message.HeaderList;
25 import com.sun.xml.ws.api.message.Message;
26
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.Set;
30
31 import javax.xml.bind.JAXBElement;
32 import javax.xml.namespace.QName;
33 import javax.xml.ws.handler.MessageContext;
34 import javax.xml.ws.handler.MessageContext.Scope;
35
36
37
38
39
40 public class AuthHandler extends AbstractUsernameTokenAuthHandler implements MessageHandler<MessageHandlerContext>
41 {
42 public Set<QName> getHeaders( )
43 {
44 return HEADERS;
45 }
46
47 public void close( MessageContext context )
48 {
49 }
50
51 public boolean handleFault( MessageHandlerContext context )
52 {
53 return true;
54 }
55
56 public boolean handleMessage( MessageHandlerContext context )
57 {
58 Boolean outboundProperty = (Boolean) context.get( MessageContext.MESSAGE_OUTBOUND_PROPERTY );
59
60 if ( outboundProperty.booleanValue( ) )
61 {
62
63 return true;
64 }
65
66 Map<String, String> callContextMap = null;
67
68 try
69 {
70
71 Message msg = context.getMessage( );
72 HeaderList hl = msg.getHeaders( );
73 Header securityHeader = hl.get( WSSE_SECURITY, true );
74
75 JAXBElement<SecurityHeaderType> sht = securityHeader.readAsJAXB( WSSE_CONTEXT.createUnmarshaller( ) );
76
77 callContextMap = extractUsernamePassword( sht );
78 }
79 catch ( Exception e )
80 {
81
82 }
83
84
85 if ( callContextMap == null )
86 {
87 callContextMap = new HashMap<String, String>( );
88 }
89
90 context.put( AbstractService.CALL_CONTEXT_MAP, callContextMap );
91 context.setScope( AbstractService.CALL_CONTEXT_MAP, Scope.APPLICATION );
92
93 return true;
94 }
95 }