15
15
import er .rest .routes .ERXRouteController ;
16
16
17
17
public class BaseRestController extends ERXRouteController {
18
-
19
- private Person authenticatedUser ;
20
18
21
19
public BaseRestController (WORequest request ) {
22
20
super (request );
@@ -39,62 +37,9 @@ protected ERXRestFormat defaultFormat() {
39
37
protected boolean isAutomaticHtmlRoutingEnabled () {
40
38
return true ;
41
39
}
42
-
43
- protected void initAuthentication () throws NotAuthorizedException {
44
- String authValue = request ().headerForKey ( "authorization" );
45
-
46
- if ( authValue != null ) {
47
- try {
48
- byte [] authBytes = new BASE64Decoder ().decodeBuffer ( authValue .replace ( "Basic " , "" ) );
49
- String [] parts = new String ( authBytes ).split ( ":" , 2 );
50
- String username = parts [0 ];
51
- String password = parts [1 ];
52
- setAuthenticatedUser (Person .validateLogin (editingContext (), username , password ));
53
- } catch ( IOException e ) {
54
- log .error ( "Could not decode basic auth data: " + e .getMessage () );
55
- e .printStackTrace ();
56
- }
57
- } else {
58
- throw new NotAuthorizedException ();
59
- }
60
- }
61
-
62
- protected Person authenticatedUser () {
63
- return authenticatedUser ;
64
- }
65
-
66
- @ Override
67
- public WOActionResults performActionNamed (String actionName , boolean throwExceptions ) {
68
- if (!isHTMlFormat ()) {
69
- try {
70
- initAuthentication ();
71
- } catch (NoSuchElementException ex ) {
72
- WOResponse response = (WOResponse )errorResponse (ERXHttpStatusCodes .UNAUTHORIZED );
73
- response .setHeader ("Basic realm=\" Members\" " , "WWW-Authenticate" );
74
- return response ;
75
- } catch (NotAuthorizedException ex ) {
76
- WOResponse response = (WOResponse )errorResponse (ERXHttpStatusCodes .UNAUTHORIZED );
77
- response .setHeader ("Basic realm=\" Members\" " , "WWW-Authenticate" );
78
- return response ;
79
- }
80
- }
81
- return super .performActionNamed (actionName , throwExceptions );
82
- }
83
-
84
- protected void setAuthenticatedUser (Person authenticatedUser ) {
85
- this .authenticatedUser = authenticatedUser ;
86
- }
87
40
88
41
protected boolean isHTMlFormat () {
89
42
return (ERXRestFormat .html ().name ().equals (this .format ().name ())) ? true : false ;
90
43
}
91
-
92
- public class NotAuthorizedException extends Exception {
93
-
94
- public NotAuthorizedException () {
95
- super ();
96
- }
97
-
98
- }
99
44
100
45
}
0 commit comments