KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > app > AppSecurityRole


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 package com.sun.enterprise.tools.verifier.tests.app;
24
25 import com.sun.enterprise.tools.verifier.tests.app.ApplicationTest;
26 import java.util.*;
27 import java.io.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.security.acl.*;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.util.FileClassLoader;
32
33
34 /**
35  * The Application role-name element contains the name of a security role.
36  */

37 public class AppSecurityRole extends ApplicationTest implements AppCheck {
38
39     
40
41     /**
42      * The Application role-name element contains the name of a security role.
43      *
44      * @param descriptor the Application deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

48     public Result check(Application descriptor) {
49
50     Result result = getInitializedResult();
51
52
53     if (!descriptor.getRoles().isEmpty()) {
54         boolean oneFailed = false;
55         boolean foundIt = false;
56         // get the security role name's in this app
57
Set sc = descriptor.getRoles();
58         Iterator itr = sc.iterator();
59         while (itr.hasNext()) {
60         foundIt = false;
61         Role role = (Role) itr.next();
62         String JavaDoc roleName = role.getName();
63         if (roleName.length() > 0) {
64             foundIt = true;
65         } else {
66             foundIt = false;
67         }
68
69       
70         if (foundIt) {
71             result.addGoodDetails(smh.getLocalString
72                       (getClass().getName() + ".passed",
73                        "The security role name [ {0} ] found within application [ {1} ]",
74                        new Object JavaDoc[] {roleName, descriptor.getName()}));
75         } else {
76             if (!oneFailed) {
77             oneFailed = true;
78             }
79             result.addErrorDetails(smh.getLocalString
80                        (getClass().getName() + ".failed",
81                         "Error: The security role name [ {0} ] not found within application [ {1} ]",
82                         new Object JavaDoc[] {roleName, descriptor.getName()}));
83         }
84         }
85         if (oneFailed) {
86         result.setStatus(Result.FAILED);
87         } else {
88         result.setStatus(Result.PASSED);
89         }
90     } else {
91         result.notApplicable(smh.getLocalString
92                  (getClass().getName() + ".notApplicable",
93                   "There are no role-name elements within the application [ {0} ]",
94                   new Object JavaDoc[] {descriptor.getName()}));
95     }
96
97     return result;
98     }
99 }
100
Popular Tags