01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2006 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * Validator.java
20: *
21: * This security validator.
22: */
23:
24: package com.rift.coad.lib.security;
25:
26: // log 4 j imports
27: import org.apache.log4j.Logger;
28:
29: /**
30: * This security validator.
31: *
32: * @author Brett Chaldecott
33: */
34: public class Validator {
35:
36: // log
37: private static Logger log = Logger.getLogger(Validator.class
38: .getName());
39:
40: /**
41: * The validator responsible for determining if the current thread can
42: * access a role.
43: *
44: * @param ref The reference to the class on which the call is being made.
45: * @param roleName The name of the role that access is being checked on.
46: * @exception AuthorizationException
47: * @exception SecurityException
48: */
49: public static void validate(Class ref, String roleName)
50: throws AuthorizationException, SecurityException {
51: log.debug("Validate access to : " + roleName);
52: ThreadPermissionSession session = SessionManager.getInstance()
53: .getSession();
54: Role role = RoleManager.getInstance().getRole(roleName);
55: if (role.canAccessRole(session.getPrincipals()) == false) {
56: throw new AuthorizationException("Access Denied to ["
57: + ref.getName() + "] and role [" + roleName + "]");
58: }
59: }
60:
61: }
|