KickJava   Java API By Example, From Geeks To Geeks.

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


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.Group;
21 import org.apache.jetspeed.services.JetspeedLDAP;
22 import org.apache.jetspeed.services.ldap.LDAPURL;
23 import org.apache.jetspeed.services.security.GroupException;
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: LDAPGroup.java,v 1.6 2004/02/23 03:12:13 jford Exp $
31  *
32  */

33 public class LDAPGroup extends BaseLDAPObject implements Group {
34
35     // ---------------------------- Constants ----------------------------
36

37     protected static final String JavaDoc OBJECT_CLASS = "jetspeedgroup";
38     protected static final String JavaDoc ORGANIZATIONAL_UNIT = "ou=groups";
39
40     protected static final String JavaDoc ATTR_GROUP_NAME = "groupname";
41     protected static final String JavaDoc ATTR_GROUP_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 LDAPGroup()
52     {
53         isNew = true;
54     }
55
56     public LDAPGroup(String JavaDoc id)
57     {
58         this.setId(id);
59         isNew = true;
60     }
61
62     public LDAPGroup(String JavaDoc name, boolean isNew)
63     {
64         name = super.createId(name);
65         super.ldapurl = JetspeedLDAP.buildURL(ATTR_GROUP_ID + "=" + name + "," + ORGANIZATIONAL_UNIT);
66         this.isNew = isNew;
67
68         if (isNew)
69         {
70             this.setName(name);
71             super.myAttrs = new BasicAttributes JavaDoc();
72             super.myAttrs.put(ATTR_GROUP_ID, this.getId());
73             super.myAttrs.put(ATTR_GROUP_NAME, this.getName());
74             super.setObjectClass(OBJECT_CLASS);
75         }
76         else
77         {
78             super.myAttrs = JetspeedLDAP.read(ldapurl);
79             this.id = getutil(ATTR_GROUP_ID);
80             this.name = getutil(ATTR_GROUP_NAME);
81         }
82     }
83
84     public LDAPGroup(LDAPURL ldapurl)
85     {
86         super.ldapurl = ldapurl;
87         super.myAttrs = JetspeedLDAP.read(ldapurl);
88         this.id = getutil(ATTR_GROUP_ID);
89         this.name = getutil(ATTR_GROUP_NAME);
90     }
91
92     // --------------------- Persistence operations ----------------------
93

94     public void update(boolean create)
95     throws GroupException
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 GroupException("Failed to insert group 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 GroupException("Failed to update group in LDAP!");
108         }
109     }
110
111     // ------------------------ Accessor methods -------------------------
112

113     /**
114      * Get the name of the Group
115      *
116      * @return the name of the group.
117      */

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

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

139     public String JavaDoc getId()
140     {
141         return id;
142     }
143
144     /**
145      * Set the id of the Group
146      *
147      * @param id the new id for the group
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