Permalink
Browse files

Merge pull request #152 from adamretter/develop

New setUid and setGid functionality
  • Loading branch information...
2 parents 136c629 + 0f234c2 commit 79814b4b3388cd000a8c3051307b939da98a4eb8 @wolfgangmm wolfgangmm committed Feb 13, 2014
Showing with 2,051 additions and 449 deletions.
  1. +49 −0 src/org/exist/client/LabelledBoolean.java
  2. +65 −0 src/org/exist/client/LabelledBooleanEditor.java
  3. +79 −0 src/org/exist/client/LabelledBooleanRenderer.java
  4. +17 −13 src/org/exist/client/ResourceDescriptor.java
  5. +30 −9 src/org/exist/client/security/BasicPermissionsTableModel.java
  6. +9 −24 src/org/exist/client/security/EditPropertiesDialog.form
  7. +9 −4 src/org/exist/client/security/EditPropertiesDialog.java
  8. +10 −5 src/org/exist/dom/DocumentImpl.java
  9. +38 −10 src/org/exist/security/AbstractUnixStylePermission.java
  10. +284 −0 src/org/exist/security/EffectiveSubject.java
  11. +34 −21 src/org/exist/security/Permission.java
  12. +6 −1 src/org/exist/security/PermissionRequired.java
  13. +9 −0 src/org/exist/security/PermissionRequiredAspect.java
  14. +63 −42 src/org/exist/security/UnixStylePermission.java
  15. +44 −25 src/org/exist/security/internal/aider/UnixStylePermissionAider.java
  16. +58 −33 src/org/exist/source/DBSource.java
  17. +1 −1 src/org/exist/storage/DBBroker.java
  18. +6 −0 src/org/exist/storage/NativeBroker.java
  19. +23 −11 src/org/exist/xmlrpc/RpcConnection.java
  20. +53 −17 src/org/exist/xquery/XQuery.java
  21. +42 −5 src/org/exist/xquery/XQueryContext.java
  22. +2 −2 ...t/xquery/functions/securitymanager/{GroupMembershipFunctions.java → GroupMembershipFunction.java}
  23. +105 −0 src/org/exist/xquery/functions/securitymanager/IdFunction.java
  24. +7 −6 src/org/exist/xquery/functions/securitymanager/{IsAuthenticated.java → IsAuthenticatedFunction.java}
  25. +4 −4 ...org/exist/xquery/functions/securitymanager/{PermissionsFunctions.java → PermissionsFunction.java}
  26. +27 −24 src/org/exist/xquery/functions/securitymanager/SecurityManagerModule.java
  27. +45 −41 src/org/exist/xquery/functions/system/AsUser.java
  28. +3 −2 src/org/exist/xquery/functions/xmldb/XMLDBAddUserToGroup.java
  29. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBChangeUser.java
  30. +3 −3 src/org/exist/xquery/functions/xmldb/XMLDBChmodCollection.java
  31. +3 −4 src/org/exist/xquery/functions/xmldb/XMLDBChmodResource.java
  32. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBCreateGroup.java
  33. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBCreateUser.java
  34. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBDeleteUser.java
  35. +22 −25 src/org/exist/xquery/functions/xmldb/XMLDBGetCurrentUser.java
  36. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBGetCurrentUserAttribute.java
  37. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBGetCurrentUserAttributeNames.java
  38. +6 −5 src/org/exist/xquery/functions/xmldb/XMLDBGetUserOrGroup.java
  39. +3 −2 src/org/exist/xquery/functions/xmldb/XMLDBGetUsers.java
  40. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBGroupExists.java
  41. +3 −2 src/org/exist/xquery/functions/xmldb/XMLDBIsAdmin.java
  42. +21 −20 src/org/exist/xquery/functions/xmldb/XMLDBIsAuthenticated.java
  43. +4 −3 src/org/exist/xquery/functions/xmldb/XMLDBPermissions.java
  44. +4 −3 src/org/exist/xquery/functions/xmldb/XMLDBPermissionsToString.java
  45. +3 −2 src/org/exist/xquery/functions/xmldb/XMLDBRemoveUserFromGroup.java
  46. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBSetCollectionPermissions.java
  47. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBSetResourcePermissions.java
  48. +1 −0 src/org/exist/xquery/functions/xmldb/XMLDBUserAccess.java
  49. +63 −0 test/src/org/exist/client/security/BasicPermissionsTableModelTest.java
  50. +148 −6 test/src/org/exist/security/UnixStylePermissionTest.java
  51. +373 −12 test/src/org/exist/security/XMLDBSecurityTest.java
  52. +111 −0 test/src/org/exist/security/internal/aider/UnixStylePermissionAiderTest.java
  53. +0 −58 test/src/org/exist/security/internal/aider/UnixStylePermissionTest.java
  54. +148 −0 test/src/org/exist/xquery/functions/securitymanager/IdFunctionTest.java
  55. +4 −4 ...t/xquery/functions/securitymanager/{PermissionsFunctionsTest.java → PermissionFunctionsTest.java}
@@ -0,0 +1,49 @@
+/*
+ * eXist Open Source Native XML Database
+ * Copyright (C) 2013 The eXist Project
+ * http://exist-db.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * $Id$
+ */
+package org.exist.client;
+
+/**
+ * Simple Label and Boolean value
+ *
+ * @author Adam Retter <adam@existsolutions.com>
+ */
+public class LabelledBoolean {
+ private final String label;
+ private final boolean set;
+
+ public LabelledBoolean(final String label, final boolean set) {
+ this.label = label;
+ this.set = set;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public boolean isSet() {
+ return set;
+ }
+
+ public LabelledBoolean copy(final boolean set) {
+ return new LabelledBoolean(getLabel(), set);
+ }
+}
@@ -0,0 +1,65 @@
+/*
+ * eXist Open Source Native XML Database
+ * Copyright (C) 2013 The eXist Project
+ * http://exist-db.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * $Id$
+ */
+package org.exist.client;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.JTable;
+import javax.swing.table.TableCellEditor;
+import javax.swing.AbstractCellEditor;
+import javax.swing.JCheckBox;
+import javax.swing.SwingConstants;
+
+/**
+ * Editor for a LabelledBoolean using a JCheckBox
+ *
+ * @author Adam Retter <adam@existsolutions.com>
+ */
+public class LabelledBooleanEditor extends AbstractCellEditor implements TableCellEditor {
+
+ private LabelledBoolean current;
+
+ @Override
+ public Object getCellEditorValue() {
+ return current;
+ }
+
+ @Override
+ public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
+ final LabelledBoolean lb = (LabelledBoolean)value;
+ final JCheckBox chkBox = new JCheckBox(lb.getLabel(), lb.isSet());
+
+ chkBox.setHorizontalAlignment(SwingConstants.LEFT);
+ chkBox.setHorizontalTextPosition(SwingConstants.RIGHT);
+
+ chkBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ current = lb.copy(!lb.isSet());
+ fireEditingStopped(); //notify that editing is done!
+ }
+ });
+
+ return chkBox;
+ }
+}
@@ -0,0 +1,79 @@
+/*
+ * eXist Open Source Native XML Database
+ * Copyright (C) 2013 The eXist Project
+ * http://exist-db.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * $Id$
+ */
+package org.exist.client;
+
+import java.awt.Component;
+import javax.swing.JCheckBox;
+import javax.swing.JTable;
+import javax.swing.SwingConstants;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
+import javax.swing.border.EmptyBorder;
+import javax.swing.plaf.UIResource;
+import javax.swing.table.TableCellRenderer;
+
+/**
+ * Renders a LabelledBoolean as a JCheckBox
+ *
+ * @author Adam Retter <adam@existsolutions.com>
+ */
+public class LabelledBooleanRenderer extends JCheckBox
+ implements TableCellRenderer, UIResource {
+
+ private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
+
+ public LabelledBooleanRenderer() {
+ super();
+ setHorizontalAlignment(SwingConstants.LEFT);
+ setBorderPainted(true);
+ setHorizontalTextPosition(SwingConstants.RIGHT);
+ }
+
+ @Override
+ public Component getTableCellRendererComponent(final JTable table, final Object value,
+ final boolean isSelected, final boolean hasFocus, final int row, final int column) {
+
+ if(isSelected) {
+ setForeground(table.getSelectionForeground());
+ super.setBackground(table.getSelectionBackground());
+ } else {
+ setForeground(table.getForeground());
+ setBackground(table.getBackground());
+ }
+
+ //set selected
+ setSelected(value != null && ((LabelledBoolean)value).isSet());
+
+ //set label
+ if(value != null) {
+ setText(((LabelledBoolean)value).getLabel());
+ }
+
+ if (hasFocus) {
+ setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
+ } else {
+ setBorder(noFocusBorder);
+ }
+
+ return this;
+ }
+}
@@ -32,14 +32,14 @@
* @author gpothier
*/
public abstract class ResourceDescriptor {
- private XmldbURI name;
- private String owner;
- private String group;
- private String permissions;
- private Date date;
+ private final XmldbURI name;
+ private final String owner;
+ private final String group;
+ private final String permissions;
+ private final Date date;
- public ResourceDescriptor(XmldbURI aName, String aOwner,
- String aGroup, String aPermissions, Date date ) {
+ public ResourceDescriptor(final XmldbURI aName, final String aOwner,
+ final String aGroup, final String aPermissions, final Date date ) {
name = aName;
owner = aOwner;
group = aGroup;
@@ -63,31 +63,35 @@ public String getPermissions() {
return permissions;
}
- public Date getDate() {
- return date;
- }
+ public Date getDate() {
+ return date;
+ }
public abstract boolean isCollection();
public static class Document extends ResourceDescriptor {
- public Document(XmldbURI aName, String aOwner, String aGroup, String aPermissions, Date date) {
+ public Document(final XmldbURI aName, final String aOwner,
+ final String aGroup, final String aPermissions, final Date date) {
super(aName, aOwner, aGroup, aPermissions, date);
}
+ @Override
public boolean isCollection() {
return false;
}
}
public static class Collection extends ResourceDescriptor {
- public Collection(XmldbURI aName) {
+ public Collection(final XmldbURI aName) {
super(aName, null, null, null, null);
}
- public Collection(XmldbURI aName, String aOwner, String aGroup, String aPermissions, Date date) {
+ public Collection(final XmldbURI aName, final String aOwner,
+ final String aGroup, final String aPermissions, final Date date) {
super(aName, aOwner, aGroup, aPermissions, date);
}
+ @Override
public boolean isCollection() {
return true;
}
@@ -1,6 +1,6 @@
/*
* eXist Open Source Native XML Database
- * Copyright (C) 2001-2012 The eXist Project
+ * Copyright (C) 2013 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
@@ -21,7 +21,9 @@
*/
package org.exist.client.security;
+import javax.swing.JCheckBox;
import javax.swing.table.DefaultTableModel;
+import org.exist.client.LabelledBoolean;
import org.exist.security.Permission;
/**
@@ -34,36 +36,45 @@ public BasicPermissionsTableModel(final Permission permission) {
super(
new Object [][] {
- new Object[] {"User", (permission.getOwnerMode() & Permission.READ) == Permission.READ, (permission.getOwnerMode() & Permission.WRITE) == Permission.WRITE, (permission.getOwnerMode() & Permission.EXECUTE) == Permission.EXECUTE},
- new Object[] {"Group", (permission.getGroupMode() & Permission.READ) == Permission.READ, (permission.getGroupMode() & Permission.WRITE) == Permission.WRITE, (permission.getGroupMode() & Permission.EXECUTE) == Permission.EXECUTE},
- new Object[] {"Other", (permission.getOtherMode() & Permission.READ) == Permission.READ, (permission.getOtherMode() & Permission.WRITE) == Permission.WRITE, (permission.getOtherMode() & Permission.EXECUTE) == Permission.EXECUTE}
+ new Object[] {"User", (permission.getOwnerMode() & Permission.READ) == Permission.READ, (permission.getOwnerMode() & Permission.WRITE) == Permission.WRITE, (permission.getOwnerMode() & Permission.EXECUTE) == Permission.EXECUTE, new LabelledBoolean("SetUID", permission.isSetUid())},
+ new Object[] {"Group", (permission.getGroupMode() & Permission.READ) == Permission.READ, (permission.getGroupMode() & Permission.WRITE) == Permission.WRITE, (permission.getGroupMode() & Permission.EXECUTE) == Permission.EXECUTE, new LabelledBoolean("SetGID", permission.isSetGid())},
+ new Object[] {"Other", (permission.getOtherMode() & Permission.READ) == Permission.READ, (permission.getOtherMode() & Permission.WRITE) == Permission.WRITE, (permission.getOtherMode() & Permission.EXECUTE) == Permission.EXECUTE, new LabelledBoolean("Sticky", permission.isSticky())}
},
new String [] {
- "Permission", "Read", "Write", "Execute"
+ "Permission", "Read", "Write", "Execute", "Special"
}
);
}
final Class[] types = new Class [] {
- java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class
+ java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class, LabelledBoolean.class
};
boolean[] canEdit = new boolean [] {
- false, true, true, true
+ false, true, true, true, true
};
@Override
public Class getColumnClass(int columnIndex) {
- return types [columnIndex];
+ return types[columnIndex];
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
- return canEdit [columnIndex];
+ return canEdit[columnIndex];
}
+
+ @Override
+ public void setValueAt(Object aValue, int row, int column) {
+ super.setValueAt(aValue, row, column); //To change body of generated methods, choose Tools | Templates.
+ }
+
+
/**
* Get the Mode described by the table model
+ *
+ * The Unix mode of the permissions
*/
public int getMode() {
int mode = 0;
@@ -83,6 +94,16 @@ public int getMode() {
}
}
+ if(((LabelledBoolean)getValueAt(0, 4)).isSet()) {
+ mode |= (Permission.SET_UID << 9);
+ }
+ if(((LabelledBoolean)getValueAt(1, 4)).isSet()) {
+ mode |= (Permission.SET_GID << 9);
+ }
+ if(((LabelledBoolean)getValueAt(2, 4)).isSet()) {
+ mode |= (Permission.STICKY << 9);
+ }
+
return mode;
}
}
Oops, something went wrong.

0 comments on commit 79814b4

Please sign in to comment.