Mercurial > hg > digilib-old
comparison servlet/src/digilib/auth/AuthOpsImpl.java @ 73:3b8797fc3e90
New servlet version 1.5b.
Mostly cleanup. Global parameters for digilib now in DigilibConfiguration,
per request parameters are now all in DigilibRequest. The DocuImage implementation
can be selected by the configuration docuimage-class.
Pixel-by-pixel view implemented with "mo=clip".
author | robcast |
---|---|
date | Fri, 24 Jan 2003 21:40:59 +0100 |
parents | 0ff3ede32060 |
children | afe7ff98bb71 |
comparison
equal
deleted
inserted
replaced
72:300d5ba8b33b | 73:3b8797fc3e90 |
---|---|
22 | 22 |
23 import javax.servlet.http.HttpServletRequest; | 23 import javax.servlet.http.HttpServletRequest; |
24 import java.util.*; | 24 import java.util.*; |
25 | 25 |
26 import digilib.*; | 26 import digilib.*; |
27 import digilib.servlet.DigilibRequest; | |
27 | 28 |
29 /** Basic implementation of AuthOps interface. | |
30 * | |
31 * Provides basic implementations. Only rolesForPath needs to be implemented | |
32 * by specific implementations. | |
33 */ | |
28 public abstract class AuthOpsImpl implements AuthOps { | 34 public abstract class AuthOpsImpl implements AuthOps { |
29 | 35 |
36 /** Local utils object. */ | |
30 protected Utils util; | 37 protected Utils util; |
31 | 38 |
39 /** Default constructor. */ | |
32 public AuthOpsImpl() { | 40 public AuthOpsImpl() { |
33 util = new Utils(); | 41 util = new Utils(); |
34 try { | 42 try { |
35 init(); | 43 init(); |
36 } catch (AuthOpException e) { | 44 } catch (AuthOpException e) { |
37 } | 45 } |
38 } | 46 } |
39 | 47 |
48 /** Constructor taking an utils object. | |
49 * @param u utils object. | |
50 */ | |
40 public AuthOpsImpl(Utils u) { | 51 public AuthOpsImpl(Utils u) { |
41 util = u; | 52 util = u; |
42 try { | 53 try { |
43 init(); | 54 init(); |
44 } catch (AuthOpException e) { | 55 } catch (AuthOpException e) { |
45 } | 56 } |
46 } | 57 } |
47 | 58 |
59 /** Test if the request is allowed to access filepath. | |
60 * @param filepath filepath to be acessed. | |
61 * @param request Request with user information. | |
62 * @throws AuthOpException Exception thrown on error. | |
63 * @return true if the request is allowed. | |
64 */ | |
48 public boolean isAuthRequired(String filepath, HttpServletRequest request) throws AuthOpException { | 65 public boolean isAuthRequired(String filepath, HttpServletRequest request) throws AuthOpException { |
49 // check permissions | 66 // check permissions |
50 List rolesRequired = rolesForPath(filepath, request); | 67 List rolesRequired = rolesForPath(filepath, request); |
51 return (rolesRequired != null); | 68 return (rolesRequired != null); |
52 } | 69 } |
53 | 70 |
71 /** | |
72 * @see digilib.auth.AuthOps#isAuthRequired(digilib.servlet.DigilibRequest) | |
73 */ | |
74 public boolean isAuthRequired(DigilibRequest request) | |
75 throws AuthOpException { | |
76 // check permissions | |
77 List rolesRequired = rolesForPath(request); | |
78 return (rolesRequired != null); | |
79 } | |
80 | |
81 /** Return authorization roles needed for request. | |
82 * | |
83 * Returns a list of authorization roles that would be allowed to access the | |
84 * specified path. The location information of the request is considered also. | |
85 * @param filepath filepath to be accessed. | |
86 * @param request ServletRequest with address information. | |
87 * @throws AuthOpException Exception thrown on error. | |
88 * @return List of Strings with role names. | |
89 */ | |
54 public boolean isAuthorized(String filepath, HttpServletRequest request) throws AuthOpException { | 90 public boolean isAuthorized(String filepath, HttpServletRequest request) throws AuthOpException { |
55 List rolesAllowed = rolesForPath(filepath, request); | 91 List rolesAllowed = rolesForPath(filepath, request); |
56 return isRoleAuthorized(rolesAllowed, request); | 92 return isRoleAuthorized(rolesAllowed, request); |
57 } | 93 } |
58 | 94 |
95 /** | |
96 * @see digilib.auth.AuthOps#isAuthorized(digilib.servlet.DigilibRequest) | |
97 */ | |
98 public boolean isAuthorized(DigilibRequest request) | |
99 throws AuthOpException { | |
100 List rolesAllowed = rolesForPath(request); | |
101 return isRoleAuthorized(rolesAllowed, request); | |
102 } | |
103 | |
104 /** Test request authorization against a list of roles. | |
105 * @param roles List of Strings with role names. | |
106 * @param request ServletRequest with address information. | |
107 * @return true if the user information in the request authorizes one of the roles. | |
108 */ | |
59 public boolean isRoleAuthorized(List roles, HttpServletRequest request) { | 109 public boolean isRoleAuthorized(List roles, HttpServletRequest request) { |
60 ListIterator r = roles.listIterator(); | 110 ListIterator r = roles.listIterator(); |
61 String s = ""; | 111 String s = ""; |
62 while (r.hasNext()) { | 112 while (r.hasNext()) { |
63 s = (String)r.next(); | 113 s = (String)r.next(); |
68 } | 118 } |
69 } | 119 } |
70 return false; | 120 return false; |
71 } | 121 } |
72 | 122 |
123 /** | |
124 * @see digilib.auth.AuthOps#isRoleAuthorized(java.util.List, digilib.servlet.DigilibRequest) | |
125 */ | |
126 public boolean isRoleAuthorized(List roles, DigilibRequest request) { | |
127 ListIterator r = roles.listIterator(); | |
128 String s = ""; | |
129 while (r.hasNext()) { | |
130 s = (String)r.next(); | |
131 util.dprintln(5, "Testing role: "+s); | |
132 if (((HttpServletRequest)request.getServletRequest()).isUserInRole(s)) { | |
133 util.dprintln(5, "Role Authorized"); | |
134 return true; | |
135 } | |
136 } | |
137 return false; | |
138 } | |
139 | |
73 public abstract void init() throws AuthOpException; | 140 public abstract void init() throws AuthOpException; |
74 | 141 |
75 public abstract List rolesForPath(String filepath, HttpServletRequest request) throws AuthOpException; | 142 public abstract List rolesForPath(String filepath, HttpServletRequest request) throws AuthOpException; |
76 | 143 |
144 public abstract List rolesForPath(DigilibRequest request) throws AuthOpException; | |
145 | |
77 } | 146 } |