1
+ package org .javaee7 .jaspic .statuscodes .sam ;
2
+
3
+ import static javax .security .auth .message .AuthStatus .SEND_FAILURE ;
4
+ import static javax .security .auth .message .AuthStatus .SEND_SUCCESS ;
5
+ import static javax .servlet .http .HttpServletResponse .SC_NOT_FOUND ;
6
+
7
+ import java .io .IOException ;
8
+ import java .util .Map ;
9
+
10
+ import javax .security .auth .Subject ;
11
+ import javax .security .auth .callback .CallbackHandler ;
12
+ import javax .security .auth .message .AuthException ;
13
+ import javax .security .auth .message .AuthStatus ;
14
+ import javax .security .auth .message .MessageInfo ;
15
+ import javax .security .auth .message .MessagePolicy ;
16
+ import javax .security .auth .message .module .ServerAuthModule ;
17
+ import javax .servlet .http .HttpServletRequest ;
18
+ import javax .servlet .http .HttpServletResponse ;
19
+
20
+ /**
21
+ * Very basic SAM that just sets an HTTP status code into the response and then returns SEND_FAILURE.
22
+ * <code>doLogin</code> is present.
23
+ *
24
+ * @author Arjan Tijms
25
+ *
26
+ */
27
+ public class TestServerAuthModule implements ServerAuthModule {
28
+
29
+ private Class <?>[] supportedMessageTypes = new Class [] { HttpServletRequest .class , HttpServletResponse .class };
30
+
31
+ @ Override
32
+ public void initialize (MessagePolicy requestPolicy , MessagePolicy responsePolicy , CallbackHandler handler , @ SuppressWarnings ("rawtypes" ) Map options ) throws AuthException {
33
+ }
34
+
35
+ @ Override
36
+ public AuthStatus validateRequest (MessageInfo messageInfo , Subject clientSubject , Subject serviceSubject ) throws AuthException {
37
+
38
+ HttpServletResponse response = (HttpServletResponse ) messageInfo .getResponseMessage ();
39
+
40
+ try {
41
+ response .sendError (SC_NOT_FOUND );
42
+ return SEND_FAILURE ;
43
+ } catch (IOException e ) {
44
+ throw (AuthException ) new AuthException ().initCause (e );
45
+ }
46
+ }
47
+
48
+ @ Override
49
+ public Class <?>[] getSupportedMessageTypes () {
50
+ return supportedMessageTypes ;
51
+ }
52
+
53
+ @ Override
54
+ public AuthStatus secureResponse (MessageInfo messageInfo , Subject serviceSubject ) throws AuthException {
55
+ return SEND_SUCCESS ;
56
+ }
57
+
58
+ @ Override
59
+ public void cleanSubject (MessageInfo messageInfo , Subject subject ) throws AuthException {
60
+
61
+ }
62
+ }
0 commit comments