FileDocCategorySizeDatePackage
AuthRealmEventListenerImpl.javaAPI DocGlassfish v2 API5961Fri May 04 22:35:26 BST 2007com.sun.enterprise.security.auth.realm

AuthRealmEventListenerImpl

public class AuthRealmEventListenerImpl extends Object implements com.sun.enterprise.admin.event.AuthRealmEventListener
Implements interface AuthRealmEventListener. So that realms can be dynamically created/updated/deleted.
author
Shing Wai Chan

Fields Summary
Constructors Summary
Methods Summary
public voidauthRealmCreated(com.sun.enterprise.admin.event.AuthRealmEvent event)
New auth realm created. It is called whenever a AuthRealmEvent with action of AuthRealmEvent.ACTION_CREATE is received.

throws
AdminEventListenerException when the listener is unable to process the event.

        try {
            createRealm(event);
        } catch(Exception ex) {
            throw new AdminEventListenerException(ex);
        }
    
public voidauthRealmDeleted(com.sun.enterprise.admin.event.AuthRealmEvent event)
Auth realm deleted. It is called whenever a AuthRealmEvent with action of AuthRealmEvent.ACTION_DELETE is received.

throws
AdminEventListenerException when the listener is unable to process the event.

        try {
            //only unload the realm, keep any auxiliary file for sanity
            Realm.unloadInstance(event.getAuthRealmName());
        } catch(Exception ex) {
            throw new AdminEventListenerException(ex);
        }
    
public voidauthRealmUpdated(com.sun.enterprise.admin.event.AuthRealmEvent event)
Auth realm updated (attributes change). It is called whenever a AuthRealmEvent with action of AuthRealmEvent.ACTION_UPDATE is received.

throws
AdminEventListenerException when the listener is unable to process the event.

        try {
            //XXX replace with a new realm, need to revisit in JSR 196
            createRealm(event);
        } catch(Exception ex) {
            throw new AdminEventListenerException(ex);
        }
    
private voidcreateRealm(com.sun.enterprise.admin.event.AuthRealmEvent event)
This method will create or replace existing realm with a new one in cache.

param
event
exception
for instance, BadRealmException, ConfigException, SynchronizationException

        ConfigContext configContext = event.getConfigContext();
        String realmName = event.getAuthRealmName();
        SecurityService security = 
            ServerBeansFactory.getSecurityServiceBean(configContext);
        AuthRealm authRealm = security.getAuthRealmByName(realmName);
        //authRealm cannot be null here
        String className = authRealm.getClassname();
        ElementProperty[] elementProps = authRealm.getElementProperty();
        int size = (elementProps != null) ? elementProps.length : 0;
        Properties props = new Properties();
        for (int i = 0; i < size; i++) {
            props.setProperty(elementProps[i].getName(),
                    elementProps[i].getValue());
        }

        if ("com.sun.enterprise.security.auth.realm.file.FileRealm".equals(className)) {
            SecuritySupport secSupp = SecurityUtil.getSecuritySupport();
            secSupp.synchronizeKeyFile(configContext, realmName);
        }
        Realm.instantiate(realmName, className, props);