KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > security > realm > web > jetty50 > JettyPrincipal


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: JettyPrincipal.java,v 1.1 2004/06/01 13:27:09 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.security.realm.web.jetty50;
28
29 import java.security.Principal JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 /**
33  * Define a principal which can be used by Jetty
34  * @author Florent Benoit
35  */

36 public class JettyPrincipal implements Principal JavaDoc {
37
38     /**
39      * Name of the principal
40      */

41     private String JavaDoc name;
42
43     /**
44      * Roles for this principal
45      */

46     private ArrayList JavaDoc roles;
47
48     /**
49      * Constructor
50      * @param name name of this principal
51      * @param roles roles for this principal
52      */

53     public JettyPrincipal(String JavaDoc name, ArrayList JavaDoc roles) {
54         this.name = name;
55         this.roles = roles;
56     }
57
58     /**
59      * Get the name of this principal
60      * @return the name of this principal
61      */

62     public String JavaDoc getName() {
63         return name;
64     }
65
66     /**
67      * This user is authenticated ?
68      * @return true if it is authenticated
69      */

70     public boolean isAuthenticated() {
71         return true;
72     }
73
74     /**
75      * Check if the given role is in the user's roles
76      * @param role the given role
77      * @return true if the role is in the user's roles
78      */

79     public boolean isUserInRole(String JavaDoc role) {
80         if (roles == null) {
81             return (false);
82         }
83         return roles.contains(role);
84     }
85
86     /**
87      * Gets the roles of this user
88      * @return roles of this user
89      */

90     public ArrayList JavaDoc getRoles() {
91         return roles;
92     }
93
94 }
Popular Tags