Mercurial > hg > digilib-old
comparison servlet/src/digilib/auth/AuthOpsImpl.java @ 1:0ff3ede32060
Initial revision
author | robcast |
---|---|
date | Thu, 17 Jan 2002 15:25:46 +0100 |
parents | |
children | 3b8797fc3e90 9cedd170b581 |
comparison
equal
deleted
inserted
replaced
0:ffd2df307e81 | 1:0ff3ede32060 |
---|---|
1 /* AuthOps -- Authentication class implementation | |
2 | |
3 Digital Image Library servlet components | |
4 | |
5 Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de) | |
6 | |
7 This program is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Please read license.txt for the full details. A copy of the GPL | |
13 may be found at http://www.gnu.org/copyleft/lgpl.html | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 */ | |
20 | |
21 package digilib.auth; | |
22 | |
23 import javax.servlet.http.HttpServletRequest; | |
24 import java.util.*; | |
25 | |
26 import digilib.*; | |
27 | |
28 public abstract class AuthOpsImpl implements AuthOps { | |
29 | |
30 protected Utils util; | |
31 | |
32 public AuthOpsImpl() { | |
33 util = new Utils(); | |
34 try { | |
35 init(); | |
36 } catch (AuthOpException e) { | |
37 } | |
38 } | |
39 | |
40 public AuthOpsImpl(Utils u) { | |
41 util = u; | |
42 try { | |
43 init(); | |
44 } catch (AuthOpException e) { | |
45 } | |
46 } | |
47 | |
48 public boolean isAuthRequired(String filepath, HttpServletRequest request) throws AuthOpException { | |
49 // check permissions | |
50 List rolesRequired = rolesForPath(filepath, request); | |
51 return (rolesRequired != null); | |
52 } | |
53 | |
54 public boolean isAuthorized(String filepath, HttpServletRequest request) throws AuthOpException { | |
55 List rolesAllowed = rolesForPath(filepath, request); | |
56 return isRoleAuthorized(rolesAllowed, request); | |
57 } | |
58 | |
59 public boolean isRoleAuthorized(List roles, HttpServletRequest request) { | |
60 ListIterator r = roles.listIterator(); | |
61 String s = ""; | |
62 while (r.hasNext()) { | |
63 s = (String)r.next(); | |
64 util.dprintln(5, "Testing role: "+s); | |
65 if (request.isUserInRole(s)) { | |
66 util.dprintln(5, "Role Authorized"); | |
67 return true; | |
68 } | |
69 } | |
70 return false; | |
71 } | |
72 | |
73 public abstract void init() throws AuthOpException; | |
74 | |
75 public abstract List rolesForPath(String filepath, HttpServletRequest request) throws AuthOpException; | |
76 | |
77 } |