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 java.io.StringReader;
22
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27
28 import javax.xml.bind.JAXBElement;
29 import javax.xml.bind.Unmarshaller;
30 import javax.xml.namespace.QName;
31 import javax.xml.ws.handler.MessageContext;
32 import javax.xml.ws.handler.MessageContext.Scope;
33 import javax.xml.ws.handler.soap.SOAPHandler;
34 import javax.xml.ws.handler.soap.SOAPMessageContext;
35
36
37 public class WebSphereAuthHandler extends AbstractUsernameTokenAuthHandler implements SOAPHandler<SOAPMessageContext>
38 {
39 public Set<QName> getHeaders( )
40 {
41 return HEADERS;
42 }
43
44 public void close( MessageContext context )
45 {
46 }
47
48 public boolean handleFault( SOAPMessageContext context )
49 {
50 return true;
51 }
52
53 @SuppressWarnings( "unchecked" )
54 public boolean handleMessage( SOAPMessageContext context )
55 {
56 Boolean outboundProperty = (Boolean) context.get( MessageContext.MESSAGE_OUTBOUND_PROPERTY );
57
58 if ( outboundProperty.booleanValue( ) )
59 {
60
61 return true;
62 }
63
64 Map<String, String> callContextMap = null;
65
66 Map<QName, List<String>> requestHeaders = (Map<QName, List<String>>) context.get(
67 "jaxws.binding.soap.headers.inbound" );
68
69 if ( requestHeaders != null )
70 {
71 List<String> secHeaders = requestHeaders.get( WSSE_SECURITY );
72
73 if ( ( secHeaders != null ) && ( secHeaders.size( ) > 0 ) )
74 {
75 try
76 {
77 Unmarshaller unmarshaller = WSSE_CONTEXT.createUnmarshaller( );
78
79 for ( String h : secHeaders )
80 {
81 try
82 {
83 JAXBElement<SecurityHeaderType> sht = (JAXBElement<SecurityHeaderType>) unmarshaller.unmarshal( new StringReader(
84 h ) );
85
86 callContextMap = extractUsernamePassword( sht );
87
88 if ( callContextMap != null )
89 {
90 break;
91 }
92 }
93 catch ( Exception e )
94 {
95
96
97 }
98 }
99 }
100 catch ( Exception e )
101 {
102
103 }
104 }
105 }
106
107
108 if ( callContextMap == null )
109 {
110 callContextMap = new HashMap<String, String>( );
111 }
112
113 context.put( AbstractService.CALL_CONTEXT_MAP, callContextMap );
114 context.setScope( AbstractService.CALL_CONTEXT_MAP, Scope.APPLICATION );
115
116 return true;
117 }
118 }