1 26 27 package org.objectweb.jonas.security.realm.factory; 28 29 import java.io.Serializable ; 30 import java.util.ArrayList ; 31 import java.util.Hashtable ; 32 import javax.management.MBeanServer ; 33 import javax.naming.Context ; 34 import javax.naming.InitialContext ; 35 import javax.naming.NamingException ; 36 import javax.naming.Reference ; 37 import javax.naming.Referenceable ; 38 39 import org.objectweb.jonas.security.SecurityService; 40 import org.objectweb.jonas.service.ServiceManager; 41 import org.objectweb.jonas.management.ReconfigDispatcher; 42 import org.objectweb.jonas.management.ReconfiguredXml; 43 44 import org.objectweb.util.monolog.api.Logger; 46 import org.objectweb.util.monolog.api.BasicLevel; 47 48 import org.objectweb.jonas.common.Log; 49 import org.objectweb.jonas.jmx.JmxService; 50 import org.objectweb.jonas.security.realm.principals.User; 51 52 57 public abstract class JResource extends ReconfigDispatcher implements Serializable , Referenceable , JResourceMBean { 58 59 62 private String name = null; 63 64 67 private static Logger logger = Log.getLogger(Log.JONAS_SECURITY_PREFIX); 68 69 72 private Hashtable users = null; 73 74 77 private long sequenceNumber; 78 79 82 private SecurityService securityService = null; 83 84 87 private MBeanServer mbeanServer = null; 88 89 93 public JResource() throws Exception { 94 users = new Hashtable (); 95 sequenceNumber = 0; 96 try { 97 ServiceManager sm = ServiceManager.getInstance(); 98 securityService = (SecurityService) sm.getSecurityService(); 99 mbeanServer = ((JmxService) sm.getJmxService()).getJmxServer(); 100 } catch (Exception e) { 101 if (logger.isLoggable(BasicLevel.DEBUG)) { 104 logger.log(BasicLevel.DEBUG, "Cannot get MBean server, client mode ? no jmx registration"); 105 } 106 } catch (Error err) { 107 if (logger.isLoggable(BasicLevel.DEBUG)) { 109 logger.log(BasicLevel.DEBUG, "No services can be retrieved, client mode ?"); 110 } 111 } 112 113 } 114 115 119 public void setName(String name) { 120 this.name = name; 121 } 122 123 127 public String getName() { 128 return name; 129 } 130 131 135 protected MBeanServer getMBeanServer() { 136 return mbeanServer; 137 } 138 139 147 public abstract Reference getReference() throws NamingException ; 148 149 153 public abstract void removeMBeans() throws JResourceException; 154 155 161 public abstract User findUser(String name) throws JResourceException; 162 163 169 public abstract boolean isValidUser(User user, String credentials); 170 171 177 public abstract ArrayList getArrayListCombinedRoles(User user) throws JResourceException; 178 179 183 public Hashtable getUsers() { 184 return users; 185 } 186 187 191 protected long getSequenceNumber() { 192 return ++sequenceNumber; 193 } 194 195 198 public void saveConfig() { 199 200 if (securityService != null) { 201 String xml = securityService.toXML(); 203 ReconfiguredXml reconfiguredXml = new ReconfiguredXml(xml); 204 205 sendReconfigNotification(getSequenceNumber(), name, reconfiguredXml); 207 sendSaveNotification(getSequenceNumber(), name); 208 209 try { 211 Context ictx = new InitialContext (); 212 ictx.rebind(getName(), this); 213 if (logger.isLoggable(BasicLevel.DEBUG)) { 214 logger.log(BasicLevel.DEBUG, "jResource " + getName() + " is rebind into the registry."); 215 } 216 } catch (NamingException e) { 217 logger.log(BasicLevel.ERROR, "Cannot rebind factory to the jndi : '" + e.getMessage() + "'"); 218 } 219 220 } 221 } 222 223 226 public static Logger getLogger() { 227 return logger; 228 } 229 232 public static void setLogger(Logger logger) { 233 JResource.logger = logger; 234 } 235 238 public void setUsers(Hashtable users) { 239 this.users = users; 240 } 241 242 245 public void clearCache() { 246 setUsers(new Hashtable ()); 247 } 248 } | Popular Tags |