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());
}
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));
}
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) {
}
}
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
}
}
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) {
}
}
Aggregations