Package org.codehaus.loom.xmlpolicy.builder

Examples of org.codehaus.loom.xmlpolicy.builder.PolicyBuilder


        throws Exception
    {
        final SarPolicyResolver resolver = new SarPolicyResolver(
            baseDirectory, workDirectory );
        setupLogger( resolver );
        final PolicyBuilder builder = new PolicyBuilder();
        final PolicyReader reader = new PolicyReader();
        final SarPolicyVerifier verifier = new SarPolicyVerifier();
        setupLogger( verifier );

        final Element element = ConfigurationUtil.toElement( configuration );
        final HashMap newData = new HashMap();
        newData.putAll( m_data );
        newData.putAll( data );
        newData.put( "/", File.separator );

        m_expander.expandValues( element, newData );

        element.setAttribute( "version", "1.0" );
        try
        {
            final PolicyMetaData policy = reader.readPolicy( element );
            verifier.verifyPolicy( policy );
            return builder.buildPolicy( policy, resolver );
        }
        catch( final Exception e )
        {
            throw new ConfigurationException( e.getMessage(), e );
        }
View Full Code Here


    }

    public void testEmptyMetaData()
        throws Exception
    {
        final PolicyBuilder builder = new PolicyBuilder();
        final PolicyMetaData metaData =
            new PolicyMetaData( new KeyStoreMetaData[ 0 ], new GrantMetaData[ 0 ] );
        final TestResolver resolver = new TestResolver();
        try
        {
            final Policy policy = builder.buildPolicy( metaData, resolver );
            final PermissionCollection permissions =
                policy.getPermissions( new CodeSource( null, new Certificate[ 0 ] ) );
            assertEquals( "Expect no permissions for empty metaData",
                          false,
                          permissions.elements().hasMoreElements() );
View Full Code Here

    }

    public void testNullResolverInBuildPolicy()
        throws Exception
    {
        final PolicyBuilder builder = new PolicyBuilder();
        final PolicyMetaData metaData =
            new PolicyMetaData( new KeyStoreMetaData[ 0 ], new GrantMetaData[ 0 ] );
        try
        {
            builder.buildPolicy( metaData, null );
            fail( "Expected to fail due to null pointer in buildPolicy" );
        }
        catch( final NullPointerException npe )
        {
            assertEquals( "NPE message",
View Full Code Here

    }

    public void testNullMetaDataInBuildPolicy()
        throws Exception
    {
        final PolicyBuilder builder = new PolicyBuilder();
        try
        {
            builder.buildPolicy( null, new TestResolver() );
            fail( "Expected to fail due to null pointer in buildPolicy" );
        }
        catch( final NullPointerException npe )
        {
            assertEquals( "NPE message",
View Full Code Here

    }

    public void testMetaDataWithAPermission()
        throws Exception
    {
        final PolicyBuilder builder = new PolicyBuilder();
        final PermissionMetaData permission =
            new PermissionMetaData( AllPermission.class.getName(), null, null, null, null );
        final GrantMetaData grant =
            new GrantMetaData( "file:/", null, null,
                               new PermissionMetaData[]{permission} );
        final PolicyMetaData metaData =
            new PolicyMetaData( new KeyStoreMetaData[ 0 ], new GrantMetaData[]{grant} );
        final TestResolver resolver = new TestResolver();
        try
        {
            final Policy policy = builder.buildPolicy( metaData, resolver );
            final CodeSource codesource =
                new CodeSource( new URL( "file:/" ), new Certificate[ 0 ] );
            final PermissionCollection permissions = policy.getPermissions( codesource );
            final Enumeration enumeration = permissions.elements();
            while( enumeration.hasMoreElements() )
View Full Code Here

    }

    public void testMetaDataWithAPermissionAndCerts()
        throws Exception
    {
        final PolicyBuilder builder = new TestPolicyBuilder();
        final PermissionMetaData permission =
            new PermissionMetaData( FilePermission.class.getName(), "/", "read",
                                    null, null );
        final GrantMetaData grant =
            new GrantMetaData( "file:/", "jenny", "default",
                               new PermissionMetaData[]{permission} );
        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() )
View Full Code Here

    }

    public void testMetaDataWithAPermissionAndMultipleCerts()
        throws Exception
    {
        final PolicyBuilder builder = new TestPolicyBuilder();
        final PermissionMetaData permission =
            new PermissionMetaData( RuntimePermission.class.getName(), "getFactory", null,
                                    null, null );
        final GrantMetaData grant =
            new GrantMetaData( "file:/", "jenny,mischelle,jenny", "default",
                               new PermissionMetaData[]{permission} );
        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() )
View Full Code Here

    }

    public void testMetaDataWithAPermissionAndCertsAndUnResolverPerm()
        throws Exception
    {
        final PolicyBuilder builder = new TestPolicyBuilder();
        final PermissionMetaData permission =
            new PermissionMetaData( AllPermission.class.getName(), null, null,
                                    "jenny", "default" );
        final GrantMetaData grant =
            new GrantMetaData( "file:/", "jenny", "default",
                               new PermissionMetaData[]{permission} );
        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() )
View Full Code Here

    }

    public void testMetaDataWithAPermissionAndCertsAndMisnamedPerm()
        throws Exception
    {
        final PolicyBuilder builder = new TestPolicyBuilder();
        final PermissionMetaData permission =
            new PermissionMetaData( AllPermission.class.getName() + "sss", null, null,
                                    null, null );
        final GrantMetaData grant =
            new GrantMetaData( "file:/", "jenny", "default",
                               new PermissionMetaData[]{permission} );
        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() )
View Full Code Here

    }

    public void testFailureWhenCreatingKeyStore()
        throws Exception
    {
        final PolicyBuilder builder = new TestPolicyBuilder();
        final PermissionMetaData permission =
            new PermissionMetaData( AllPermission.class.getName() + "sss", null, null,
                                    null, null );
        final GrantMetaData grant =
            new GrantMetaData( "file:/", "jenny", "default",
                               new PermissionMetaData[]{permission} );
        final KeyStoreMetaData keyStore =
            new KeyStoreMetaData( "default", "http://spice.sourceforge.net/NoExist", "DoDgY" );
        final PolicyMetaData metaData =
            new PolicyMetaData( new KeyStoreMetaData[]{keyStore}, new GrantMetaData[]{grant} );
        final TestResolver resolver = new TestResolver();
        try
        {
            builder.buildPolicy( metaData, resolver );
            fail( "Expected to fail when creating policy as unable to create store" );
        }
        catch( Exception e )
        {
        }
View Full Code Here

TOP

Related Classes of org.codehaus.loom.xmlpolicy.builder.PolicyBuilder

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.