1 package org.tigris.scarab.services.security; 2 3 4 49 50 import java.util.ArrayList ; 51 import java.util.List ; 52 53 import org.apache.fulcrum.security.impl.db.DBSecurityService; 54 55 import org.apache.fulcrum.security.entity.Group; 56 57 import org.apache.fulcrum.security.util.GroupSet; 58 import org.apache.fulcrum.security.util.DataBackendException; 59 import org.apache.fulcrum.security.util.EntityExistsException; 60 import org.apache.fulcrum.security.util.UnknownEntityException; 61 62 import org.apache.torque.om.Persistent; 63 import org.apache.torque.util.Criteria; 64 65 import org.tigris.scarab.om.ScarabModulePeer; 66 import org.tigris.scarab.om.Module; 67 import org.tigris.scarab.util.Log; 68 69 70 77 public class ScarabDBSecurityService extends DBSecurityService 78 { 79 85 public GroupSet getGroups(Criteria criteria) 86 throws DataBackendException 87 { 88 List groups = null; 89 try 90 { 91 groups = ScarabModulePeer.doSelect(criteria); 92 } 93 catch(Exception e) 94 { 95 throw new DataBackendException("getGroups(Criteria) failed", e); } 97 if (groups == null) 98 { 99 groups = new ArrayList (0); 100 } 101 return new GroupSet(groups); 102 } 103 104 111 public void saveGroup(Group group) 112 throws DataBackendException, UnknownEntityException 113 { 114 try 115 { 116 if (!((Persistent)group).isNew()) 117 { 118 group.save(); 119 } 120 } 121 catch(Exception e) 122 { 123 throw new DataBackendException("saveGroup(Group) failed" ,e); } 125 throw new UnknownEntityException("Unknown group '" + group + "'"); } 127 128 136 public synchronized Group addGroup(Group group) 137 throws DataBackendException, EntityExistsException 138 { 139 try 140 { 141 lockExclusive(); 142 if (((Persistent)group).isNew()) 143 { 144 group.save(); 145 getAllGroups().add(group); 147 return group; 148 } 149 } 150 catch(Exception e) 151 { 152 throw new DataBackendException("addGroup(Group) failed", e); } 154 finally 155 { 156 unlockExclusive(); 157 } 158 throw new EntityExistsException("Group '" + group + 161 "' already exists"); } 163 164 172 public synchronized void removeGroup(Group group) 173 throws DataBackendException, UnknownEntityException 174 { 175 try 176 { 177 lockExclusive(); 178 if (!((Persistent)group).isNew()) 179 { 180 ((Module)group).setDeleted(true); 181 group.save(); 182 getAllGroups().remove(group); 183 } 184 } 185 catch(Exception e) 186 { 187 Log.get().error("Failed to delete a Group"); 188 Log.get().error(e); 189 throw new DataBackendException("removeGroup(Group) failed", e); } 191 finally 192 { 193 unlockExclusive(); 194 } 195 throw new UnknownEntityException("Unknown group '" + group + "'"); } 197 198 207 public synchronized void renameGroup(Group group, String name) 208 throws DataBackendException, UnknownEntityException 209 { 210 throw new DataBackendException("rename is not supported"); 212 236 } 237 238 247 protected boolean checkExists(Group group) 248 throws DataBackendException, Exception 249 { 250 return ScarabModulePeer.checkExists(group); 251 } 252 } 253 | Popular Tags |