Search in sources :

Example 1 with DoNothingSecurityHelper

use of org.teiid.runtime.DoNothingSecurityHelper 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 2 with DoNothingSecurityHelper

use of org.teiid.runtime.DoNothingSecurityHelper in project teiid by teiid.

the class TestSessionServiceImpl method setup.

@Before
public void setup() {
    ssi = new SessionServiceImpl();
    ssi.setSecurityHelper(new DoNothingSecurityHelper());
}
Also used : DoNothingSecurityHelper(org.teiid.runtime.DoNothingSecurityHelper) Before(org.junit.Before)

Example 3 with DoNothingSecurityHelper

use of org.teiid.runtime.DoNothingSecurityHelper in project teiid by teiid.

the class TestLogonImpl method setup.

@Before
public void setup() {
    ssi = new SessionServiceImpl();
    ssi.setSecurityHelper(new DoNothingSecurityHelper() {

        @Override
        public Subject getSubjectInContext(String securityDomain) {
            if (securityDomain.equals("SC")) {
                return new Subject();
            }
            return null;
        }
    });
}
Also used : SessionServiceImpl(org.teiid.services.SessionServiceImpl) DoNothingSecurityHelper(org.teiid.runtime.DoNothingSecurityHelper) Subject(javax.security.auth.Subject) Before(org.junit.Before)

Example 4 with DoNothingSecurityHelper

use of org.teiid.runtime.DoNothingSecurityHelper in project teiid by teiid.

the class TestJDBCSocketAuthentication method oneTimeSetup.

@BeforeClass
public static void oneTimeSetup() throws Exception {
    SocketConfiguration config = new SocketConfiguration();
    config.setSSLConfiguration(new SSLConfiguration());
    addr = new InetSocketAddress(0);
    config.setBindAddress(addr.getHostName());
    config.setPortNumber(0);
    EmbeddedConfiguration dqpConfig = new EmbeddedConfiguration();
    dqpConfig.setMaxActivePlans(2);
    dqpConfig.setSecurityHelper(new DoNothingSecurityHelper() {

        @Override
        public Subject getSubjectInContext(Object context) {
            return null;
        }

        @Override
        public Subject getSubjectInContext(String securityDomain) {
            return null;
        }
    });
    server = new FakeServer(false);
    server.start(dqpConfig, false);
    server.deployVDB("parts", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
    jdbcTransport = new SocketListener(addr, config, server.getClientServiceRegistry(), BufferManagerFactory.getStandaloneBufferManager()) {

        @Override
        protected SSLAwareChannelHandler createChannelHandler() {
            SSLAwareChannelHandler result = new SSLAwareChannelHandler(this) {

                public void messageReceived(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception {
                    if (delay > 0) {
                        Thread.sleep(delay);
                    }
                    super.messageReceived(ctx, msg);
                }
            };
            return result;
        }
    };
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) InetSocketAddress(java.net.InetSocketAddress) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) DoNothingSecurityHelper(org.teiid.runtime.DoNothingSecurityHelper) Subject(javax.security.auth.Subject) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) BeforeClass(org.junit.BeforeClass)

Aggregations

DoNothingSecurityHelper (org.teiid.runtime.DoNothingSecurityHelper)4 Subject (javax.security.auth.Subject)3 Before (org.junit.Before)2 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)2 FileInputStream (java.io.FileInputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 Identity (java.security.Identity)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 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 FakeServer (org.teiid.jdbc.FakeServer)1 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)1 Column (org.teiid.metadata.Column)1 MetadataFactory (org.teiid.metadata.MetadataFactory)1 Table (org.teiid.metadata.Table)1