KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > tests > AuthRealmTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.config.serverbeans.validation.tests;
25
26 import java.util.Locale JavaDoc;
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 JavaDoc;
47
48 /**
49     Custom Test for Auth Realm element which calls the Generic Validation before performing custom tests
50
51     @author Srinivas Krishnan
52     @version 2.0
53 */

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); // Before doing custom validation do basic validation
65

66         if(valCtx.isDELETE()) {
67             AuthRealm ar = (AuthRealm)valCtx.getTargetBean();
68             SecurityService sec = (SecurityService) ar.parent();
69             String JavaDoc realmName = ar.getName();
70             String JavaDoc defaultRealmName = null;
71             try {
72                 defaultRealmName = sec.getDefaultRealm();
73             } catch (Exception JavaDoc 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             // atleast one element of auth-realm is required
81
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 JavaDoc 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 JavaDoc[]{"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 JavaDoc[]{"jaas-context"}));
101                 }
102             }
103         }
104     }
105 }
106
Popular Tags