Java Code Examples for java.security.AccessController#checkPermission()

The following examples show how to use java.security.AccessController#checkPermission() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Check if the connector server creator can assume the identity of each
 * principal in the authenticated subject, i.e. check if the connector
 * server creator codebase contains a subject delegation permission for
 * each principal present in the authenticated subject.
 *
 * @return {@code true} if the connector server creator can delegate to all
 * the authenticated principals in the subject. Otherwise, {@code false}.
 */
public static synchronized boolean
    checkRemoveCallerContext(Subject subject) {
    try {
        for (Principal p : getSubjectPrincipals(subject)) {
            final String pname =
                p.getClass().getName() + "." + p.getName();
            final Permission sdp =
                new SubjectDelegationPermission(pname);
            AccessController.checkPermission(sdp);
        }
    } catch (SecurityException e) {
        return false;
    }
    return true;
}
 
Example 2
/**
 * Check if the connector server creator can assume the identity of each
 * principal in the authenticated subject, i.e. check if the connector
 * server creator codebase contains a subject delegation permission for
 * each principal present in the authenticated subject.
 *
 * @return {@code true} if the connector server creator can delegate to all
 * the authenticated principals in the subject. Otherwise, {@code false}.
 */
public static synchronized boolean
    checkRemoveCallerContext(Subject subject) {
    try {
        for (Principal p : getSubjectPrincipals(subject)) {
            final String pname =
                p.getClass().getName() + "." + p.getName();
            final Permission sdp =
                new SubjectDelegationPermission(pname);
            AccessController.checkPermission(sdp);
        }
    } catch (SecurityException e) {
        return false;
    }
    return true;
}
 
Example 3
public static void main(String args[]) throws Throwable {
    // ExtensiblePolicyTest1.policy: policy file grants permission to
    // watch TVChannel 3-6
    // ExtensiblePolicyTest2.policy: policy file grants permission to
    // watch TVChanel 4
    // ExtensiblePolicyTest3.policy: policy file grants permission signed
    // by duke2 to watch TVChanel 5

    TVPermission perm = new TVPermission("channel:5", "watch");
    boolean getException = false;
    String exceptionMessage = null;
    boolean expectException = Boolean.parseBoolean(args[0]);
    try {
        AccessController.checkPermission(perm);
    } catch (SecurityException se) {
        getException = true;
        exceptionMessage = se.getMessage();
    }

    if (expectException ^ getException) {
        throw new RuntimeException("Test Failed: expectException = "
                + expectException + " getException = " + getException
                + "\n" + exceptionMessage);
    }
}
 
Example 4
/**
 * Check if the connector server creator can assume the identity of each
 * principal in the authenticated subject, i.e. check if the connector
 * server creator codebase contains a subject delegation permission for
 * each principal present in the authenticated subject.
 *
 * @return {@code true} if the connector server creator can delegate to all
 * the authenticated principals in the subject. Otherwise, {@code false}.
 */
public static synchronized boolean
    checkRemoveCallerContext(Subject subject) {
    try {
        for (Principal p : getSubjectPrincipals(subject)) {
            final String pname =
                p.getClass().getName() + "." + p.getName();
            final Permission sdp =
                new SubjectDelegationPermission(pname);
            AccessController.checkPermission(sdp);
        }
    } catch (SecurityException e) {
        return false;
    }
    return true;
}
 
Example 5
public static void main(String args[]) throws Throwable {
    // ExtensiblePolicyTest1.policy: policy file grants permission to
    // watch TVChannel 3-6
    // ExtensiblePolicyTest2.policy: policy file grants permission to
    // watch TVChanel 4
    // ExtensiblePolicyTest3.policy: policy file grants permission signed
    // by duke2 to watch TVChanel 5

    TVPermission perm = new TVPermission("channel:5", "watch");
    boolean getException = false;
    String exceptionMessage = null;
    boolean expectException = Boolean.parseBoolean(args[0]);
    try {
        AccessController.checkPermission(perm);
    } catch (SecurityException se) {
        getException = true;
        exceptionMessage = se.getMessage();
    }

    if (expectException ^ getException) {
        throw new RuntimeException("Test Failed: expectException = "
                + expectException + " getException = " + getException
                + "\n" + exceptionMessage);
    }
}
 
Example 6
/**
 * Check if the connector server creator can assume the identity of each
 * principal in the authenticated subject, i.e. check if the connector
 * server creator codebase contains a subject delegation permission for
 * each principal present in the authenticated subject.
 *
 * @return {@code true} if the connector server creator can delegate to all
 * the authenticated principals in the subject. Otherwise, {@code false}.
 */
public static synchronized boolean
    checkRemoveCallerContext(Subject subject) {
    try {
        for (Principal p : getSubjectPrincipals(subject)) {
            final String pname =
                p.getClass().getName() + "." + p.getName();
            final Permission sdp =
                new SubjectDelegationPermission(pname);
            AccessController.checkPermission(sdp);
        }
    } catch (SecurityException e) {
        return false;
    }
    return true;
}
 
Example 7
public static void main(String args[]) throws Throwable {
    // ExtensiblePolicyTest1.policy: policy file grants permission to
    // watch TVChannel 3-6
    // ExtensiblePolicyTest2.policy: policy file grants permission to
    // watch TVChanel 4
    // ExtensiblePolicyTest3.policy: policy file grants permission signed
    // by duke2 to watch TVChanel 5

    TVPermission perm = new TVPermission("channel:5", "watch");
    boolean getException = false;
    String exceptionMessage = null;
    boolean expectException = Boolean.parseBoolean(args[0]);
    try {
        AccessController.checkPermission(perm);
    } catch (SecurityException se) {
        getException = true;
        exceptionMessage = se.getMessage();
    }

    if (expectException ^ getException) {
        throw new RuntimeException("Test Failed: expectException = "
                + expectException + " getException = " + getException
                + "\n" + exceptionMessage);
    }
}
 
Example 8
Source Project: JDKSourceCode1.8   File: SubjectDelegator.java    License: MIT License 6 votes vote down vote up
/**
 * Check if the connector server creator can assume the identity of each
 * principal in the authenticated subject, i.e. check if the connector
 * server creator codebase contains a subject delegation permission for
 * each principal present in the authenticated subject.
 *
 * @return {@code true} if the connector server creator can delegate to all
 * the authenticated principals in the subject. Otherwise, {@code false}.
 */
public static synchronized boolean
    checkRemoveCallerContext(Subject subject) {
    try {
        for (Principal p : getSubjectPrincipals(subject)) {
            final String pname =
                p.getClass().getName() + "." + p.getName();
            final Permission sdp =
                new SubjectDelegationPermission(pname);
            AccessController.checkPermission(sdp);
        }
    } catch (SecurityException e) {
        return false;
    }
    return true;
}
 
Example 9
public static void main (String argv[]) throws Exception {
     try {
         AccessController.checkPermission(
                     new BasicPermission("no such permission"){});
     } catch (NullPointerException npe) {
        throw new Exception("Unexpected NullPointerException for security" +
                     " debug option, -Djava.security.debug=failure");
     } catch (AccessControlException ace) {
     }
}
 
Example 10
public AccessControlContext
    delegatedContext(AccessControlContext authenticatedACC,
                     Subject delegatedSubject,
                     boolean removeCallerContext)
        throws SecurityException {

    if (System.getSecurityManager() != null && authenticatedACC == null) {
        throw new SecurityException("Illegal AccessControlContext: null");
    }

    // Check if the subject delegation permission allows the
    // authenticated subject to assume the identity of each
    // principal in the delegated subject
    //
    Collection<Principal> ps = getSubjectPrincipals(delegatedSubject);
    final Collection<Permission> permissions = new ArrayList<>(ps.size());
    for(Principal p : ps) {
        final String pname = p.getClass().getName() + "." + p.getName();
        permissions.add(new SubjectDelegationPermission(pname));
    }
    PrivilegedAction<Void> action =
        new PrivilegedAction<Void>() {
            public Void run() {
                for (Permission sdp : permissions) {
                    AccessController.checkPermission(sdp);
                }
                return null;
            }
        };
    AccessController.doPrivileged(action, authenticatedACC);

    return getDelegatedAcc(delegatedSubject, removeCallerContext);
}
 
Example 11
public static void main(String args[]) {
    TVPermission perm = new TVPermission("channel:5", "watch");
    try {
        AccessController.checkPermission(perm);
    } catch (SecurityException se) {
        throw new RuntimeException(se);
    }
}
 
Example 12
public static void main (String argv[]) throws Exception {
     try {
         AccessController.checkPermission(
                     new BasicPermission("no such permission"){});
     } catch (NullPointerException npe) {
        throw new Exception("Unexpected NullPointerException for security" +
                     " debug option, -Djava.security.debug=failure");
     } catch (AccessControlException ace) {
     }
}
 
Example 13
public AccessControlContext
    delegatedContext(AccessControlContext authenticatedACC,
                     Subject delegatedSubject,
                     boolean removeCallerContext)
        throws SecurityException {

    if (System.getSecurityManager() != null && authenticatedACC == null) {
        throw new SecurityException("Illegal AccessControlContext: null");
    }

    // Check if the subject delegation permission allows the
    // authenticated subject to assume the identity of each
    // principal in the delegated subject
    //
    Collection<Principal> ps = getSubjectPrincipals(delegatedSubject);
    final Collection<Permission> permissions = new ArrayList<>(ps.size());
    for(Principal p : ps) {
        final String pname = p.getClass().getName() + "." + p.getName();
        permissions.add(new SubjectDelegationPermission(pname));
    }
    PrivilegedAction<Void> action =
        new PrivilegedAction<Void>() {
            public Void run() {
                for (Permission sdp : permissions) {
                    AccessController.checkPermission(sdp);
                }
                return null;
            }
        };
    AccessController.doPrivileged(action, authenticatedACC);

    return getDelegatedAcc(delegatedSubject, removeCallerContext);
}
 
Example 14
public static void main(String args[]) {
    TVPermission perm = new TVPermission("channel:5", "watch");
    try {
        AccessController.checkPermission(perm);
    } catch (SecurityException se) {
        throw new RuntimeException(se);
    }
}
 
Example 15
public static void main (String argv[]) throws Exception {
     try {
         AccessController.checkPermission(
                     new BasicPermission("no such permission"){});
     } catch (NullPointerException npe) {
        throw new Exception("Unexpected NullPointerException for security" +
                     " debug option, -Djava.security.debug=failure");
     } catch (AccessControlException ace) {
     }
}
 
Example 16
public static void main(String args[]) {
    TVPermission perm = new TVPermission("channel:5", "watch");
    try {
        AccessController.checkPermission(perm);
    } catch (SecurityException se) {
        throw new RuntimeException(se);
    }
}
 
Example 17
public static void main (String argv[]) throws Exception {
     try {
         AccessController.checkPermission(
                     new BasicPermission("no such permission"){});
     } catch (NullPointerException npe) {
        throw new Exception("Unexpected NullPointerException for security" +
                     " debug option, -Djava.security.debug=failure");
     } catch (AccessControlException ace) {
     }
}
 
Example 18
@Override public Void run() {
    AccessController.checkPermission(permission);
    return null;
}
 
Example 19
@Override public Void run() {
    AccessController.checkPermission(permission);
    return null;
}
 
Example 20
@Override public Void run() {
    AccessController.checkPermission(permission);
    return null;
}