Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPORTAL-3263 "Restricted" page editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Sep 17, 2013
1 parent 06dee80 commit c4c2922
Show file tree
Hide file tree
Showing 36 changed files with 654 additions and 202 deletions.
Expand Up @@ -48,11 +48,11 @@ public class UserACL {

protected static Log log = ExoLogger.getLogger("organization:UserACL");

private final Collection<MembershipEntry> NO_MEMBERSHIP = Collections.emptyList();
private static final Collection<MembershipEntry> NO_MEMBERSHIP = Collections.emptyList();

private final Collection<String> NO_ROLES = Collections.emptyList();
private static final Collection<String> NO_ROLES = Collections.emptyList();

private final Identity guest = new Identity(null, NO_MEMBERSHIP, NO_ROLES);
private static final Identity guest = new Identity(null, NO_MEMBERSHIP, NO_ROLES);

private String superUser_;

Expand All @@ -72,7 +72,6 @@ public class UserACL {

private String adminMSType;

@SuppressWarnings("unchecked")
public UserACL(InitParams params) {
UserACLMetaData md = new UserACLMetaData(params);

Expand Down Expand Up @@ -471,6 +470,8 @@ private List<String> defragmentPermission(String permission) {

public static class Permission implements Serializable {

private static final long serialVersionUID = -2642107810551203332L;

private String name_;

private String groupId_ = "";
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.List;

import org.exoplatform.portal.config.UserACL;
import org.exoplatform.portal.pom.config.Utils;
import org.exoplatform.portal.pom.data.ComponentData;
import org.exoplatform.portal.pom.data.ContainerData;
Expand All @@ -33,6 +34,12 @@
**/
public class Container extends ModelObject {

public static final String[] DEFAULT_ACCESS_PERMISSIONS = new String[] { UserACL.EVERYONE };

public static final String[] DEFAULT_ADD_APPLICATION_PERMISSIONS_PERMISSIONS = new String[] { UserACL.EVERYONE };

public static final String[] DEFAULT_ADD_CONTAINER_PERMISSIONS_PERMISSIONS = new String[] { UserACL.EVERYONE };

protected String id;

protected String name;
Expand All @@ -56,6 +63,10 @@ public class Container extends ModelObject {

protected String[] accessPermissions;

protected String[] addContainerPermissions;

protected String[] addApplicationPermissions;

protected ArrayList<ModelObject> children;

public Container() {
Expand Down Expand Up @@ -180,6 +191,41 @@ public void setAccessPermissions(String[] accessPermissions) {
this.accessPermissions = accessPermissions;
}

public String[] getAddContainerPermissions() {
return addContainerPermissions;
}

public void setAddContainerPermissions(String[] addContainerPermissions) {
this.addContainerPermissions = addContainerPermissions;
}

public String[] getAddApplicationPermissions() {
return addApplicationPermissions;
}

public void setAddApplicationPermissions(String[] addApplicationPermissions) {
this.addApplicationPermissions = addApplicationPermissions;
}

public void ensureInitialPermissionsSet() {
if (accessPermissions == null || accessPermissions.length == 0) {
accessPermissions = DEFAULT_ACCESS_PERMISSIONS;
}
// if (addApplicationPermissions == null || addApplicationPermissions.length == 0) {
// addApplicationPermissions = DEFAULT_ADD_APPLICATION_PERMISSIONS_PERMISSIONS;
// }
// if (addContainerPermissions == null || addContainerPermissions.length == 0) {
// addContainerPermissions = DEFAULT_ADD_CONTAINER_PERMISSIONS_PERMISSIONS;
// }
if (children != null && children.size() > 0) {
for (ModelObject o : children) {
if (o instanceof Container) {
((Container) o).ensureInitialPermissionsSet();
}
}
}
}

public String getDecorator() {
// Here to please jibx binding but not used anymore
return null;
Expand Down
Expand Up @@ -28,6 +28,7 @@
import static org.gatein.common.xml.stax.writer.StaxWriterUtils.writeOptionalElement;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -99,6 +100,8 @@ protected void marshalContainer(StaxWriter<Element> writer, Container container)
writeOptionalElement(writer, Element.DESCRIPTION, container.getDescription());

marshalAccessPermissions(writer, container.getAccessPermissions());
marshalPermissions(writer, Element.ADD_APPLICATION_PERMISSIONS, container.getAddApplicationPermissions());
marshalPermissions(writer, Element.ADD_CONTAINER_PERMISSIONS, container.getAddContainerPermissions());

writeOptionalElement(writer, Element.FACTORY_ID, container.getFactoryId());

Expand Down Expand Up @@ -137,7 +140,15 @@ protected Container unmarshalContainer(StaxNavigator<Element> navigator) throws
current = navigator.sibling();
break;
case ACCESS_PERMISSIONS:
container.setAccessPermissions(unmarshalAccessPermissions(navigator, false));
container.setAccessPermissions(unmarshalPermissions(navigator, false));
current = navigator.sibling();
break;
case ADD_CONTAINER_PERMISSIONS:
container.setAddContainerPermissions(unmarshalPermissions(navigator, false));
current = navigator.sibling();
break;
case ADD_APPLICATION_PERMISSIONS:
container.setAddApplicationPermissions(unmarshalPermissions(navigator, false));
current = navigator.sibling();
break;
case FACTORY_ID:
Expand Down Expand Up @@ -494,7 +505,7 @@ protected <S> Application<S> unmarshalApplication(StaxNavigator<Element> navigat
current = navigator.sibling();
break;
case ACCESS_PERMISSIONS:
application.setAccessPermissions(unmarshalAccessPermissions(navigator, true));
application.setAccessPermissions(unmarshalPermissions(navigator, true));
current = navigator.sibling();
break;
case SHOW_INFO_BAR:
Expand Down Expand Up @@ -543,16 +554,19 @@ protected <S> Application<S> unmarshalApplication(StaxNavigator<Element> navigat
}

protected void marshalAccessPermissions(StaxWriter<Element> writer, String[] accessPermissions) throws XMLStreamException {
accessPermissions = (accessPermissions == null || accessPermissions.length == 0) ? null : accessPermissions;
marshalPermissions(writer, Element.ACCESS_PERMISSIONS, accessPermissions);
}

writeOptionalElement(writer, Element.ACCESS_PERMISSIONS, DelimitedValueType.SEMI_COLON, accessPermissions);
protected void marshalPermissions(StaxWriter<Element> writer, Element element, String[] accessPermissions) throws XMLStreamException {
accessPermissions = (accessPermissions == null || accessPermissions.length == 0) ? null : accessPermissions;
writeOptionalElement(writer, element, DelimitedValueType.SEMI_COLON, accessPermissions);
}

protected String[] unmarshalAccessPermissions(StaxNavigator<Element> navigator, boolean required) throws XMLStreamException {
protected String[] unmarshalPermissions(StaxNavigator<Element> navigator, boolean required) throws XMLStreamException {
if (required) {
return parseRequiredContent(navigator, DelimitedValueType.SEMI_COLON);
return Utils.tidyUp(parseRequiredContent(navigator, DelimitedValueType.SEMI_COLON));
} else {
return parseContent(navigator, DelimitedValueType.SEMI_COLON, null);
return Utils.tidyUp(parseContent(navigator, DelimitedValueType.SEMI_COLON, null));
}
}

Expand Down
Expand Up @@ -86,6 +86,8 @@ public enum Element implements EnumElement<Element> {
DESCRIPTION("description"),
FACTORY_ID("factory-id"),
ACCESS_PERMISSIONS("access-permissions"),
ADD_CONTAINER_PERMISSIONS("add-container-permissions"),
ADD_APPLICATION_PERMISSIONS("add-application-permissions"),
EDIT_PERMISSION("edit-permission"),
PORTLET_APPLICATION("portlet-application"),
GADGET_APPLICATION("gadget-application"),
Expand Down
Expand Up @@ -152,7 +152,7 @@ private Page unmarshalPage(StaxNavigator<Element> navigator) throws XMLStreamExc
current = navigator.sibling();
break;
case ACCESS_PERMISSIONS:
page.setAccessPermissions(unmarshalAccessPermissions(navigator, true));
page.setAccessPermissions(unmarshalPermissions(navigator, true));
current = navigator.sibling();
break;
case EDIT_PERMISSION:
Expand Down
Expand Up @@ -190,7 +190,7 @@ private PortalConfig unmarshalPortalConfig(StaxNavigator<Element> navigator) thr
current = navigator.next();
break;
case ACCESS_PERMISSIONS:
portalConfig.setAccessPermissions(unmarshalAccessPermissions(navigator, false));
portalConfig.setAccessPermissions(unmarshalPermissions(navigator, false));
current = navigator.sibling();
break;
case EDIT_PERMISSION:
Expand Down
Expand Up @@ -79,4 +79,40 @@ public static <N> LocalizedString parseLocalizedString(StaxNavigator<N> navigato

return new LocalizedString(value, lang);
}

/**
* Removes empty strings and {@code null} elements from the given string {@code array}. Returns the submitted instance if
* there is no change.
*
* @param array the array to tidy up
* @return A new array with empty strings and {@code null} elements removed or the innstance submitted over {@code array}
* argument if there is no change necessary.
*/
public static String[] tidyUp(String[] array) {
if (array == null || array.length == 0) {
return array;
} else {
int resultLength = array.length;
for (int i = 0; i < resultLength; i++) {
if (array[i] == null || array[i].length() == 0) {
/* shift the remaining elements to the left */
for (int j = i; j + 1 < resultLength; j++) {
array[j] = array[j + 1];
}
resultLength--;
i--;
}
}
if (resultLength < array.length) {
/* cut */
String[] result = new String[resultLength];
System.arraycopy(array, 0, result, 0, resultLength);
return result;
} else {
/* no change */
return array;
}
}
}

}
12 changes: 8 additions & 4 deletions component/portal/src/main/resources/binding.xml
@@ -1,17 +1,17 @@
<!--
Copyright (C) 2009 eXo Platform SAS.
This 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.1 of
the License, or (at your option) any later version.
This software 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 software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Expand Down Expand Up @@ -59,10 +59,12 @@
<value name="id" usage="optional" field="id" style="attribute"/>
<value name="name" usage="optional" field="name"/>
<value name="title" field="title" usage="optional"/>
<value name="factory-id" field="factoryId" usage="optional"/>
<value name="icon" field="icon" usage="optional"/>
<value name="template" field="template" usage="optional" style="attribute"/>
<value name="access-permissions" field="accessPermissions" usage="optional"/>
<value name="factory-id" field="factoryId" usage="optional"/>
<value name="add-application-permissions" field="addApplicationPermissions" usage="optional"/>
<value name="add-container-permissions" field="addContainerPermissions" usage="optional"/>
<value name="decorator" field="decorator" usage="optional" style="attribute"/>
<value name="description" field="description" usage="optional"/>
<value name="width" usage="optional" field="width" style="attribute"/>
Expand All @@ -84,6 +86,8 @@
<value name="title" field="title" usage="optional"/>
<value name="factory-id" field="factoryId" usage="optional"/>
<value name="access-permissions" field="accessPermissions" usage="optional"/>
<value name="add-application-permissions" field="addApplicationPermissions" usage="optional"/>
<value name="add-container-permissions" field="addContainerPermissions" usage="optional"/>
<value name="edit-permission" field="editPermission" usage="optional"/>
<value name="show-max-window" field="showMaxWindow" usage="optional"/>
<collection field="children" ordered="false">
Expand Down
@@ -0,0 +1,50 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This 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.1 of
* the License, or (at your option) any later version.
*
* This software 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 software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.exoplatform.portal.mop.management.binding.xml;

import static org.junit.Assert.assertArrayEquals;
import junit.framework.TestCase;

/**
* @author <a href="mailto:ppalaga@redhat.com">Peter Palaga</a>
*
*/
public class UtilsTest extends TestCase {
public void testTidyUp() {
assertArrayEquals(null, Utils.tidyUp(null));
assertArrayEquals(new String[] {}, Utils.tidyUp(new String[] {}));

String[] array = new String[] {"one", "two", "three"};
assertSame(array, Utils.tidyUp(array));

assertArrayEquals(new String[] {"one", "three"}, Utils.tidyUp(new String[] {"one", "", "three"}));
assertArrayEquals(new String[] {"one",}, Utils.tidyUp(new String[] {"one", "", ""}));
assertArrayEquals(new String[] {"three"}, Utils.tidyUp(new String[] {"", "", "three"}));
assertArrayEquals(new String[] {}, Utils.tidyUp(new String[] {"", "", ""}));
assertArrayEquals(new String[] {"one", "three"}, Utils.tidyUp(new String[] {"one", null, "three"}));
assertArrayEquals(new String[] {"one"}, Utils.tidyUp(new String[] {"one", null, null}));
assertArrayEquals(new String[] {"three"}, Utils.tidyUp(new String[] {null, null, "three"}));
assertArrayEquals(new String[] {}, Utils.tidyUp(new String[] {null, null, null}));
}

}
Expand Up @@ -24,4 +24,5 @@
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_5 http://www.gatein.org/xml/ns/gatein_objects_1_5"
xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_5">
<name></name>
<add-container-permissions>Everyone</add-container-permissions>
</page>
Expand Up @@ -24,9 +24,16 @@
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_5 http://www.gatein.org/xml/ns/gatein_objects_1_5"
xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_5">
<name></name>
<container template='system:/groovy/portal/webui/container/UIContainer.gtmpl'></container>
<add-container-permissions>Everyone</add-container-permissions>
<container template='system:/groovy/portal/webui/container/UIContainer.gtmpl'>
<add-application-permissions>Everyone</add-application-permissions>
</container>
<container template='system:/groovy/portal/webui/container/UITableColumnContainer.gtmpl'>
<container template='system:/groovy/portal/webui/container/UIContainer.gtmpl'></container>
<container template='system:/groovy/portal/webui/container/UIContainer.gtmpl'></container>
<container template='system:/groovy/portal/webui/container/UIContainer.gtmpl'>
<add-application-permissions>Everyone</add-application-permissions>
</container>
<container template='system:/groovy/portal/webui/container/UIContainer.gtmpl'>
<add-application-permissions>Everyone</add-application-permissions>
</container>
</container>
</page>
Expand Up @@ -24,9 +24,16 @@
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_5 http://www.gatein.org/xml/ns/gatein_objects_1_5"
xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_5">
<name></name>
<add-container-permissions>Everyone</add-container-permissions>
<container template="system:/groovy/portal/webui/container/UITableColumnContainer.gtmpl">
<container template="system:/groovy/portal/webui/container/UIContainer.gtmpl"></container>
<container template="system:/groovy/portal/webui/container/UIContainer.gtmpl"></container>
<container template="system:/groovy/portal/webui/container/UIContainer.gtmpl"></container>
<container template="system:/groovy/portal/webui/container/UIContainer.gtmpl">
<add-application-permissions>Everyone</add-application-permissions>
</container>
<container template="system:/groovy/portal/webui/container/UIContainer.gtmpl">
<add-application-permissions>Everyone</add-application-permissions>
</container>
<container template="system:/groovy/portal/webui/container/UIContainer.gtmpl">
<add-application-permissions>Everyone</add-application-permissions>
</container>
</container>
</page>

0 comments on commit c4c2922

Please sign in to comment.