1 23 24 package com.sun.enterprise.security; 25 26 import java.util.*; 27 import java.util.logging.Logger ; 28 import java.util.logging.Level ; 29 import com.sun.logging.LogDomains; 30 import javax.security.auth.login.*; 31 import com.sun.enterprise.config.serverbeans.*; 32 import com.sun.enterprise.config.*; 33 import com.sun.enterprise.server.*; 34 import com.sun.enterprise.security.auth.realm.Realm; 35 import com.sun.enterprise.security.auth.realm.BadRealmException; 36 import com.sun.enterprise.util.LocalStringManagerImpl; 37 38 39 47 48 public class RealmConfig 49 { 50 private static Logger logger = 51 LogDomains.getLogger(LogDomains.SECURITY_LOGGER); 52 53 54 public static void createRealms(String defaultRealm, AuthRealm[] realms) 55 { 56 assert(realms != null); 57 58 String goodRealm = null; 60 for (int i=0; i < realms.length; i++) { 61 62 AuthRealm aRealm = realms[i]; 63 String realmName = aRealm.getName(); 64 String realmClass = aRealm.getClassname(); 65 assert (realmName != null); 66 assert (realmClass != null); 67 68 try { 69 ElementProperty[] realmProps = 70 aRealm.getElementProperty(); 71 72 Properties props = new Properties(); 73 74 for (int j=0; j < realmProps.length; j++) { 75 ElementProperty p = realmProps[j]; 76 String name = p.getName(); 77 String value = p.getValue(); 78 props.setProperty(name, value); 79 } 80 Realm.instantiate(realmName, realmClass, props); 81 82 logger.fine("Configured realm: " + realmName); 83 84 if (goodRealm == null) { 85 goodRealm = realmName; 86 } 87 } catch (Exception e) { 88 logger.log(Level.WARNING, 89 "realmconfig.disable", realmName); 90 logger.log(Level.WARNING, "security.exception", e); 91 } 92 } 93 94 98 if (goodRealm == null) { 99 logger.severe("realmconfig.nogood"); 100 101 } else { 102 try { 103 Realm def = Realm.getInstance(defaultRealm); 104 if (def == null) { 105 defaultRealm = goodRealm; 106 } 107 } catch (Exception e) { 108 defaultRealm = goodRealm; 109 } 110 Realm.setDefaultRealm(defaultRealm); 111 logger.fine("Default realm is set to: "+ defaultRealm); 112 } 113 } 114 115 125 public static void createRealms() 126 { 127 128 try { 129 logger.fine("Initializing configured realms."); 130 131 ConfigContext configContext = 132 ApplicationServer.getServerContext().getConfigContext(); 133 assert(configContext != null); 134 135 Server configBean = 136 ServerBeansFactory.getServerBean(configContext); 137 assert(configBean != null); 138 139 SecurityService securityBean = 140 ServerBeansFactory.getSecurityServiceBean(configContext); 141 assert(securityBean != null); 142 143 String defaultRealm = securityBean.getDefaultRealm(); 145 146 AuthRealm[] realms = securityBean.getAuthRealm(); 148 assert(realms != null); 149 150 createRealms(defaultRealm, realms); 151 152 } catch (Exception e) { 153 logger.log(Level.SEVERE, "realmconfig.nogood", e); 154 155 } 156 } 157 158 159 160 161 } 162 | Popular Tags |