KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.logging.Level JavaDoc;
28
29 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
30 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
31 import com.sun.enterprise.config.serverbeans.validation.Result;
32 import com.sun.enterprise.config.serverbeans.Ssl;
33 import com.sun.enterprise.config.serverbeans.IiopListener;
34 import com.sun.enterprise.config.serverbeans.ServerTags;
35 import com.sun.enterprise.config.serverbeans.validation.tests.StaticTest;
36
37 import com.sun.enterprise.config.ConfigBean;
38 import com.sun.enterprise.config.ConfigContextEvent;
39 import com.sun.enterprise.config.ConfigException;
40
41 /**
42     Custom Test for Ssl Element which calls the Generic Validation before performing custom tests
43
44     @author Srinivas Krishnan
45     @version 2.0
46 */

47
48 public class SslTest extends GenericValidator {
49     
50     public SslTest(ValidationDescriptor desc) {
51         super(desc);
52     }
53     
54     public Result validate(final ConfigContextEvent cce) {
55         _logger.log(Level.CONFIG, "SslTest validation");
56         
57         final Result result = super.validate(cce); // Before doing custom validation do basic validation
58

59         final String JavaDoc choice = cce.getChoice();
60         if(choice.equals(StaticTest.UPDATE)) {
61             return performUpdateChecks(result, cce);
62         } else if (choice.equals(StaticTest.SET)) {
63             return performSetChecks(result,cce);
64         }
65         return result;
66     }
67
68     private Result performUpdateChecks(final Result result, final ConfigContextEvent cce){
69         _logger.log(Level.CONFIG, "SslTest performing update check");
70         final ConfigBean co = (ConfigBean) cce.getClassObject();
71         final String JavaDoc parentsDtdName = ((ConfigBean) co.parent()).dtdName();
72         _logger.log(Level.FINER, "SslTest update - parent's DTD name is \""+parentsDtdName+"\"");
73
74         _logger.log(Level.FINER, "SslTest update - attribute name is \""+cce.getName()+"\"");
75         _logger.log(Level.FINER, "SslTest update - attribute value is \""+cce.getObject()+"\"");
76
77         if (parentsDtdName.equals(ServerTags.IIOP_LISTENER)
78             && cce.getName().equals(ServerTags.SSL2_ENABLED)
79             && ((String JavaDoc) cce.getObject()).equalsIgnoreCase("true")){
80             _logger.log(Level.FINER, "SslTest update check - parent is an iiop-listener, and ssl2enabled attribute is being set to true");
81             ssl2NotAllowed(result);
82         }
83         return result;
84     }
85     private Result performSetChecks(final Result result, final ConfigContextEvent cce){
86         _logger.log(Level.CONFIG, "SsltTest performing set check");
87         _logger.log(Level.FINER, "SsltTest set - parent's class is \""+cce.getClassObject().getClass().getName()+"\"");
88         _logger.log(Level.FINER, "SsltTest set - ssl objects ssl2enabled attribute is set: \""+((Ssl) cce.getObject()).isSsl2Enabled()+"\"");
89         if (cce.getClassObject() instanceof IiopListener
90             && ((Ssl) cce.getObject()).isSsl2Enabled()){
91             _logger.log(Level.FINER, "SsltTest set check - parent is an iiop-listener, and ssl2enabled attribute is being set to true");
92             ssl2NotAllowed(result);
93         }
94         return result;
95     }
96
97     private void ssl2NotAllowed(final Result result){
98         _logger.log(Level.CONFIG, "SslTest - an invalid attempt to enable ssl2 has been found. Returning an error");
99         result.failed(smh.getLocalString(getClass().getName()+".ssl2NotAllowed",
100                                          "ssl2 cannot be enabled for an iiop-listener"));
101     }
102     
103 }
104
Popular Tags