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"}));
}
}
}