1 23 24 package com.sun.enterprise.security.auth.realm; 25 26 import java.util.Properties ; 27 28 import com.sun.enterprise.config.ConfigContext; 29 import com.sun.enterprise.config.ConfigException; 30 import com.sun.enterprise.config.serverbeans.AuthRealm; 31 import com.sun.enterprise.config.serverbeans.ElementProperty; 32 import com.sun.enterprise.config.serverbeans.SecurityService; 33 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 34 import com.sun.enterprise.admin.event.AdminEventListenerException; 35 import com.sun.enterprise.admin.event.AuthRealmEvent; 36 import com.sun.enterprise.admin.event.AuthRealmEventListener; 37 import com.sun.enterprise.security.SecurityUtil; 38 import com.sun.enterprise.server.pluggable.SecuritySupport; 39 40 45 public class AuthRealmEventListenerImpl implements AuthRealmEventListener { 46 47 54 public void authRealmCreated(AuthRealmEvent event) 55 throws AdminEventListenerException { 56 try { 57 createRealm(event); 58 } catch(Exception ex) { 59 throw new AdminEventListenerException(ex); 60 } 61 } 62 63 70 public void authRealmDeleted(AuthRealmEvent event) 71 throws AdminEventListenerException { 72 try { 73 Realm.unloadInstance(event.getAuthRealmName()); 75 } catch(Exception ex) { 76 throw new AdminEventListenerException(ex); 77 } 78 } 79 80 87 public void authRealmUpdated(AuthRealmEvent event) 88 throws AdminEventListenerException { 89 try { 90 createRealm(event); 92 } catch(Exception ex) { 93 throw new AdminEventListenerException(ex); 94 } 95 } 96 97 104 private void createRealm(AuthRealmEvent event) throws Exception { 105 ConfigContext configContext = event.getConfigContext(); 106 String realmName = event.getAuthRealmName(); 107 SecurityService security = 108 ServerBeansFactory.getSecurityServiceBean(configContext); 109 AuthRealm authRealm = security.getAuthRealmByName(realmName); 110 String className = authRealm.getClassname(); 112 ElementProperty[] elementProps = authRealm.getElementProperty(); 113 int size = (elementProps != null) ? elementProps.length : 0; 114 Properties props = new Properties (); 115 for (int i = 0; i < size; i++) { 116 props.setProperty(elementProps[i].getName(), 117 elementProps[i].getValue()); 118 } 119 120 if ("com.sun.enterprise.security.auth.realm.file.FileRealm".equals(className)) { 121 SecuritySupport secSupp = SecurityUtil.getSecuritySupport(); 122 secSupp.synchronizeKeyFile(configContext, realmName); 123 } 124 Realm.instantiate(realmName, className, props); 125 } 126 } 127 | Popular Tags |