1 19 package org.lucane.server.store; 20 21 import org.lucane.server.*; 22 import org.lucane.common.concepts.*; 23 import java.util.*; 24 25 28 public abstract class ServiceStore 29 { 30 35 public abstract void storeService(ServiceConcept service) throws Exception ; 36 37 42 public abstract void updateService(ServiceConcept service) throws Exception ; 43 44 49 public abstract void removeService(ServiceConcept service) throws Exception ; 50 51 57 public abstract ServiceConcept getService(String name) throws Exception ; 58 59 64 public abstract Iterator getAllServices() throws Exception ; 65 66 72 public Iterator getAuthorizedServices(UserConcept user) 73 throws Exception 74 { 75 ArrayList authorizedServices = new ArrayList(); 76 77 UserStore um = Server.getInstance().getStore().getUserStore(); 78 Iterator groups = um.getAllUserGroups(user); 79 while(groups.hasNext()) 80 { 81 GroupConcept group = (GroupConcept)groups.next(); 82 Iterator services = group.getServices(); 83 while(services.hasNext()) 84 { 85 ServiceConcept service = (ServiceConcept)services.next(); 86 if(! authorizedServices.contains(service)) 87 authorizedServices.add(service); 88 } 89 } 90 91 return authorizedServices.iterator(); 92 } 93 94 101 public boolean isAuthorizedService(UserConcept user, ServiceConcept service) 102 throws Exception 103 { 104 Iterator i = getAuthorizedServices(user); 105 while(i.hasNext()) 106 { 107 Object o = i.next(); 108 109 if(service.equals(o)) 110 return true; 111 } 112 113 return false; 114 } 115 116 122 public Iterator getUsersFor(ServiceConcept service) 123 throws Exception 124 { 125 ArrayList users = new ArrayList(); 126 127 UserStore us = Server.getInstance().getStore().getUserStore(); 128 Iterator i = us.getAllUsers(); 129 while(i.hasNext()) 130 { 131 UserConcept user = (UserConcept)i.next(); 132 if(isAuthorizedService(user, service)) 133 users.add(user); 134 } 135 136 return users.iterator(); 137 } 138 } 139 | Popular Tags |