use of java.security.UnresolvedPermission in project jdk8u_jdk by JetBrains.
the class AccessorMethods method main.
public static void main(String[] args) throws Exception {
// set CA cert in chain
File f = new File(System.getProperty("test.src", "."), CA);
FileInputStream fis = new FileInputStream(f);
CertificateFactory fac = CertificateFactory.getInstance("X.509");
Certificate cacert = fac.generateCertificate(fis);
Certificate[] signercerts = new Certificate[4];
signercerts[1] = cacert;
signercerts[3] = cacert;
// set signer certs
f = new File(System.getProperty("test.src", "."), SIGNER1);
fis = new FileInputStream(f);
Certificate signer1 = fac.generateCertificate(fis);
signercerts[0] = signer1;
f = new File(System.getProperty("test.src", "."), SIGNER2);
fis = new FileInputStream(f);
Certificate signer2 = fac.generateCertificate(fis);
signercerts[2] = signer2;
UnresolvedPermission up = new UnresolvedPermission("type", "name", "actions", signercerts);
if (!up.getUnresolvedType().equals("type") || !up.getUnresolvedName().equals("name") || !up.getUnresolvedActions().equals("actions")) {
throw new SecurityException("Test 1 Failed");
}
Certificate[] certs = up.getUnresolvedCerts();
if (certs == null || certs.length != 2) {
throw new SecurityException("Test 2 Failed");
}
boolean foundSigner1 = false;
boolean foundSigner2 = false;
if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
foundSigner1 = true;
}
if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
foundSigner2 = true;
}
if (!foundSigner1 || !foundSigner2) {
throw new SecurityException("Test 3 Failed");
}
}
use of java.security.UnresolvedPermission in project jdk8u_jdk by JetBrains.
the class PolicyPermissions method addGrantEntry.
/**
* Add one policy entry to the vector.
*/
private void addGrantEntry(GrantEntry ge, KeyStore keyStore) {
if (debug != null) {
debug.println("Adding policy entry: ");
debug.println(" signedBy " + ge.signedBy);
debug.println(" codeBase " + ge.codeBase);
if (ge.principals != null) {
for (PrincipalEntry pppe : ge.principals) {
debug.println(" " + pppe.getPrincipalClass() + " " + pppe.getPrincipalName());
}
}
debug.println();
}
try {
CodeSource codesource = getCodeSource(ge, keyStore);
// skip if signedBy alias was unknown...
if (codesource == null)
return;
PolicyEntry entry = new PolicyEntry(codesource);
Enumeration<PermissionEntry> enum_ = ge.permissionElements();
while (enum_.hasMoreElements()) {
PermissionEntry pe = enum_.nextElement();
try {
// XXX special case PrivateCredentialPermission-SELF
Permission perm;
if (pe.permission.equals("javax.security.auth.PrivateCredentialPermission") && pe.name.endsWith(" self")) {
perm = getInstance(pe.permission, pe.name + " \"self\"", pe.action);
} else {
perm = getInstance(pe.permission, pe.name, pe.action);
}
entry.add(perm);
if (debug != null) {
debug.println(" " + perm);
}
} catch (ClassNotFoundException cnfe) {
Certificate[] certs;
if (pe.signedBy != null) {
certs = getCertificates(keyStore, pe.signedBy);
} else {
certs = null;
}
// a signer and found the keys for it.
if (certs != null || pe.signedBy == null) {
Permission perm = new UnresolvedPermission(pe.permission, pe.name, pe.action, certs);
entry.add(perm);
if (debug != null) {
debug.println(" " + perm);
}
}
} catch (java.lang.reflect.InvocationTargetException ite) {
System.err.println(AUTH_POLICY + rb.getString(".error.adding.Permission.") + pe.permission + rb.getString("SPACE") + ite.getTargetException());
} catch (Exception e) {
System.err.println(AUTH_POLICY + rb.getString(".error.adding.Permission.") + pe.permission + rb.getString("SPACE") + e);
}
}
policyEntries.addElement(entry);
} catch (Exception e) {
System.err.println(AUTH_POLICY + rb.getString(".error.adding.Entry.") + ge + rb.getString("SPACE") + e);
}
if (debug != null) {
debug.println();
}
}
use of java.security.UnresolvedPermission in project Bytecoder by mirkosertic.
the class PolicyPermissions method addGrantEntry.
/**
* Add one policy entry to the vector.
*/
private void addGrantEntry(GrantEntry ge, KeyStore keyStore) {
if (debug != null) {
debug.println("Adding policy entry: ");
debug.println(" signedBy " + ge.signedBy);
debug.println(" codeBase " + ge.codeBase);
if (ge.principals != null) {
for (PrincipalEntry pppe : ge.principals) {
debug.println(" " + pppe.getPrincipalClass() + " " + pppe.getPrincipalName());
}
}
debug.println();
}
try {
CodeSource codesource = getCodeSource(ge, keyStore);
// skip if signedBy alias was unknown...
if (codesource == null)
return;
PolicyEntry entry = new PolicyEntry(codesource);
Enumeration<PermissionEntry> enum_ = ge.permissionElements();
while (enum_.hasMoreElements()) {
PermissionEntry pe = enum_.nextElement();
try {
// XXX special case PrivateCredentialPermission-SELF
Permission perm;
if (pe.permission.equals("javax.security.auth.PrivateCredentialPermission") && pe.name.endsWith(" self")) {
perm = getInstance(pe.permission, pe.name + " \"self\"", pe.action);
} else {
perm = getInstance(pe.permission, pe.name, pe.action);
}
entry.add(perm);
if (debug != null) {
debug.println(" " + perm);
}
} catch (ClassNotFoundException cnfe) {
Certificate[] certs;
if (pe.signedBy != null) {
certs = getCertificates(keyStore, pe.signedBy);
} else {
certs = null;
}
// a signer and found the keys for it.
if (certs != null || pe.signedBy == null) {
Permission perm = new UnresolvedPermission(pe.permission, pe.name, pe.action, certs);
entry.add(perm);
if (debug != null) {
debug.println(" " + perm);
}
}
} catch (java.lang.reflect.InvocationTargetException ite) {
System.err.println(AUTH_POLICY + rb.getString(".error.adding.Permission.") + pe.permission + rb.getString("SPACE") + ite.getTargetException());
} catch (Exception e) {
System.err.println(AUTH_POLICY + rb.getString(".error.adding.Permission.") + pe.permission + rb.getString("SPACE") + e);
}
}
policyEntries.addElement(entry);
} catch (Exception e) {
System.err.println(AUTH_POLICY + rb.getString(".error.adding.Entry.") + ge + rb.getString("SPACE") + e);
}
if (debug != null) {
debug.println();
}
}
use of java.security.UnresolvedPermission in project ant by apache.
the class Permissions method createPermission.
private java.security.Permission createPermission(final Permissions.Permission permission) {
try {
// First add explicitly already resolved permissions will not be
// resolved when added as unresolved permission.
final Class<? extends java.security.Permission> clazz = Class.forName(permission.getClassName()).asSubclass(java.security.Permission.class);
final String name = permission.getName();
final String actions = permission.getActions();
final Constructor<? extends java.security.Permission> ctr = clazz.getConstructor(PARAMS);
return ctr.newInstance(name, actions);
} catch (final Exception e) {
// Let the UnresolvedPermission handle it.
return new UnresolvedPermission(permission.getClassName(), permission.getName(), permission.getActions(), null);
}
}
use of java.security.UnresolvedPermission in project scheduling by ow2-proactive.
the class ClientsPolicy method getPermissions.
@Override
public PermissionCollection getPermissions(final ProtectionDomain domain) {
try {
readLock.lock();
PermissionCollection permissions = new Permissions();
// Look up permissions
Principal[] principals = domain.getPrincipals();
boolean identityPrincipal = false;
if (principals != null) {
for (Principal principal : principals) {
if (principal instanceof IdentityPrincipal) {
identityPrincipal = true;
PermissionCollection pc = original.getPermissions(domain);
if (pc != null) {
Permission permission = new PrincipalPermission((IdentityPrincipal) principal);
// always adding identity permission
permissions.add(permission);
if (debug) {
// WARNING cannot use log4j as it may lead to recursive permission check
System.out.println(principal + " has " + permission);
}
for (Enumeration<Permission> en = pc.elements(); en.hasMoreElements(); ) {
permission = en.nextElement();
// boot class path, so they were not correctly resolved at JVM start up time
if (permission instanceof UnresolvedPermission) {
permission = resolvePermission((UnresolvedPermission) permission);
if (permission == null)
continue;
}
// For IdentityPrincipal org.ow2.proactive.permissions.AllPermissions must be used
if (!permission.getClass().isAssignableFrom(AllPermission.class)) {
if (debug) {
// WARNING cannot use log4j as it may lead to recursive permission check
System.out.println(principal + " has " + permission);
}
permissions.add(permission);
}
}
}
}
}
}
if (!identityPrincipal) {
return original.getPermissions(domain);
}
return permissions;
} finally {
readLock.unlock();
}
}
Aggregations