KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > Validator


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 /**
31  * This security validator.
32  *
33  * @author Brett Chaldecott
34  */

35 public class Validator {
36     
37     // log
38
private static Logger log =
39         Logger.getLogger(Validator.class.getName());
40     
41     /**
42      * The validator responsible for determining if the current thread can
43      * access a role.
44      *
45      * @param ref The reference to the class on which the call is being made.
46      * @param roleName The name of the role that access is being checked on.
47      * @exception AuthorizationException
48      * @exception SecurityException
49      */

50     public static void validate(Class JavaDoc ref,String JavaDoc roleName) throws
51             AuthorizationException, SecurityException JavaDoc {
52         log.debug("Validate access to : " + roleName);
53         ThreadPermissionSession session =
54                 SessionManager.getInstance().getSession();
55         Role role = RoleManager.getInstance().getRole(roleName);
56         if (role.canAccessRole(session.getPrincipals()) == false) {
57             throw new AuthorizationException("Access Denied to [" +
58                     ref.getName() + "] and role [" + roleName + "]");
59         }
60     }
61     
62 }
63
Popular Tags