1 23 24 package com.sun.enterprise.config.serverbeans.validation.tests; 25 26 import java.util.Locale ; 27 28 import com.sun.enterprise.config.serverbeans.validation.GenericValidator; 29 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor; 30 import com.sun.enterprise.config.serverbeans.validation.ValidationContext; 31 import com.sun.enterprise.config.serverbeans.validation.Result; 32 import com.sun.enterprise.config.serverbeans.Domain; 33 import com.sun.enterprise.config.serverbeans.Config; 34 import com.sun.enterprise.config.serverbeans.Resources; 35 import com.sun.enterprise.config.serverbeans.validation.tests.StaticTest; 36 import com.sun.enterprise.config.serverbeans.AuthRealm; 37 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 38 import com.sun.enterprise.config.serverbeans.SecurityService; 39 import com.sun.enterprise.config.serverbeans.ElementProperty; 40 41 import com.sun.enterprise.config.ConfigBean; 42 import com.sun.enterprise.config.ConfigContextEvent; 43 import com.sun.enterprise.config.ConfigContext; 44 import com.sun.enterprise.config.ConfigException; 45 46 import java.util.logging.Level ; 47 48 54 55 public class AuthRealmTest extends GenericValidator { 56 57 static boolean checked = false; 58 59 public AuthRealmTest(ValidationDescriptor desc) { 60 super(desc); 61 } 62 63 public void validate(ValidationContext valCtx) { 64 super.validate(valCtx); 66 if(valCtx.isDELETE()) { 67 AuthRealm ar = (AuthRealm)valCtx.getTargetBean(); 68 SecurityService sec = (SecurityService) ar.parent(); 69 String realmName = ar.getName(); 70 String defaultRealmName = null; 71 try { 72 defaultRealmName = sec.getDefaultRealm(); 73 } catch (Exception ee) { 74 } 75 if(defaultRealmName != null && defaultRealmName.equals(realmName)) { 76 valCtx.result.failed(smh.getLocalString(getClass().getName()+".defaultRealmDelete", 77 "Default auth-realm can not be deleted")); 78 } 79 80 AuthRealm[] authRealm = sec.getAuthRealm(); 82 if(authRealm.length < 2) 83 valCtx.result.failed(smh.getLocalString(getClass().getName()+".authRealmOneCantDelete", 84 "At least one auth-realm required, auth-realm can not be deleted")); 85 86 87 } else if(valCtx.isADD()) { 88 AuthRealm ar = (AuthRealm)valCtx.getTargetBean(); 89 String className = ar.getClassname(); 90 if(className.endsWith(".FileRealm")) { 91 ElementProperty fileProp = ar.getElementPropertyByName("file"); 92 if(fileProp==null) { 93 valCtx.result.failed(smh.getLocalString(getClass().getName()+".propNotFounfInFileRealm", 94 "Auth realm can not be added. \"{0}\" property should be provided for FileRealm type.", 95 new Object []{"file"})); 96 } 97 ElementProperty jaasContextProp = ar.getElementPropertyByName("jaas-context"); 98 if(jaasContextProp==null) { 99 valCtx.result.failed(smh.getLocalString(getClass().getName()+".propNotFounfInFileRealm", 100 "Auth realm can not be added. \"{0}\" property should be provided for FileRealm type.", new Object []{"jaas-context"})); 101 } 102 } 103 } 104 } 105 } 106 | Popular Tags |