28import java.security.AllPermission;
29import java.security.CodeSource;
30import java.security.Permission;
31import java.security.PrivilegedAction;
32import java.security.ProtectionDomain;
33import java.security.cert.Certificate;
35import org.jau.sys.PlatformProps;
38 @SuppressWarnings(
"removal")
39 private static final SecurityManager securityManager;
40 private static final Permission allPermissions;
41 private static final boolean DEBUG =
false;
53 @SuppressWarnings({
"deprecation",
"removal" })
58 return System.getSecurityManager();
75 @SuppressWarnings({
"deprecation",
"removal" })
80 return java.security.AccessController.doPrivileged( o );
85 allPermissions =
new AllPermission();
91 final ProtectionDomain insecPD =
doPrivileged(
new PrivilegedAction<ProtectionDomain>() {
93 public ProtectionDomain run() {
96 boolean _hasAllPermissions;
98 insecPD.implies(allPermissions);
99 _hasAllPermissions =
true;
100 }
catch(
final SecurityException ace ) {
101 _hasAllPermissions =
false;
106 System.err.println(
"SecurityUtil: Has SecurityManager: "+ (
null != securityManager ) ) ;
108 final Certificate[] certs =
doPrivileged(
new PrivilegedAction<Certificate[]>() {
110 public Certificate[] run() {
111 return getCerts(SecurityUtil.class);
113 System.err.println(
"SecurityUtil: Cert count: "+ (
null != certs ? certs.length : 0 ));
114 if(
null != certs ) {
115 for(
int i=0; i<certs.length; i++) {
116 System.err.println(
"\t cert["+i+
"]: "+certs[i].toString());
140 }
catch(
final SecurityException ace ) {
157 @SuppressWarnings({
"deprecation",
"removal" })
158 public static final void checkPermission(
final Permission perm)
throws SecurityException {
159 if(
null != securityManager ) {
160 securityManager.checkPermission(perm);
173 }
catch(
final SecurityException ace ) {
182 @SuppressWarnings({
"deprecation",
"removal" })
184 if(
null != securityManager ) {
185 securityManager.checkLink(libName);
193 @SuppressWarnings({
"deprecation",
"removal" })
195 if(
null != securityManager ) {
196 securityManager.checkPermission(allLinkPermission);
199 private static final RuntimePermission allLinkPermission =
new RuntimePermission(
"loadLibrary.*");
206 public static final Certificate[]
getCerts(
final Class<?> clz)
throws SecurityException {
207 final ProtectionDomain pd = clz.getProtectionDomain();
208 final CodeSource cs = (
null != pd) ? pd.getCodeSource() :
null;
209 final Certificate[] certs = (
null != cs) ? cs.getCertificates() :
null;
210 return (
null != certs && certs.length>0) ? certs :
null;
213 public static final boolean equals(
final Certificate[] a,
final Certificate[] b) {
217 if(a==
null || b==
null) {
220 if(a.length != b.length) {
225 while( i < a.length && a[i].equals(b[i]) ) {
228 return i == a.length;
static final boolean hasPermission(final Permission perm)
Returns true if no SecurityManager has been installed or the installed SecurityManager's checkPermiss...
static final SecurityManager getSecurityManager()
Call wrapper for System#getSecurityManager().
static final boolean hasLinkPermission(final String libName)
Returns true if no SecurityManager has been installed or the installed SecurityManager's checkLink(li...
static final void checkPermission(final Permission perm)
Throws an SecurityException if an installed SecurityManager does not permit the requested Permission.
static final void checkLinkPermission(final String libName)
Throws an SecurityException if an installed SecurityManager does not permit to dynamically link the g...
static final void checkAllLinkPermission()
Throws an SecurityException if an installed SecurityManager does not permit to dynamically link to al...
static final boolean hasAllPermissions()
Returns true if no SecurityManager has been installed or the installed SecurityManager's checkPermiss...
static final Certificate[] getCerts(final Class<?> clz)
static final boolean equals(final Certificate[] a, final Certificate[] b)
static< T > T doPrivileged(final PrivilegedAction< T > o)
Call wrapper for java.security.AccessController#doPrivileged(PrivilegedAction).
static final void checkAllPermissions()
Throws an SecurityException if an installed SecurityManager does not permit the requested AllPermissi...