summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-06-14 16:18:42 +0200
committerSimon Rettberg2018-06-14 16:18:42 +0200
commitade450e19527dbf377d945ca7bae7a145cf44196 (patch)
treeaa6098a0a6b907fd39b3ca7591b9fe8670b08567
parent[server] Don't wipe network shares if client didn't set field (diff)
downloadtutor-module-ade450e19527dbf377d945ca7bae7a145cf44196.tar.gz
tutor-module-ade450e19527dbf377d945ca7bae7a145cf44196.tar.xz
tutor-module-ade450e19527dbf377d945ca7bae7a145cf44196.zip
Add support for LDAP lecture filters
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LdapFilterConfigurator.java214
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java24
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java17
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java20
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java1
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java36
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java15
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java75
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserEntryXml.java19
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserListXml.java2
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/XmlFilterEntry.java21
11 files changed, 436 insertions, 8 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LdapFilterConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LdapFilterConfigurator.java
new file mode 100644
index 00000000..7028deb1
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LdapFilterConfigurator.java
@@ -0,0 +1,214 @@
+package org.openslx.dozmod.gui.control;
+
+import java.awt.GridBagConstraints;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.LdapFilter;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.control.table.LectureLdapFilterTable;
+import org.openslx.dozmod.gui.control.table.QScrollPane;
+import org.openslx.dozmod.gui.helper.GridManager;
+import org.openslx.dozmod.gui.helper.MessageType;
+
+/**
+ * Widget for network share configuration of lectures
+ */
+public class LdapFilterConfigurator extends LdapFilterConfiguratorLayout {
+
+ private static final long serialVersionUID = -3336605759245603655L;
+ private final static Logger LOGGER = Logger.getLogger(LdapFilterConfigurator.class);
+ private List<LdapFilter> filterList = null;
+
+ public LdapFilterConfigurator() {
+
+ super();
+
+ tblFilters.getModel().addTableModelListener(new TableModelListener() {
+ @Override
+ public void tableChanged(TableModelEvent e) {
+ fireChangeEvent();
+ }
+ });
+
+ tblFilters.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ LdapFilter item = tblFilters.getSelectedItem();
+ if (item == null) {
+ clearInputFields();
+ return;
+ }
+ // share from the list is selected: fill bottom form and change "Add" to "Apply"
+ btnDel.setEnabled(true);
+ txtAttribute.setText(item.attribute);
+ txtValue.setText(item.value);
+ btnAdd.setText("Ändern");
+ }
+ });
+
+ btnAdd.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // check if we are editing an existing share entry or
+ // creating a new one, check for input either way
+ LdapFilter input = new LdapFilter();
+
+ input.attribute = txtAttribute.getText();
+ if (input.attribute == null || input.attribute.isEmpty()) {
+ Gui.showMessageBox("Kein Attribut angegeben", MessageType.ERROR, null, null);
+ return;
+ }
+ input.value = txtValue.getText();
+ if (input.value == null) {
+ input.value = "";
+ }
+
+ // either we delete the existing share from the data or we are
+ // creating a new one, either way add it to the list and update
+ // the table, if its not present already
+ if (filterList.contains(input)) {
+ Gui.showMessageBox("Eintrag bereits vorhanden", MessageType.ERROR, null, null);
+ return;
+ }
+ // now decide whether to create a new entry or update existing one
+ LdapFilter oldEntry = tblFilters.getSelectedItem();
+ if (oldEntry != null) {
+ // editing existing one, delete it from the internal data
+ filterList.remove(oldEntry);
+ }
+ filterList.add(input);
+ tblFilters.getModel().setData(filterList);
+ clearInputFields();
+ }
+ });
+
+ btnDel.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // try to delete the selected share
+ LdapFilter selection = tblFilters.getSelectedItem();
+ if (selection == null) {
+ return;
+ }
+ try {
+ if (!filterList.remove(selection)) {
+ // false if it was not found
+ LOGGER.error("Could not remove non-existent filter '" + selection.toString()
+ + "' from the table data: " + filterList.toString());
+ return;
+ }
+ // refresh table data
+ tblFilters.getModel().setData(filterList);
+ } catch (Exception ex) {
+ LOGGER.debug("Failed to remove " + selection.toString() + " from the table data.", ex);
+ return;
+ }
+ }
+ });
+ btnDel.setEnabled(false);
+ }
+
+ private void clearInputFields() {
+ btnDel.setEnabled(false);
+ txtAttribute.setText(null);
+ txtValue.setText(null);
+ btnAdd.setText("Hinzufügen");
+ }
+
+ public List<LdapFilter> getState() {
+ return filterList;
+ }
+
+ public boolean setState(List<LdapFilter> data) {
+ if (data == null)
+ return false;
+ if (filterList == null) {
+ filterList = new ArrayList<>();
+ }
+ filterList = data;
+ tblFilters.getModel().setData(filterList);
+ return true;
+ }
+
+ protected List<ChangeListener> listenerList = new ArrayList<>();
+
+ public void addLdapFilterListTableContentConfigurationChangeEventListener(ChangeListener listener) {
+ listenerList.add(listener);
+ }
+
+ public void removeNetshareConfigurationChangeEventListener(ChangeListener listener) {
+ listenerList.remove(listener);
+ }
+
+ void fireChangeEvent() {
+ for (ChangeListener listener : new ArrayList<>(listenerList)) {
+ listener.stateChanged(null);
+ }
+ }
+}
+
+/**
+ * Internal layout class for this widget
+ */
+class LdapFilterConfiguratorLayout extends JPanel {
+
+ private static final long serialVersionUID = 6479838641542743622L;
+
+ private final static String HELPTEXT = "Geben Sie hier LDAP Filter ein, die die Sichtbarkeit"
+ + " der Veranstaltung abhängig vom angemeldeten Benutzer einschränken. Eine Veranstaltung"
+ + " ist sichtbar, sobald einer der angegebenen Filter zutrifft. Zusätzliche Raumbeschränkungen"
+ + " greifen weiterhin.";
+
+ protected final LectureLdapFilterTable tblFilters = new LectureLdapFilterTable();
+ protected final JTextField txtAttribute, txtValue;
+ protected final JButton btnAdd, btnDel;
+
+ public LdapFilterConfiguratorLayout() {
+ GridManager grid = new GridManager(this, 1, true, new Insets(3, 3, 3, 3));
+ // top info panel
+ grid.add(new QLabel(HELPTEXT)).fill(true, false).expand(true, false);
+ grid.nextRow();
+ // middle filter list
+ grid.add(new QScrollPane(tblFilters)).fill(true, true).expand(true, true);
+ grid.nextRow();
+
+ btnDel = new JButton("Entfernen");
+ grid.add(btnDel).anchor(GridBagConstraints.EAST);
+ grid.nextRow();
+
+ JPanel pnlNewShare = new JPanel();
+ GridManager gridNewFilter = new GridManager(pnlNewShare, 2, true);
+ pnlNewShare.setBorder(BorderFactory.createTitledBorder("Filter definieren"));
+ gridNewFilter.add(new QLabel("Attribut"));
+ txtAttribute = new JTextField();
+ gridNewFilter.add(txtAttribute).fill(true, false).expand(true, false);
+ gridNewFilter.nextRow();
+ gridNewFilter.add(new QLabel("Wert"));
+ txtValue = new JTextField();
+ gridNewFilter.add(txtValue).fill(true, false).expand(true, false);
+ gridNewFilter.nextRow();
+ btnAdd = new JButton("Hinzufügen");
+ gridNewFilter.add(btnAdd, 2).anchor(GridBagConstraints.EAST);
+ gridNewFilter.nextRow();
+ gridNewFilter.finish(false);
+ grid.add(pnlNewShare).fill(true, false).expand(true, false);
+ grid.nextRow();
+ grid.finish(false);
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java
new file mode 100644
index 00000000..ac5e8e0f
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java
@@ -0,0 +1,24 @@
+package org.openslx.dozmod.gui.control.table;
+
+import org.openslx.bwlp.thrift.iface.LdapFilter;
+
+@SuppressWarnings("serial")
+public class LectureLdapFilterTable extends ListTable<LdapFilter> {
+
+ public static final ListTableColumn COL_ATTRIBUTE = new ListTableColumn("Attribut");
+ public static final ListTableColumn COL_VALUE = new ListTableColumn("Wert");
+
+ public LectureLdapFilterTable() {
+ super(COL_ATTRIBUTE, COL_VALUE);
+ }
+
+ @Override
+ protected Object getValueAtInternal(LdapFilter item, ListTableColumn columnIndex) {
+ if (columnIndex == COL_ATTRIBUTE)
+ return item.attribute;
+ if (columnIndex == COL_VALUE)
+ return item.value;
+ throw new IndexOutOfBoundsException();
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
index b7dce83a..4ae8af93 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
@@ -145,7 +145,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
private String originalRunscript = null;
private List<NetShare> currentNetshares = null;
private List<NetShare> originalNetshares = null;
-
+
/**
* Constructor
*
@@ -331,6 +331,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
dtpEndDate.addActionListener(actionListener);
spnStartTime.addChangeListener(changeListener);
spnEndTime.addChangeListener(changeListener);
+ ctlLdapFilterConfigurator.addLdapFilterListTableContentConfigurationChangeEventListener(changeListener);
// save default color of date/time stuff to reset the background later
dateTimeTextColor = dtpStartDate.getForeground();
@@ -431,6 +432,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
// init advanced info
ctlRunscriptConfigurator.setState(lecture.runscript);
ctlNetshareConfigurator.setState(lecture.networkShares);
+ ctlLdapFilterConfigurator.setState(lecture.ldapFilters);
txtTitle.setText(lecture.getLectureName());
lblTitleInfo.setText(lecture.getLectureName());
@@ -640,7 +642,13 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
}
// done with mandatory checks, remove error message
lblError.setText(null);
+
+
+ // TODO: Refactor change detection and error display so you don't lose your mind when
+ // trying to work with it.
+ return true;
+ /*
// check for changes in all fields
changed = !txtTitle.getText().equals(lecture.getLectureName())
|| !txtDescription.getText().equals(lecture.getDescription())
@@ -660,6 +668,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
|| (currentNetshares != null && !currentNetshares.equals(originalNetshares))
|| imageLinkChanged;
return changed;
+ */
}
/**
@@ -669,10 +678,11 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
private void saveChanges() {
boolean saved = saveChangesInternal();
callback.updated(saved);
- if (saved)
+ if (saved) {
dispose();
- else
+ } else {
btnSaveChanges.setEnabled(true);
+ }
}
/**
@@ -703,6 +713,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
false, chkHasUsbAccess.isSelected());
metadata.setNetworkExceptions(currentNetrules);
metadata.setNetworkShares(currentNetshares);
+ metadata.setLdapFilters(ctlLdapFilterConfigurator.getState());
// now trigger the actual action
try {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java
index 57a82b6d..ab20567c 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java
@@ -30,6 +30,7 @@ import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.ComboBox;
import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer;
+import org.openslx.dozmod.gui.control.LdapFilterConfigurator;
import org.openslx.dozmod.gui.control.LectureCustomPermissionManager;
import org.openslx.dozmod.gui.control.LocationSelector;
import org.openslx.dozmod.gui.control.NetshareConfigurator;
@@ -93,6 +94,7 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
protected final LocationSelector ctlLocationSelector;
protected final RunscriptConfigurator ctlRunscriptConfigurator;
protected final NetshareConfigurator ctlNetshareConfigurator;
+ protected final LdapFilterConfigurator ctlLdapFilterConfigurator;
private static final Properties pickerStrings = new Properties();
@@ -104,7 +106,8 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
protected JPanel pnlTabPermissions;
protected JPanel pnlTabLocations;
protected JPanel pnlTabRunscript;
- private JPanel pnlTabNetshare;
+ protected JPanel pnlTabNetshare;
+ protected JPanel pnlTabLdapFilter;
static {
pickerStrings.put("text.today", "Heute");
@@ -375,6 +378,18 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
GridManager grdNetshare = new GridManager(pnlTabNetshare, 1, false, new Insets(8, 2, 8, 2));
grdNetshare.add(ctlNetshareConfigurator).fill(true, true).expand(true, true);
grdNetshare.finish(false);
+
+ /* *******************************************************************************
+ *
+ * Tab "LDAP-Filters"
+ *
+ ********************************************************************************/
+ ctlLdapFilterConfigurator = new LdapFilterConfigurator();
+ pnlTabLdapFilter = new JPanel();
+ GridManager grdLdap = new GridManager(pnlTabLdapFilter, 1, false, new Insets(8, 2, 8, 2));
+ grdLdap.add(ctlLdapFilterConfigurator).fill(true, true).expand(true, true);
+ grdLdap.finish(false);
+
/* *******************************************************************************
*
* Main panel containing the tabs
@@ -397,6 +412,9 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
if (Session.hasFeature(Feature.NETWORK_SHARES)) {
pnlTabs.addTab("Netzlaufwerke", pnlTabNetshare);
}
+ if (Session.hasFeature(Feature.LECTURE_FILTER_LDAP)) {
+ pnlTabs.addTab("LDAP-Filter", pnlTabLdapFilter);
+ }
add(pnlTabs, BorderLayout.CENTER);
// usage counter + button panel on the bottom
JPanel buttonPanel = new JPanel();
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java
index 2587661b..5f21c22f 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java
@@ -11,6 +11,7 @@ public class SupportedFeatures {
registerFeature(Feature.NETWORK_SHARES);
registerFeature(Feature.MULTIPLE_HYPERVISORS);
registerFeature(Feature.SERVER_SIDE_COPY);
+ registerFeature(Feature.LECTURE_FILTER_LDAP);
}
public static String getFeatureString() {
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
index 423428c0..003abc05 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
@@ -16,6 +16,7 @@ public class Updater {
addLogTable();
fixEmailFieldLength();
addNetworkShares();
+ addLectureFilter();
}
private static void addLectureLocationMapTable() throws SQLException {
@@ -182,4 +183,39 @@ public class Updater {
throw e;
}
}
+
+ private static void addLectureFilter() throws SQLException {
+ try (MysqlConnection connection = Database.getConnection()) {
+ MysqlStatement tablesStmt = connection.prepareStatement("SHOW TABLES");
+ ResultSet tables = tablesStmt.executeQuery();
+ while (tables.next()) {
+ if (tables.getString(1).equals("lecturefilter")) {
+ return; // Table exists, don't do anything
+ }
+ }
+ // Add table
+ MysqlStatement tableAddStmt = connection.prepareStatement(
+ "CREATE TABLE `lecturefilter` ("
+ + " `lectureid` char(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,"
+ + " `filtertype` varchar(24) CHARACTER SET ascii NOT NULL,"
+ + " `filterkey` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL,"
+ + " `filtervalue` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,"
+ + " KEY `lectureid` (`lectureid`,`filtertype`)"
+ + " KEY `fk_lectureid_1` (`lectureid`)"
+ + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
+ tableAddStmt.executeUpdate();
+ // Add constraint
+ MysqlStatement constraintStmt = connection.prepareStatement(
+ "ALTER TABLE `lecturefilter` ADD "
+ + " CONSTRAINT `lectureid` FOREIGN KEY (`lectureid`) REFERENCES `lecture` (`lectureid`)"
+ + " ON DELETE CASCADE ON UPDATE CASCADE");
+ constraintStmt.executeUpdate();
+ connection.commit();
+ LOGGER.info("Updated database: Added lecture filter table");
+ } catch (SQLException e) {
+ LOGGER.error("Query failed in Updater.addLectureFilter()", e);
+ throw e;
+ }
+ }
+
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
index 32124899..701d435b 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
@@ -20,6 +20,7 @@ import org.openslx.bwlp.sat.thrift.cache.OperatingSystemList;
import org.openslx.bwlp.sat.util.Util;
import org.openslx.bwlp.sat.web.VmChooserEntryXml;
import org.openslx.bwlp.sat.web.VmChooserListXml;
+import org.openslx.bwlp.sat.web.XmlFilterEntry;
import org.openslx.bwlp.thrift.iface.LectureRead;
import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.bwlp.thrift.iface.LectureWrite;
@@ -121,6 +122,9 @@ public class DbLecture {
if (lecture.isSetNetworkShares()) {
DbNetshare.writeNetworkShares(connection, lectureId, lecture.networkShares);
}
+ if (lecture.isSetLdapFilters()) {
+ DbLectureFilter.writeLdapFilters(connection, lectureId, lecture.ldapFilters);
+ }
connection.commit();
return lectureId;
} catch (SQLException e) {
@@ -145,6 +149,9 @@ public class DbLecture {
if (lecture.isSetNetworkShares()) {
DbNetshare.writeNetworkShares(connection, lectureId, lecture.networkShares);
}
+ if (lecture.isSetLdapFilters()) {
+ DbLectureFilter.writeLdapFilters(connection, lectureId, lecture.ldapFilters);
+ }
stmt.executeUpdate();
}
@@ -332,6 +339,7 @@ public class DbLecture {
User.setCombinedUserPermissions(lecture, user);
lecture.setLocationIds(DbLocation.getLectureLocations(connection, lectureId));
lecture.setNetworkShares(DbNetshare.getLectureNetshares(connection, lectureId));
+ lecture.setLdapFilters(DbLectureFilter.getLectureLdapFilters(connection, lectureId));
return lecture;
} catch (SQLException e) {
LOGGER.error("Query failed in DbLecture.getLectureDetails()", e);
@@ -507,12 +515,15 @@ public class DbLecture {
boolean isForThisLocation = rs.getString("loctest") != null;
if (!isForThisLocation && rs.getBoolean("islocationprivate"))
continue; // Is limited to location, and we're not in one of the required locations
+ String lectureId = rs.getString("lectureid");
boolean isTemplate = rs.getBoolean("istemplate");
int prio = 100;
+ // Get ldap filters
+ List<XmlFilterEntry> ldapFilters = DbLectureFilter.getFiltersXml(connection, lectureId);
list.add(new VmChooserEntryXml(rs.getString("filepath"), prio, "-",
- rs.getString("lecturename"), rs.getString("description"), rs.getString("lectureid"),
+ rs.getString("lecturename"), rs.getString("description"), lectureId,
rs.getString("virtid"), rs.getString("virtname"), rs.getString("virtoskeyword"),
- rs.getString("osname"), "", isForThisLocation, isTemplate));
+ rs.getString("osname"), "", isForThisLocation, isTemplate, ldapFilters));
}
return list;
} catch (SQLException e) {
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java
new file mode 100644
index 00000000..81c42444
--- /dev/null
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java
@@ -0,0 +1,75 @@
+package org.openslx.bwlp.sat.database.mappers;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.sat.database.MysqlConnection;
+import org.openslx.bwlp.sat.database.MysqlStatement;
+import org.openslx.bwlp.sat.util.Util;
+import org.openslx.bwlp.sat.web.XmlFilterEntry;
+import org.openslx.bwlp.thrift.iface.LdapFilter;
+
+public class DbLectureFilter {
+
+ private static final Logger LOGGER = Logger.getLogger(DbLectureFilter.class);
+
+ public static List<LdapFilter> getLectureLdapFilters(MysqlConnection connection, String lectureId)
+ throws SQLException {
+ List<LdapFilter> list = new ArrayList<>();
+ MysqlStatement stmt = connection.prepareStatement("SELECT filterkey, filtervalue FROM lecturefilter"
+ + " WHERE lectureid = :lectureid AND filtertype = 'LDAP'");
+ stmt.setString("lectureid", lectureId);
+ ResultSet rs = stmt.executeQuery();
+ while (rs.next()) {
+ String key = rs.getString("filterkey");
+ String value = rs.getString("filtervalue");
+ list.add(new LdapFilter(key, value));
+ }
+ return list;
+ }
+
+ public static final List<XmlFilterEntry> getFiltersXml(MysqlConnection connection, String lectureId)
+ throws SQLException {
+ List<XmlFilterEntry> list = null;
+ MysqlStatement stmt = connection.prepareStatement("SELECT filterkey, filtervalue FROM lecturefilter"
+ + " WHERE lectureid = :lectureid AND filtertype = 'LDAP'");
+ stmt.setString("lectureid", lectureId);
+ ResultSet rs = stmt.executeQuery();
+ while (rs.next()) {
+ String key = rs.getString("filterkey");
+ String value = rs.getString("filtervalue");
+ if (list == null) {
+ list = new ArrayList<>();
+ }
+ list.add(new XmlFilterEntry("LDAP", key, value));
+ }
+ return list;
+ }
+
+ public static void writeLdapFilters(MysqlConnection connection, String lectureId, List<LdapFilter> list)
+ throws SQLException {
+ if (lectureId == null || lectureId.isEmpty()) {
+ return;
+ }
+ MysqlStatement delStmt = connection.prepareStatement("DELETE FROM lecturefilter WHERE lectureid = :lectureid");
+ delStmt.setString("lectureid", lectureId);
+ delStmt.executeUpdate();
+ if (list == null || list.isEmpty()) {
+ return;
+ }
+ MysqlStatement addStmt = connection.prepareStatement("INSERT INTO lecturefilter (lectureid, filtertype, filterkey, filtervalue)"
+ + " VALUES (:lectureid, 'LDAP', :key, :value)");
+ addStmt.setString("lectureid", lectureId);
+ for (LdapFilter filter : list) {
+ if (Util.isEmptyString(filter.attribute) || filter.value == null)
+ continue;
+ addStmt.setString("key", filter.attribute);
+ addStmt.setString("value", filter.value);
+ addStmt.executeUpdate();
+ }
+ }
+
+}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserEntryXml.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserEntryXml.java
index d383a72a..fd4e0505 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserEntryXml.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserEntryXml.java
@@ -1,7 +1,10 @@
package org.openslx.bwlp.sat.web;
+import java.util.List;
+
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
+import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
@Root(name = "eintrag")
@@ -33,10 +36,12 @@ public class VmChooserEntryXml {
private VmChooserParamXml for_location;
@Element
private VmChooserParamXml is_template;
+ @Element
+ private VmChooserListXml filters;
public VmChooserEntryXml(String imageFilePath, int priority, String creator, String short_description,
String long_description, String uuid, String virtId, String virtualizerName, String osVirtName,
- String osDisplayName, String icon, boolean isForThisLocation, boolean isTemplate) {
+ String osDisplayName, String icon, boolean isForThisLocation, boolean isTemplate, List<XmlFilterEntry> ldapFilters) {
this.image_name = new VmChooserParamXml(imageFilePath);
this.priority = new VmChooserParamXml(priority);
this.creator = new VmChooserParamXml(creator);
@@ -50,6 +55,7 @@ public class VmChooserEntryXml {
this.os_name = new VmChooserParamXml(osDisplayName);
this.for_location = new VmChooserParamXml(isForThisLocation);
this.is_template = new VmChooserParamXml(isTemplate);
+ this.filters = new VmChooserListXml(ldapFilters);
}
private static class VmChooserParamXml {
@@ -70,5 +76,16 @@ public class VmChooserEntryXml {
}
}
+
+ private static class VmChooserListXml {
+
+ @ElementList(required = false, inline = true, entry = "filter")
+ private List<XmlFilterEntry> list;
+
+ public VmChooserListXml(List<XmlFilterEntry> list) {
+ this.list = list;
+ }
+
+ }
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserListXml.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserListXml.java
index beebce1a..47ca0e1e 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserListXml.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserListXml.java
@@ -10,7 +10,7 @@ import org.simpleframework.xml.Root;
public class VmChooserListXml {
@ElementList(inline = true, name = "eintrag")
- public List<VmChooserEntryXml> entries;
+ private List<VmChooserEntryXml> entries;
public VmChooserListXml(boolean createEmptyList) {
if (createEmptyList) {
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/XmlFilterEntry.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/XmlFilterEntry.java
new file mode 100644
index 00000000..1c733f9f
--- /dev/null
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/XmlFilterEntry.java
@@ -0,0 +1,21 @@
+package org.openslx.bwlp.sat.web;
+
+import org.simpleframework.xml.Attribute;
+import org.simpleframework.xml.Element;
+
+public class XmlFilterEntry {
+
+ @Attribute(required = false)
+ private String type;
+ @Element
+ private String key;
+ @Element
+ private String value;
+
+ public XmlFilterEntry(String type, String key, String value) {
+ this.type = type;
+ this.key = key;
+ this.value = value;
+ }
+
+}