KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > security > ldap > LDAPPermission


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.om.security.ldap;
18
19 import javax.naming.directory.BasicAttributes JavaDoc;
20 import org.apache.jetspeed.om.security.Permission;
21 import org.apache.jetspeed.services.JetspeedLDAP;
22 import org.apache.jetspeed.services.ldap.LDAPURL;
23 import org.apache.jetspeed.services.security.PermissionException;
24
25 /**
26  *
27  * @author <a HREF="mailto:ender@kilicoglu.nom.tr">Ender KILICOGLU</a>
28  * @author <a HREF="mailto:sami.leino@netorek.fi">Sami Leino</a>
29  *
30  * @version $Id: LDAPPermission.java,v 1.5 2004/02/23 03:12:13 jford Exp $
31  *
32  */

33 public class LDAPPermission extends BaseLDAPObject implements Permission {
34
35     // ---------------------------- Constants ----------------------------
36

37     protected static final String JavaDoc OBJECT_CLASS = "jetspeedpermission";
38     protected static final String JavaDoc ORGANIZATIONAL_UNIT = "ou=permissions";
39
40     protected static final String JavaDoc ATTR_PERMISSION_NAME = "permissionname";
41     protected static final String JavaDoc ATTR_PERMISSION_ID = "uid";
42
43     // ------------------------- Member variables ------------------------
44

45     protected String JavaDoc name = null;
46     protected String JavaDoc id = null;
47     protected boolean isNew = true;
48
49     // --------------------------- Constructors --------------------------
50

51     public LDAPPermission()
52     {
53         isNew = true;
54     }
55
56     public LDAPPermission(String JavaDoc id)
57     {
58         this.setId(id);
59         isNew = true;
60     }
61
62     public LDAPPermission(String JavaDoc name, boolean isNew)
63     {
64         name = super.createId(name);
65         super.ldapurl = JetspeedLDAP.buildURL(ATTR_PERMISSION_ID + "=" + name + "," + ORGANIZATIONAL_UNIT);
66         this.isNew = isNew;
67
68         if (isNew)
69         {
70             this.setName(name);
71             super.myAttrs = new BasicAttributes JavaDoc();
72             myAttrs.put(ATTR_PERMISSION_ID, id);
73             myAttrs.put(ATTR_PERMISSION_NAME, name);
74             super.setObjectClass(OBJECT_CLASS);
75         }
76         else
77         {
78             super.myAttrs = JetspeedLDAP.read(ldapurl);
79             this.id = super.getutil(ATTR_PERMISSION_ID);
80             this.name = super.getutil(ATTR_PERMISSION_NAME);
81         }
82     }
83
84     public LDAPPermission(LDAPURL ldapurl)
85     {
86         super.ldapurl = ldapurl;
87         super.myAttrs = JetspeedLDAP.read(ldapurl);
88         this.id = super.getutil(ATTR_PERMISSION_ID);
89         this.name = super.getutil(ATTR_PERMISSION_NAME);
90     }
91
92     // --------------------- Persistence operations ----------------------
93

94     public void update(boolean create)
95     throws PermissionException
96     {
97         removeutil("createTimeStamp", false);
98         removeutil("modifyTimeStamp", false);
99
100         if (create)
101         {
102             if (JetspeedLDAP.addEntry(super.ldapurl, super.myAttrs) == false) throw new PermissionException("Could not insert permission in LDAP!");
103         }
104         else if (JetspeedLDAP.exists(super.ldapurl))
105         {
106             JetspeedLDAP.deleteAttrs(super.ldapurl, super.rmAttrs);
107             if (JetspeedLDAP.updateEntry(super.ldapurl, super.myAttrs) == false) throw new PermissionException("Could not update permission in LDAP!");
108         }
109     }
110
111     // ------------------------ Accessor methods -------------------------
112

113     /**
114      * Get the name of the Permission
115      *
116      * @return the name of the permission.
117      */

118     public String JavaDoc getName()
119     {
120         return name;
121     }
122  
123     /**
124      * Set the name of the Permission
125      *
126      * @param permissionName the name of the Permission.
127      */

128     public void setName(String JavaDoc permissionName)
129     {
130         setId(permissionName);
131         name = super.createId(permissionName);
132     }
133
134     /**
135      * Get the id of the Permission
136      *
137      * @return the id of the permission.
138      */

139     public String JavaDoc getId()
140     {
141         return id;
142     }
143
144     /**
145      * Set the id of the Permission
146      *
147      * @param id the new id for the permission
148      */

149     public void setId(String JavaDoc id)
150     {
151         if (this.id == null)
152         {
153             this.id = super.createId(id);
154         }
155     }
156
157     public boolean isNew()
158     {
159         return isNew;
160     }
161
162     void setNew(boolean isNew)
163     {
164         this.isNew = isNew;
165     }
166
167 }
Popular Tags