1 17 package org.apache.catalina.security; 18 19 import java.security.Security ; 20 import org.apache.catalina.startup.CatalinaProperties; 21 22 28 public final class SecurityConfig{ 29 private static SecurityConfig singleton = null; 30 31 private static org.apache.commons.logging.Log log= 32 org.apache.commons.logging.LogFactory.getLog( SecurityConfig.class ); 33 34 35 private final static String PACKAGE_ACCESS = "sun.," 36 + "org.apache.catalina." 37 + ",org.apache.jasper." 38 + ",org.apache.coyote." 39 + ",org.apache.tomcat."; 40 41 private final static String PACKAGE_DEFINITION= "java.,sun." 42 + ",org.apache.catalina." 43 + ",org.apache.coyote." 44 + ",org.apache.tomcat." 45 + ",org.apache.jasper."; 46 49 private String packageDefinition; 50 51 52 55 private String packageAccess; 56 57 58 61 private SecurityConfig(){ 62 try{ 63 packageDefinition = CatalinaProperties.getProperty("package.definition"); 64 packageAccess = CatalinaProperties.getProperty("package.access"); 65 } catch (java.lang.Exception ex){ 66 if (log.isDebugEnabled()){ 67 log.debug("Unable to load properties using CatalinaProperties", ex); 68 } 69 } 70 } 71 72 73 77 public static SecurityConfig newInstance(){ 78 if (singleton == null){ 79 singleton = new SecurityConfig(); 80 } 81 return singleton; 82 } 83 84 85 88 public void setPackageAccess(){ 89 if (packageAccess == null){ 91 setSecurityProperty("package.access", PACKAGE_ACCESS); 92 } else { 93 setSecurityProperty("package.access", packageAccess); 94 } 95 } 96 97 98 101 public void setPackageDefinition(){ 102 if (packageDefinition == null){ 104 setSecurityProperty("package.definition", PACKAGE_DEFINITION); 105 } else { 106 setSecurityProperty("package.definition", packageDefinition); 107 } 108 } 109 110 111 115 private final void setSecurityProperty(String properties, String packageList){ 116 if (System.getSecurityManager() != null){ 117 String definition = Security.getProperty(properties); 118 if( definition != null && definition.length() > 0 ){ 119 definition += ","; 120 } 121 122 Security.setProperty(properties, 123 definition + packageList); 126 } 127 } 128 129 130 } 131 132 133 134 135 | Popular Tags |