FileDocCategorySizeDatePackage
AuthRealmTest.javaAPI DocGlassfish v2 API5617Fri May 04 22:24:38 BST 2007com.sun.enterprise.config.serverbeans.validation.tests

AuthRealmTest

public class AuthRealmTest extends com.sun.enterprise.config.serverbeans.validation.GenericValidator
Custom Test for Auth Realm element which calls the Generic Validation before performing custom tests
author
Srinivas Krishnan
version
2.0

Fields Summary
static boolean
checked
Constructors Summary
public AuthRealmTest(com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor desc)

    
       
        super(desc);
    
Methods Summary
public voidvalidate(com.sun.enterprise.config.serverbeans.validation.ValidationContext valCtx)

        super.validate(valCtx); // Before doing custom validation do basic validation
        
        if(valCtx.isDELETE()) {
            AuthRealm ar = (AuthRealm)valCtx.getTargetBean();
            SecurityService sec = (SecurityService) ar.parent();
            String realmName = ar.getName();
            String defaultRealmName = null;
            try {
                defaultRealmName = sec.getDefaultRealm();
            } catch (Exception ee) {
            }
            if(defaultRealmName != null && defaultRealmName.equals(realmName)) {
                valCtx.result.failed(smh.getLocalString(getClass().getName()+".defaultRealmDelete",
                        "Default auth-realm can not be deleted"));
            }
            
            // atleast one element of auth-realm is required
            AuthRealm[] authRealm = sec.getAuthRealm();
            if(authRealm.length < 2)
                valCtx.result.failed(smh.getLocalString(getClass().getName()+".authRealmOneCantDelete",
                        "At least one auth-realm required, auth-realm can not be deleted"));
            
            
        } else if(valCtx.isADD()) {
            AuthRealm ar = (AuthRealm)valCtx.getTargetBean();
            String className = ar.getClassname();
            if(className.endsWith(".FileRealm")) {
                ElementProperty fileProp = ar.getElementPropertyByName("file");
                if(fileProp==null) {
                    valCtx.result.failed(smh.getLocalString(getClass().getName()+".propNotFounfInFileRealm",
                            "Auth realm can not be added. \"{0}\" property should be provided for FileRealm type.", 
                            new Object[]{"file"}));
                }
                ElementProperty jaasContextProp = ar.getElementPropertyByName("jaas-context");
                if(jaasContextProp==null) {
                    valCtx.result.failed(smh.getLocalString(getClass().getName()+".propNotFounfInFileRealm",
                            "Auth realm can not be added. \"{0}\" property should be provided for FileRealm type.", new Object[]{"jaas-context"}));
                }
            }
        }