public void addRole(GeoServerRole role) throws IOException{ Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("roles.insert", con); ps.setString(1,role.getAuthority()); //ps.setNull(2, Types.VARCHAR); ps.execute(); addRoleProperties(role, con); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
/** * Executes {@link Connection#commit()} and frees * the connection * @see org.geoserver.security.GeoServerRoleStore#store() */ public void store() throws IOException { // Simply commit the transaction try { getConnection().commit(); releaseConnection(); } catch (SQLException ex) { throw new IOException(ex); } setModified(false); }
public void testRoleDatabaseSetup() { try { JDBCRoleStore jdbcStore = (JDBCRoleStore) store; assertTrue(jdbcStore.tablesAlreadyCreated()); jdbcStore.checkDDLStatements(); jdbcStore.checkDMLStatements(); jdbcStore.clear(); jdbcStore.dropTables(); jdbcStore.store(); assertFalse(jdbcStore.tablesAlreadyCreated()); jdbcStore.load(); } catch (IOException ex) { Assert.fail(ex.getMessage()); } }
@Override public GeoServerRoleStore createStore(GeoServerRoleService service) throws IOException { JDBCRoleStore store = (JDBCRoleStore) super.createStore(service); try { JDBCTestSupport.dropExistingTables(store,store.getConnection()); } catch (SQLException e) { throw new IOException(e); } store.createTables(); store.store(); return store; }
public void initializeFromService(GeoServerRoleService service) throws IOException { JDBCRoleService jdbcService= (JDBCRoleService) service; this.name=service.getName(); this.adminRoleName=jdbcService.adminRoleName; this.groupAdminRoleName=jdbcService.groupAdminRoleName; this.datasource=jdbcService.datasource; this.ddlProps=jdbcService.ddlProps; this.dmlProps=jdbcService.dmlProps; this.securityManager=service.getSecurityManager(); try { getConnection().commit(); } catch (SQLException e) { throw new IOException(e); } } }
@Test public void testRoleDatabaseSetup() { try { JDBCRoleStore jdbcStore = (JDBCRoleStore) store; assertTrue(jdbcStore.tablesAlreadyCreated()); jdbcStore.checkDDLStatements(); jdbcStore.checkDMLStatements(); jdbcStore.clear(); jdbcStore.dropTables(); jdbcStore.store(); assertFalse(jdbcStore.tablesAlreadyCreated()); jdbcStore.load(); } catch (IOException ex) { Assert.fail(ex.getMessage()); } }
@Override public GeoServerRoleStore createStore(GeoServerRoleService service) throws IOException { JDBCRoleStore store = (JDBCRoleStore) super.createStore(service); try { JDBCTestSupport.dropExistingTables(store, store.getConnection()); } catch (SQLException e) { throw new IOException(e); } store.createTables(); store.store(); return store; }
@After public void dropExistingTables() throws Exception { if (store != null) { JDBCRoleStore jdbcStore = (JDBCRoleStore) store; JDBCTestSupport.dropExistingTables(jdbcStore, jdbcStore.getConnection()); store.store(); } }
/** * Executes {@link Connection#rollback() and * frees the connection object * * @see org.geoserver.security.jdbc.JDBCRoleService#load() */ public void load() throws IOException { // Simply roll back the transaction try { getConnection().rollback(); releaseConnection(); } catch (SQLException ex) { throw new IOException(ex); } setModified(false); }
public void associateRoleToUser(GeoServerRole role, String username) throws IOException{ Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("userroles.insert", con); ps.setString(1,role.getAuthority()); ps.setString(2,username); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
@Override public GeoServerRoleStore createStore(GeoServerRoleService service) throws IOException { JDBCRoleStore store = (JDBCRoleStore) super.createStore(service); try { JDBCTestSupport.dropExistingTables(store, store.getConnection()); } catch (SQLException e) { throw new IOException(e); } store.createTables(); store.store(); return store; }
@Override protected void tearDownInternal() throws Exception { super.tearDownInternal(); if (store!=null) { JDBCRoleStore jdbcStore =(JDBCRoleStore)store; JDBCTestSupport.dropExistingTables(jdbcStore,jdbcStore.getConnection()); store.store(); } }
public void associateRoleToGroup(GeoServerRole role, String groupname) throws IOException{ Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("grouproles.insert", con); ps.setString(1,role.getAuthority()); ps.setString(2,groupname); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
@Override public GeoServerRoleStore createStore(GeoServerRoleService service) throws IOException { JDBCRoleStore store = (JDBCRoleStore) super.createStore(service); try { JDBCTestSupport.dropExistingTables(store,store.getConnection()); } catch (SQLException e) { throw new IOException(e); } store.createTables(); store.store(); return store; }
@Override protected void tearDownInternal() throws Exception { super.tearDownInternal(); JDBCRoleStore rs = (JDBCRoleStore) roleStore; JDBCTestSupport.dropExistingTables(rs, rs.getConnection()); roleStore.store(); JDBCUserGroupStore ugs = (JDBCUserGroupStore) ugStore; JDBCTestSupport.dropExistingTables(ugs, ugs.getConnection()); ugStore.store(); }
public void disAssociateRoleFromGroup(GeoServerRole role, String groupname) throws IOException{ Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("grouproles.delete", con); ps.setString(1,role.getAuthority()); ps.setString(2,groupname); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
@Override public GeoServerRoleStore createStore(GeoServerRoleService service) throws IOException { JDBCRoleStore store = (JDBCRoleStore) super.createStore(service); try { JDBCTestSupport.dropExistingTables(store, store.getConnection()); } catch (SQLException e) { throw new IOException(e); } store.createTables(); store.store(); return store; }
@Override protected void tearDownInternal() throws Exception { super.tearDownInternal(); if (roleStore!=null) { JDBCRoleStore jdbcStore1 =(JDBCRoleStore) roleStore; JDBCTestSupport.dropExistingTables(jdbcStore1,jdbcStore1.getConnection()); roleStore.store(); } if (usergroupStore!=null) { JDBCUserGroupStore jdbcStore2 =(JDBCUserGroupStore) usergroupStore; JDBCTestSupport.dropExistingTables(jdbcStore2,jdbcStore2.getConnection()); usergroupStore.store(); } }
public void clear() throws IOException { Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("grouproles.deleteAll", con); ps.execute(); ps.close(); ps = getDMLStatement("userroles.deleteAll", con); ps.execute(); ps.close(); ps = getDMLStatement("roleprops.deleteAll", con); ps.execute(); ps.close(); ps = getDMLStatement("roles.deleteAll", con); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
@Override public GeoServerRoleStore createStore(GeoServerRoleService service) throws IOException { JDBCRoleStore store = (JDBCRoleStore) super.createStore(service); try { JDBCTestSupport.dropExistingTables(store,store.getConnection()); } catch (SQLException e) { throw new IOException(e); } store.createTables(); store.store(); return store; }