1 26 27 package org.objectweb.jonas.security.realm.factory; 28 29 import java.util.Hashtable ; 31 32 import javax.naming.Context ; 34 import javax.naming.Name ; 35 import javax.naming.RefAddr ; 36 import javax.naming.Reference ; 37 38 import org.objectweb.jonas.common.JNDIUtils; 39 40 import org.objectweb.util.monolog.api.BasicLevel; 42 43 48 public class JResourceMemoryFactory extends JResourceFactory { 49 50 53 private static final String FACTORY_TYPE = "org.objectweb.jonas.security.realm.factory.JResourceMemory"; 54 55 73 public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { 74 75 Reference ref = (Reference ) obj; 77 78 String clname = ref.getClassName(); 80 81 if (!ref.getClassName().equals(FACTORY_TYPE)) { 83 getLogger().log(BasicLevel.ERROR, "Cannot create object : required type is '" + FACTORY_TYPE 84 + "', but found type is '" + clname + "'."); 85 return null; 86 } 87 88 Hashtable users = new Hashtable (); 89 Hashtable groups = new Hashtable (); 90 Hashtable roles = new Hashtable (); 91 92 String jResName = (String ) ref.get("name").getContent(); 93 94 RefAddr refAddr = null; 95 refAddr = ref.get("users"); 96 if (refAddr != null) { 97 users = (Hashtable ) JNDIUtils.getObjectFromBytes((byte[]) refAddr.getContent(), getLogger()); 98 } 99 100 refAddr = ref.get("groups"); 101 if (refAddr != null) { 102 groups = (Hashtable ) JNDIUtils.getObjectFromBytes((byte[]) refAddr.getContent(), getLogger()); 103 } 104 105 refAddr = ref.get("roles"); 106 if (refAddr != null) { 107 roles = (Hashtable ) JNDIUtils.getObjectFromBytes((byte[]) refAddr.getContent(), getLogger()); 108 } 109 110 JResourceMemory jResourceMemory = new JResourceMemory(); 112 jResourceMemory.setName(jResName); 113 jResourceMemory.setUsers(users); 114 jResourceMemory.setGroups(groups); 115 jResourceMemory.setRoles(roles); 116 117 return jResourceMemory; 118 } 119 120 } | Popular Tags |