Search in sources :

Example 11 with Identity

use of java.security.Identity in project robovm by robovm.

the class IdentityTest method testAddCertificate2.

/**
     * verify addCertificate(Certificate certificate) adds a certificate for this identity.
     * if the identity does not have a public key, the identity's public key is set to be that specified in the certificate.
     */
public void testAddCertificate2() throws Exception {
    Identity i = new IdentityStub("iii");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null);
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    i.addCertificate(c1);
    assertSame(c1, i.certificates()[0]);
    assertSame(pk1, i.getPublicKey());
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) CertificateStub(org.apache.harmony.security.tests.support.CertificateStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity)

Example 12 with Identity

use of java.security.Identity in project teiid by teiid.

the class TestRowBasedSecurity method testSecurity.

@Test
public void testSecurity() throws Exception {
    es = new EmbeddedServer();
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    final Vector<Principal> v = new Vector<Principal>();
    v.add(new Identity("myrole") {
    });
    final Subject subject = new Subject();
    Group g = Mockito.mock(Group.class);
    Mockito.stub(g.getName()).toReturn("Roles");
    Mockito.stub(g.members()).toReturn((Enumeration) v.elements());
    subject.getPrincipals().add(g);
    ec.setSecurityHelper(new DoNothingSecurityHelper() {

        @Override
        public Subject getSubjectInContext(String securityDomain) {
            return subject;
        }

        @Override
        public Subject getSubjectInContext(Object context) {
            return subject;
        }
    });
    es.start(ec);
    HardCodedExecutionFactory hcef = new HardCodedExecutionFactory() {

        @Override
        public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
            Table t = metadataFactory.addTable("x");
            Column col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, t);
            metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, t);
            metadataFactory.addPermission("y", t, null, null, Boolean.TRUE, null, null, null, "col = 'a'", null);
            metadataFactory.addColumnPermission("y", col, null, null, null, null, "null", null);
            t = metadataFactory.addTable("y");
            col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, t);
            metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, t);
            metadataFactory.addPermission("z", t, null, null, null, null, null, null, "col = 'e'", null);
            Table v = metadataFactory.addTable("v");
            metadataFactory.addPermission("y", v, null, null, Boolean.TRUE, null, null, null, null, null);
            col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, v);
            metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, v);
            v.setTableType(Type.View);
            v.setVirtual(true);
            v.setSelectTransformation("/*+ cache(scope:session) */ select col, col2 from y");
        }

        @Override
        public boolean isSourceRequiredForMetadata() {
            return false;
        }
    };
    hcef.addData("SELECT x.col, x.col2 FROM x", Arrays.asList(Arrays.asList("a", "b"), Arrays.asList("c", "d")));
    hcef.addData("SELECT y.col, y.col2 FROM y", Arrays.asList(Arrays.asList("e", "f"), Arrays.asList("h", "g")));
    es.addTranslator("hc", hcef);
    es.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("roles-vdb.xml")));
    Connection c = es.getDriver().connect("jdbc:teiid:z;PassthroughAuthentication=true", null);
    Statement s = c.createStatement();
    ResultSet rs = s.executeQuery("select * from x");
    rs.next();
    // masking
    assertEquals(null, rs.getString(1));
    assertEquals("b", rs.getString(2));
    // row filter
    assertFalse(rs.next());
    rs.close();
    s = c.createStatement();
    rs = s.executeQuery("select lookup('myschema.x', 'col', 'col2', 'b')");
    rs.next();
    // global scoped
    assertEquals(null, rs.getString(1));
    s = c.createStatement();
    rs = s.executeQuery("select count(col2) from v where col is not null");
    rs.next();
    assertEquals(1, rs.getInt(1));
    // different session with different roles
    v.clear();
    c = es.getDriver().connect("jdbc:teiid:z;PassthroughAuthentication=true", null);
    s = c.createStatement();
    rs = s.executeQuery("select count(col2) from v where col is not null");
    rs.next();
    assertEquals(2, rs.getInt(1));
}
Also used : Group(java.security.acl.Group) Table(org.teiid.metadata.Table) Statement(java.sql.Statement) EmbeddedServer(org.teiid.runtime.EmbeddedServer) Connection(java.sql.Connection) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) DoNothingSecurityHelper(org.teiid.runtime.DoNothingSecurityHelper) Subject(javax.security.auth.Subject) FileInputStream(java.io.FileInputStream) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) ResultSet(java.sql.ResultSet) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Identity(java.security.Identity) Vector(java.util.Vector) Principal(java.security.Principal) Test(org.junit.Test)

Example 13 with Identity

use of java.security.Identity in project robovm by robovm.

the class Identity2Test method test_ConstructorLjava_lang_StringLjava_security_IdentityScope.

/**
     * java.security.Identity#Identity(java.lang.String,
     *        java.security.IdentityScope)
     */
public void test_ConstructorLjava_lang_StringLjava_security_IdentityScope() throws Exception {
    String nameNull = null;
    String[] str = { "test", "", "!@#$%^&*()", "identity name" };
    IdentityScopeSubclass iss = new IdentityScopeSubclass("name");
    IdentitySubclass is;
    for (int i = 0; i < str.length; i++) {
        try {
            is = new IdentitySubclass(str[i], new IdentityScopeSubclass());
            assertNotNull(is);
            assertTrue(is instanceof Identity);
        } catch (Exception e) {
            System.out.println(e);
            fail("Unexpected exception for parameter " + str[i]);
        }
    }
    try {
        is = new IdentitySubclass(nameNull, new IdentityScopeSubclass());
    } catch (NullPointerException npe) {
    } catch (Exception e) {
        fail("Incorrect exception " + e + " was thrown");
    }
    try {
        is = new IdentitySubclass("test", iss);
        is = new IdentitySubclass("test", iss);
        fail("KeyManagementException was not thrown");
    } catch (KeyManagementException expected) {
    }
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException) KeyManagementException(java.security.KeyManagementException)

Example 14 with Identity

use of java.security.Identity in project robovm by robovm.

the class IdentityScope2Test method test_addIdentityLjava_security_Identity.

/**
     * java.security.IdentityScope#addIdentity(java.security.Identity)
     */
public void test_addIdentityLjava_security_Identity() throws Exception {
    IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass());
    Identity id = new IdentitySubclass("id1");
    id.setPublicKey(getPubKey());
    sub.addIdentity(id);
    try {
        Identity id2 = new IdentitySubclass("id2");
        id2.setPublicKey(getPubKey());
        sub.addIdentity(id2);
        fail("KeyManagementException should have been thrown");
    } catch (KeyManagementException e) {
    // Expected
    }
}
Also used : IdentitySubclass(org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException)

Example 15 with Identity

use of java.security.Identity in project robovm by robovm.

the class IdentityScope2Test method test_getIdentityLjava_security_Principal.

/**
     * java.security.IdentityScope#getIdentity(java.security.Principal)
     */
public void test_getIdentityLjava_security_Principal() throws Exception {
    Identity id = new IdentitySubclass("principal name");
    id.setPublicKey(getPubKey());
    IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass());
    try {
        sub.getIdentity((java.security.Principal) null);
        fail("Test 1: NullPointerException expected.");
    } catch (NullPointerException expected) {
    }
    sub.addIdentity(id);
    Identity returnedId = sub.getIdentity(id);
    assertEquals("Test 2: Returned Identity not the same as the added one;", id, returnedId);
    Identity id2 = new IdentitySubclass("Another identity");
    id2.setPublicKey(getPubKey());
    assertNull("Test 3: Null value expected.", sub.getIdentity(id2));
    try {
        sub.getIdentity((java.security.Principal) null);
        fail("Test 4: NullPointerException expected.");
    } catch (NullPointerException expected) {
    }
}
Also used : IdentitySubclass(org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass) Identity(java.security.Identity)

Aggregations

Identity (java.security.Identity)23 IdentityStub (org.apache.harmony.security.tests.support.IdentityStub)13 IdentitySubclass (org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass)8 PublicKeyStub (org.apache.harmony.security.tests.support.PublicKeyStub)7 KeyManagementException (java.security.KeyManagementException)5 CertificateStub (org.apache.harmony.security.tests.support.CertificateStub)4 PublicKey (java.security.PublicKey)3 IdentityScope (java.security.IdentityScope)2 FileInputStream (java.io.FileInputStream)1 Principal (java.security.Principal)1 Group (java.security.acl.Group)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Vector (java.util.Vector)1 Subject (javax.security.auth.Subject)1 IdentityScopeSubclass (org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass)1 Test (org.junit.Test)1 Column (org.teiid.metadata.Column)1 MetadataFactory (org.teiid.metadata.MetadataFactory)1