Skip to content

Commit

Permalink
Work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorgner committed Nov 10, 2024
1 parent 2f974cb commit 0a1b600
Show file tree
Hide file tree
Showing 14 changed files with 438 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ public final Iterable getIterableProperty(final PropertyKey<? extends Iterable>
*/
@Override
public final Node getNode() {
Thread.dumpStack();
return TransactionCommand.getCurrentTransaction().getNode(nodeId);
}

Expand Down Expand Up @@ -822,43 +821,6 @@ private boolean isGranted(final Permission permission, final PrincipalInterface
}
}

// new experimental custom permission resultion based on query
final PropertyKey<String> permissionPropertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(PrincipalInterface.class, "customPermissionQuery" + StringUtils.capitalize(permission.name()));
final String customPermissionQuery = accessingUser.getProperty(permissionPropertyKey);

if (StringUtils.isNotEmpty(customPermissionQuery)) {

final Map<String, Object> params = new HashMap<>();

params.put("principalUuid", accessingUser.getUuid());
params.put("principalId", accessingUser.getUuid());
params.put("principalType", accessingUser.getType());

params.put("targetNodeUuid", this.getUuid());
params.put("targetNodeType", this.getType());

boolean result = false;
try {

final DatabaseService db = Services.getInstance().getDatabaseService();
final NativeQuery<Boolean> cpq = db.query(customPermissionQuery, Boolean.class);

cpq.configure(params);

result = db.execute(cpq);

} catch (final Exception ex) {
logger.error("Error in custom permission resolution", ex);
}

logger.info("CPQ (" + permission.name() + ") '" + customPermissionQuery + "': "+ result);

if (result) {
return true;
}

}

// Check permissions from domain relationships
if (resolvePermissions) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public class Group extends Principal {
);

public static final View uiView = new View(Group.class, PropertyView.Ui,
isGroupProperty, jwksReferenceIdProperty, membersProperty, customPermissionQueryReadProperty, customPermissionQueryWriteProperty,
customPermissionQueryDeleteProperty, customPermissionQueryAccessControlProperty
isGroupProperty, jwksReferenceIdProperty, membersProperty
);

public Iterable<PrincipalInterface> getMembers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public interface PrincipalInterface extends NodeInterface, AccessControllable {
Property<String> proxyUsernameProperty = new StringProperty("proxyUsername");
Property<String> proxyPasswordProperty = new StringProperty("proxyPassword");
Property<String> publicKeysProperty = new ArrayProperty("publicKeys", String.class);
Property<String> customPermissionQueryReadProperty = new StringProperty("customPermissionQueryRead");
Property<String> customPermissionQueryWriteProperty = new StringProperty("customPermissionQueryWrite");
Property<String> customPermissionQueryDeleteProperty = new StringProperty("customPermissionQueryDelete");
Property<String> customPermissionQueryAccessControlProperty = new StringProperty("customPermissionQueryAccessControl");

View uiView = new View(PrincipalInterface.class, PropertyView.Ui,
blockedProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,6 @@ public static ServiceResult reloadSchema(final ErrorBuffer errorBuffer, final St

} catch (FrameworkException fex) {

FlushCachesCommand.flushAll();

logger.error("Unable to compile dynamic schema: {}", fex.getMessage());
logger.error(ExceptionUtils.getStackTrace(fex));
success = false;
Expand All @@ -438,8 +436,6 @@ public static ServiceResult reloadSchema(final ErrorBuffer errorBuffer, final St

} catch (Throwable t) {

FlushCachesCommand.flushAll();

logger.error("Unable to compile dynamic schema: {}", t.getMessage());
logger.error(ExceptionUtils.getStackTrace(t));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ public void processMessage(final WebSocketMessage webSocketData) {
return;
}

TransactionCommand.getCurrentTransaction().prefetch("(n:NodeInterface { id: \"" + webSocketData.getId() + "\" })-[:CONTAINS]->(m)",
Set.of("all/OUTGOING/CONTAINS"),
Set.of("all/INCOMING/CONTAINS")
);
prefetch(webSocketData.getId());

final List<GraphObject> result = new LinkedList<>();
DOMNode currentNode = (DOMNode) node.getFirstChild();

while (currentNode != null) {

prefetch(currentNode.getUuid());

result.add(currentNode);

currentNode = (DOMNode) currentNode.getNextSibling();
Expand All @@ -83,4 +82,47 @@ public void processMessage(final WebSocketMessage webSocketData) {
public String getCommand() {
return "DOM_NODE_CHILDREN";
}

private void prefetch(final String uuid) {

TransactionCommand.getCurrentTransaction().prefetch("(n:NodeInterface:DOMNode { id: \"" + uuid + "\" })-[r]-(m)",

Set.of(
"all/OUTGOING/CONTAINS",
"all/OUTGOING/CONTAINS_NEXT_SIBLING",
"all/OUTGOING/SUCCESS_TARGET",
"all/OUTGOING/FAILURE_TARGET",
"all/OUTGOING/SUCCESS_NOTIFICATION_ELEMENT",
"all/OUTGOING/FAILURE_NOTIFICATION_ELEMENT",
"all/OUTGOING/RELOADS",
"all/OUTGOING/FLOW",
"all/OUTGOING/INPUT_ELEMENT",
"all/OUTGOING/OWNS",
"all/OUTGOING/PARAMETER",
"all/OUTGOING/SECURITY",
"all/OUTGOING/SYNC",
"all/OUTGOING/PAGE",
"all/OUTGOING/TRIGGERED_BY"
),

Set.of(

"all/INCOMING/CONTAINS",
"all/INCOMING/CONTAINS_NEXT_SIBLING",
"all/INCOMING/SUCCESS_TARGET",
"all/INCOMING/FAILURE_TARGET",
"all/INCOMING/SUCCESS_NOTIFICATION_ELEMENT",
"all/INCOMING/FAILURE_NOTIFICATION_ELEMENT",
"all/INCOMING/RELOADS",
"all/INCOMING/FLOW",
"all/INCOMING/INPUT_ELEMENT",
"all/INCOMING/OWNS",
"all/INCOMING/PARAMETER",
"all/INCOMING/SECURITY",
"all/INCOMING/SYNC",
"all/INCOMING/PAGE",
"all/INCOMING/TRIGGERED_BY"
)
);
}
}
2 changes: 1 addition & 1 deletion structr-base/src/main/resources/test/views.properties
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ G._html_=_html_accesskey,_html_class,_html_contenteditable,_html_contextmenu,_ht
G.public=children,cypherQuery,dataKey,functionQuery,isDOMNode,name,pageId,parent,partialUpdateKey,path,restQuery,sharedComponentId,syncedNodesIds,tag,
G.ui=_html_class,_html_id,children,childrenIds,cypherQuery,data-structr-id,dataKey,functionQuery,hideConditions,hideForLocales,isDOMNode,pageId,parent,partialUpdateKey,path,restQuery,sharedComponentId,sharedComponentConfiguration,showConditions,showForLocales,syncedNodesIds,tag,data-structr-from-widget,data-structr-insert,eventMapping,data-structr-reload-target,data-structr-tree-children,data-structr-manual-reload-target,data-structr-delay-or-interval,data-structr-rendering-mode,failureActions,reloadingActions,triggeredActions,failureNotificationActions,successNotificationActions
Group.public=blocked,isGroup,members,name,
Group.ui=blocked,customPermissionQueryAccessControl,customPermissionQueryDelete,customPermissionQueryRead,customPermissionQueryWrite,isGroup,members,jwksReferenceId,
Group.ui=blocked,isGroup,members,jwksReferenceId,
H1._html_=_html_accesskey,_html_class,_html_contenteditable,_html_contextmenu,_html_dir,_html_draggable,_html_dropzone,_html_hidden,_html_id,_html_lang,_html_onabort,_html_onblur,_html_oncanplay,_html_oncanplaythrough,_html_onchange,_html_onclick,_html_oncontextmenu,_html_ondblclick,_html_ondrag,_html_ondragend,_html_ondragenter,_html_ondragleave,_html_ondragover,_html_ondragstart,_html_ondrop,_html_ondurationchange,_html_onemptied,_html_onended,_html_onerror,_html_onfocus,_html_oninput,_html_oninvalid,_html_onkeydown,_html_onkeypress,_html_onkeyup,_html_onload,_html_onloadeddata,_html_onloadedmetadata,_html_onloadstart,_html_onmousedown,_html_onmousemove,_html_onmouseout,_html_onmouseover,_html_onmouseup,_html_onmousewheel,_html_onpause,_html_onplay,_html_onplaying,_html_onprogress,_html_onratechange,_html_onreadystatechange,_html_onreset,_html_onscroll,_html_onseeked,_html_onseeking,_html_onselect,_html_onshow,_html_onstalled,_html_onsubmit,_html_onsuspend,_html_ontimeupdate,_html_onvolumechange,_html_onwaiting,_html_role,_html_spellcheck,_html_style,_html_tabindex,_html_title,_html_translate,
H1.public=children,cypherQuery,dataKey,functionQuery,isDOMNode,name,pageId,parent,partialUpdateKey,path,restQuery,sharedComponentId,syncedNodesIds,tag,
H1.ui=_html_class,_html_id,children,childrenIds,cypherQuery,data-structr-id,dataKey,functionQuery,hideConditions,hideForLocales,isDOMNode,pageId,parent,partialUpdateKey,path,restQuery,sharedComponentId,sharedComponentConfiguration,showConditions,showForLocales,syncedNodesIds,tag,data-structr-from-widget,data-structr-insert,eventMapping,data-structr-reload-target,data-structr-tree-children,data-structr-manual-reload-target,data-structr-delay-or-interval,data-structr-rendering-mode,failureActions,reloadingActions,triggeredActions,failureNotificationActions,successNotificationActions
Expand Down
Loading

0 comments on commit 0a1b600

Please sign in to comment.