Package java.security

Examples of java.security.Policy$UnsupportedEmptyCollection


        final KeyStoreMetaData keyStore =
            new KeyStoreMetaData( "default", "http://spice.sourceforge.net", "DoDgY" );
        final PolicyMetaData metaData =
            new PolicyMetaData( new KeyStoreMetaData[]{keyStore}, new GrantMetaData[]{grant} );
        final TestResolver resolver = new TestResolver();
        final Policy policy = builder.buildPolicy( metaData, resolver );
        final CodeSource codesource =
            new CodeSource( new URL( "file:/" ), new Certificate[]{MockCertificate.JENNY_CERTIFICATE} );
        final PermissionCollection permissions = policy.getPermissions( codesource );
        final Enumeration enumeration = permissions.elements();
        while( enumeration.hasMoreElements() )
        {
            final Object perm = enumeration.nextElement();
            if( perm instanceof UnresolvedPermission )
View Full Code Here


{
   private PolicyConfiguration pc;

   public void testUncheckedExact() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = null;
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);

      WebResourcePermission wrp = new WebResourcePermission("/protected/exact/get/roleA", "GET");
      assertFalse("/protected/exact/get/roleA GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/protected/exact/get/roleA", "POST");
      assertFalse("/protected/exact/get/roleA POST", p.implies(pd, wrp));

      caller = new SimplePrincipal[]{new SimplePrincipal("RoleA")};
      wrp = new WebResourcePermission("/protected/exact/get/roleA", "GET");
      assertFalse("/protected/exact/get/roleA GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/protected/exact/get/roleA", "POST");
      assertFalse("/protected/exact/get/roleA POST", p.implies(pd, wrp));

      caller = new SimplePrincipal[]{new SimplePrincipal("RoleB")};
      pd = new ProtectionDomain(null, null, null, caller);
      wrp = new WebResourcePermission("/protected/exact/get/roleA", "GET");
      assertFalse("/protected/exact/get/roleA GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/protected/exact/get/roleA", "POST");
      assertTrue("/protected/exact/get/roleA POST", p.implies(pd, wrp));
   }
View Full Code Here

{
   private PolicyConfiguration pc;

   public void testUncheckedPrefix() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = null;
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);

      // There should be no
      WebResourcePermission wrp = new WebResourcePermission("/restricted/post-only/x", "GET");
      assertFalse("/restricted/post-only/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/post-only/x", "POST");
      assertFalse("/restricted/post-only/x POST", p.implies(pd, wrp));

      caller = new SimplePrincipal[]{new SimplePrincipal("PostRole")};
      pd = new ProtectionDomain(null, null, null, caller);
      wrp = new WebResourcePermission("/restricted/post-only/x", "GET");
      assertFalse("/restricted/post-only/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/post-only/x", "POST");
      assertTrue("/restricted/post-only/x POST", p.implies(pd, wrp));

   }
View Full Code Here

*/
public class DataWebConstraintsUnitTestCase extends TestCase
{
   public void testUncheckedExact() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = null;
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);

      WebResourcePermission wrp = new WebResourcePermission("/", "GET");
      assertTrue("/ GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/", "POST");
      assertTrue("/ POST", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/any", "POST");
      assertTrue("/any POST", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/", "DELETE");
      assertTrue("/any DELETE", p.implies(pd, wrp));

   }
View Full Code Here

{
   private PolicyConfiguration pc;

   public void testUnchecked() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = null;
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);
      // Test /unchecked
      WebResourcePermission wrp = new WebResourcePermission("/unchecked", "GET");
      assertTrue("/unchecked GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/unchecked/x", "GET");
      assertTrue("/unchecked/x GET", p.implies(pd, wrp));

      // Test the Unrestricted security-constraint
      wrp = new WebResourcePermission("/restricted/not", "GET");
      assertTrue("/restricted/not GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/not/x", "GET");
      assertTrue("/restricted/not/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/not/x", "HEAD");
      assertTrue("/restricted/not/x HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/not/x", "POST");
      assertTrue("/restricted/not/x POST", p.implies(pd, wrp));

      wrp = new WebResourcePermission("/", "GET");
      assertTrue("/ GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/other", "GET");
      assertTrue("/other GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/other", "HEAD");
      assertTrue("/other HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/other", "POST");
      assertTrue("/other POST", p.implies(pd, wrp));
   }
View Full Code Here

      assertTrue("/other POST", p.implies(pd, wrp));
   }

   public void testGetAccess() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = {new SimplePrincipal("GetRole")};
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);

      // Test the Restricted GET security-constraint
      WebResourcePermission wrp = new WebResourcePermission("/restricted/get-only", "GET");
      assertTrue("/restricted/get-only GET", p.implies(pd, wrp));

      wrp = new WebResourcePermission("/restricted/get-only/x", "GET");
      assertTrue("/restricted/get-only/x GET", p.implies(pd, wrp));

      // Test the Restricted ANY security-constraint
      wrp = new WebResourcePermission("/restricted/any/x", "GET");
      assertTrue("/restricted/any/x GET", p.implies(pd, wrp));

      // Test that a POST to the Restricted GET security-constraint fails
      wrp = new WebResourcePermission("/restricted/get-only/x", "POST");
      assertFalse("/restricted/get-only/x POST", p.implies(pd, wrp));

      // Test that Restricted POST security-constraint fails
      wrp = new WebResourcePermission("/restricted/post-only/x", "GET");
      assertFalse("/restricted/post-only/x GET", p.implies(pd, wrp));

      // Validate that the excluded subcontext if not accessible
      wrp = new WebResourcePermission("/restricted/get-only/excluded/x", "GET");
      assertFalse("/restricted/get-only/excluded/x GET", p.implies(pd, wrp));

      caller = new SimplePrincipal[]{new SimplePrincipal("OtherRole")};
      pd = new ProtectionDomain(null, null, null, caller);
      // Test the Restricted GET security-constraint
      wrp = new WebResourcePermission("/restricted/get-only", "GET");
      assertFalse("/restricted/get-only GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/get-only/x", "GET");
      assertFalse("/restricted/get-only/x GET", p.implies(pd, wrp));

      /* Test the Restricted ANY security-constraint. Note that this would be
      allowed by the non-JACC and standalone tomcat as they interpret the "*"
      role-name to mean any role while the JACC mapping simply replaces "*" with
      the web.xml security-role/role-name values.
      */
      wrp = new WebResourcePermission("/restricted/any/x", "GET");
      assertFalse("/restricted/any/x GET", p.implies(pd, wrp));
   }
View Full Code Here

   /** Test that the excluded paths are not accessible by anyone
    */
   public void testExcludedAccess() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = {new SimplePrincipal("GetRole")};
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);

      WebResourcePermission wrp = new WebResourcePermission("/excluded/x", "GET");
      assertFalse("/excluded/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/excluded/x", "OPTIONS");
      assertFalse("/excluded/x OPTIONS", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/excluded/x", "HEAD");
      assertFalse("/excluded/x HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/excluded/x", "POST");
      assertFalse("/excluded/x POST", p.implies(pd, wrp));

      wrp = new WebResourcePermission("/restricted/", "GET");
      assertFalse("/restricted/ GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/", "OPTIONS");
      assertFalse("/restricted/ OPTIONS", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/", "HEAD");
      assertFalse("/restricted/ HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/", "POST");
      assertFalse("/restricted/ POST", p.implies(pd, wrp));

      wrp = new WebResourcePermission("/restricted/get-only/excluded/x", "GET");
      assertFalse("/restricted/get-only/excluded/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/get-only/excluded/x", "OPTIONS");
      assertFalse("/restricted/get-only/excluded/x OPTIONS", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/get-only/excluded/x", "HEAD");
      assertFalse("/restricted/get-only/excluded/x HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/get-only/excluded/x", "POST");
      assertFalse("/restricted/get-only/excluded/x POST", p.implies(pd, wrp));

      wrp = new WebResourcePermission("/restricted/post-only/excluded/x", "GET");
      assertFalse("/restricted/post-only/excluded/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/post-only/excluded/x", "OPTIONS");
      assertFalse("/restricted/post-only/excluded/x OPTIONS", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/post-only/excluded/x", "HEAD");
      assertFalse("/restricted/post-only/excluded/x HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/post-only/excluded/x", "POST");
      assertFalse("/restricted/post-only/excluded/x POST", p.implies(pd, wrp));

      wrp = new WebResourcePermission("/restricted/any/excluded/x", "GET");
      assertFalse("/restricted/any/excluded/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/any/excluded/x", "OPTIONS");
      assertFalse("/restricted/any/excluded/x OPTIONS", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/any/excluded/x", "HEAD");
      assertFalse("/restricted/any/excluded/x HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/any/excluded/x", "POST");
      assertFalse("/restricted/any/excluded/x POST", p.implies(pd, wrp));
   }
View Full Code Here

   /** Test POSTs against URLs that only allows the POST method and required
    * the PostRole role
    */
   public void testPostAccess() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = {new SimplePrincipal("PostRole")};
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);

      WebResourcePermission wrp = new WebResourcePermission("/restricted/post-only/", "POST");
      assertTrue("/restricted/post-only/ POST", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/post-only/x", "POST");
      assertTrue("/restricted/post-only/x POST", p.implies(pd, wrp));

      // Test the Restricted ANY security-constraint
      wrp = new WebResourcePermission("/restricted/any/x", "POST");
      assertTrue("/restricted/any/x POST", p.implies(pd, wrp));

      // Validate that the excluded subcontext if not accessible
      wrp = new WebResourcePermission("/restricted/post-only/excluded/x", "POST");
      assertFalse("/restricted/post-only/excluded/x POST", p.implies(pd, wrp));

      // Test that a GET to the Restricted POST security-constraint fails
      wrp = new WebResourcePermission("/restricted/post-only/x", "GET");
      assertFalse("/restricted/post-only/excluded/x GET", p.implies(pd, wrp));
      // Test that Restricted POST security-constraint fails
      wrp = new WebResourcePermission("/restricted/get-only/x", "POST");
      assertFalse("/restricted/get-only/x POST", p.implies(pd, wrp));

      // Change to otherUser to test failure
      caller = new SimplePrincipal[]{new SimplePrincipal("OtherRole")};
      pd = new ProtectionDomain(null, null, null, caller);

      // Test the Restricted Post security-constraint
      wrp = new WebResourcePermission("/restricted/post-only", "POST");
      assertFalse("/restricted/post-only POST", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/post-only/x", "POST");
      assertFalse("/restricted/post-only/x POST", p.implies(pd, wrp));

   }
View Full Code Here

{
   private PolicyConfiguration pc;

   public void testUnchecked() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = null;
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);

      WebResourcePermission wrp = new WebResourcePermission("/a", "GET");
      assertTrue("/a GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/a", "POST");
      assertTrue("/a POST", p.implies(pd, wrp));

      caller = new SimplePrincipal[]{new SimplePrincipal("R1")};
      pd = new ProtectionDomain(null, null, null, caller);
      wrp = new WebResourcePermission("/a/x", "GET");
      assertTrue("/a/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/a/x", "POST");
      boolean implied = p.implies(pd, wrp);
      assertTrue("/a/x POST", implied);
      wrp = new WebResourcePermission("/b/x", "GET");
      assertTrue("/b/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/b/x", "POST");
      assertTrue("/b/x POST", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/b/x", "DELETE");
      assertFalse("/b/x DELETE", p.implies(pd, wrp));

      wrp = new WebResourcePermission("/a/x.asp", "GET");
      assertTrue("/a/x.asp GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/a/x.asp", "POST");
      assertTrue("/a/x.asp POST", p.implies(pd, wrp));

      WebUserDataPermission wudp = new WebUserDataPermission("/a/*:/a", "GET:CONFIDENTIAL");
      assertTrue("/a/*:/a GET:CONFIDENTIAL", p.implies(pd, wudp));
      wudp = new WebUserDataPermission("/a/*:/a", "GET:CONFIDENTIAL");
      assertTrue("/b/*:/b GET,POST:CONFIDENTIAL", p.implies(pd, wudp));
     
   }
View Full Code Here

{
   private PolicyConfiguration pc;

   public void testUncheckedPrefix() throws Exception
   {
      Policy p = Policy.getPolicy();
      SimplePrincipal[] caller = null;
      ProtectionDomain pd = new ProtectionDomain(null, null, null, caller);
      // Test /unchecked
      WebResourcePermission wrp = new WebResourcePermission("/unchecked", "GET");
      assertTrue("/unchecked GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/unchecked/x", "GET");
      assertTrue("/unchecked/x GET", p.implies(pd, wrp));

      // Test the Unrestricted security-constraint
      wrp = new WebResourcePermission("/restricted/not", "GET");
      assertTrue("/restricted/not GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/not/x", "GET");
      assertTrue("/restricted/not/x GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/not/x", "HEAD");
      assertTrue("/restricted/not/x HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/restricted/not/x", "POST");
      assertTrue("/restricted/not/x POST", p.implies(pd, wrp));

      wrp = new WebResourcePermission("/", "GET");
      assertTrue("/ GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/other", "GET");
      assertTrue("/other GET", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/other", "HEAD");
      assertTrue("/other HEAD", p.implies(pd, wrp));
      wrp = new WebResourcePermission("/other", "POST");
      assertTrue("/other POST", p.implies(pd, wrp));
   }
View Full Code Here

TOP

Related Classes of java.security.Policy$UnsupportedEmptyCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.