java.security.BasicPermission Java Examples

The following examples show how to use java.security.BasicPermission. 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
Source File: ProtectedResource.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/scope")
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<Permission>> hasScopePermission(@QueryParam("scope") String scope) {
    return identity.checkPermission(new BasicPermission("Scope Permission Resource") {
        @Override
        public String getActions() {
            return scope;
        }
    }).onItem()
            .apply(new Function<Boolean, List<Permission>>() {
                @Override
                public List<Permission> apply(Boolean granted) {
                    if (granted) {
                        return identity.getAttribute("permissions");
                    }
                    throw new ForbiddenException();
                }
            });
}
 
Example #2
Source File: ExitVMEquals.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #3
Source File: FailureDebugOption.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #4
Source File: ExitVMEquals.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #5
Source File: FailureDebugOption.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #6
Source File: ExitVMEquals.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #7
Source File: FailureDebugOption.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #8
Source File: ExitVMEquals.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #9
Source File: FailureDebugOption.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: ExitVMEquals.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #11
Source File: FailureDebugOption.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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 #12
Source File: ExitVMEquals.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #13
Source File: FailureDebugOption.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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 #14
Source File: ExitVMEquals.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #15
Source File: FailureDebugOption.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: ExitVMEquals.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #17
Source File: FailureDebugOption.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: ExitVMEquals.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #19
Source File: FailureDebugOption.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 #20
Source File: ExitVMEquals.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #21
Source File: FailureDebugOption.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #22
Source File: ExitVMEquals.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #23
Source File: FailureDebugOption.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 #24
Source File: ExitVMEquals.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #25
Source File: FailureDebugOption.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 #26
Source File: ExitVMEquals.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
Example #27
Source File: FailureDebugOption.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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) {
     }
}