public void clear() throws IOException { Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("groupmembers.deleteAll", con); ps.execute(); ps.close(); ps = getDMLStatement("groups.deleteAll", con); ps.execute(); ps.close(); ps = getDMLStatement("userprops.deleteAll", con); ps.execute(); ps.close(); ps = getDMLStatement("users.deleteAll", con); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); } /**
public boolean removeUser(GeoServerUser user) throws IOException { Connection con = null; PreparedStatement ps = null; boolean retval = false; try { con = getConnection(); ps = getDMLStatement("users.delete", con); ps.setString(1,user.getUsername()); ps.execute(); retval= ps.getUpdateCount()>0; ps.close(); ps = getDMLStatement("userprops.deleteForUser",con); ps.setString(1,user.getUsername()); ps.execute(); ps.close(); ps = getDMLStatement("groupmembers.deleteUser", con); ps.setString(1,user.getUsername()); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); return retval; }
public boolean removeGroup(GeoServerUserGroup group) throws IOException { Connection con = null; PreparedStatement ps = null; boolean retval=false; try { con = getConnection(); ps = getDMLStatement("groups.delete", con); ps.setString(1,group.getGroupname()); ps.execute(); retval = ps.getUpdateCount()>0; ps.close(); ps = getDMLStatement("groupmembers.deleteGroup", con); ps.setString(1,group.getGroupname()); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); return retval; }
public void associateUserToGroup(GeoServerUser user, GeoServerUserGroup group) throws IOException { Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("groupmembers.insert", con); ps.setString(1,group.getGroupname()); ps.setString(2,user.getUsername()); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
/** * Helper method for inserting user properties * * @param user * @param con * @throws SQLException * @throws IOException */ protected void addUserProperties(GeoServerUser user, Connection con) throws SQLException,IOException { if (user.getProperties().size()==0) return; // nothing to do PreparedStatement ps = getDMLStatement("userprops.insert", con); try { for (Object key : user.getProperties().keySet()) { Object propertyVal = user.getProperties().get(key); ps.setString(1,user.getUsername()); ps.setString(2,key.toString()); ps.setObject(3,propertyVal); ps.execute(); } } finally { closeFinally(null, ps, null); } }
public void disAssociateUserFromGroup(GeoServerUser user, GeoServerUserGroup group) throws IOException { Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("groupmembers.delete", con); ps.setString(1,group.getGroupname()); ps.setString(2,user.getUsername()); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
public void addGroup(GeoServerUserGroup group) throws IOException { Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("groups.insert", con); ps.setString(1,group.getGroupname()); ps.setString(2,convertToString(group.isEnabled())); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
public void updateGroup(GeoServerUserGroup group) throws IOException { Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("groups.update", con); ps.setString(1,convertToString(group.isEnabled())); ps.setString(2,group.getGroupname()); ps.execute(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
public void updateUser(GeoServerUser user) throws IOException,PasswordPolicyException { preparePassword(user); Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("users.update", con); ps.setString(1,user.getPassword()); ps.setString(2,convertToString(user.isEnabled())); ps.setString(3,user.getUsername()); ps.execute(); ps.close(); ps = getDMLStatement("userprops.deleteForUser",con); ps.setString(1,user.getUsername()); ps.execute(); addUserProperties(user, con); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }
public void addUser(GeoServerUser user) throws IOException, PasswordPolicyException { preparePassword(user); Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = getDMLStatement("users.insert", con); ps.setString(1,user.getUsername()); if (user.getPassword() != null) { ps.setString(2,user.getPassword()); } else { ps.setNull(2, Types.VARCHAR); } ps.setString(3,convertToString(user.isEnabled())); ps.execute(); addUserProperties(user, con); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } setModified(true); }