Skip to content
Browse files

added resource signatur to auth methods

  • Loading branch information...
1 parent 7c38612 commit 58a5b315af6aae9a88dec103198ce2e3651320b4 @amorgner amorgner committed May 21, 2012
Showing with 55 additions and 49 deletions.
  1. +7 −3 structr/structr-core/src/main/java/org/structr/common/SecurityContext.java
  2. +1 −1 structr/structr-core/src/main/java/org/structr/core/auth/Authenticator.java
  3. +1 −1 structr/structr-core/src/main/java/org/structr/core/auth/StructrAuthenticator.java
  4. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/auth/RestAuthenticator.java
  5. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/EntityResolverResource.java
  6. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/MaintenanceParameterResource.java
  7. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/MaintenanceResource.java
  8. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/NamedRelationIdResource.java
  9. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/NamedRelationResource.java
  10. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/PagingResource.java
  11. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/RelationshipFollowingResource.java
  12. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/RelationshipIdResource.java
  13. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/RelationshipNodeResource.java
  14. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/RelationshipResource.java
  15. +21 −19 structr/structr-rest/src/main/java/org/structr/rest/resource/Resource.java
  16. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/SortResource.java
  17. +2 −2 structr/structr-rest/src/main/java/org/structr/rest/resource/StaticRelationshipResource.java
  18. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/TypeResource.java
  19. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/TypedIdResource.java
  20. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/UuidResource.java
  21. +1 −1 structr/structr-rest/src/main/java/org/structr/rest/resource/ViewFilterResource.java
  22. +5 −5 structr/structr-rest/src/main/java/org/structr/rest/servlet/JsonRestServlet.java
  23. +1 −1 structr/structr-ui/src/main/java/org/structr/web/auth/HttpAuthenticator.java
  24. +1 −1 structr/structr-ui/src/main/java/org/structr/web/auth/UiAuthenticator.java
View
10 structr/structr-core/src/main/java/org/structr/common/SecurityContext.java
@@ -100,8 +100,8 @@ public void initializeAndExamineRequest(HttpServletRequest request, HttpServletR
this.authenticator.initializeAndExamineRequest(this, request, response);
}
- public void examineRequest(HttpServletRequest request, ResourceAccess resourceAccess, String propertyView) throws FrameworkException {
- this.authenticator.examineRequest(this, request, resourceAccess, propertyView);
+ public void examineRequest(HttpServletRequest request, String resourceSignature, ResourceAccess resourceAccess, String propertyView) throws FrameworkException {
+ this.authenticator.examineRequest(this, request, resourceSignature, resourceAccess, propertyView);
}
public Principal doLogin(String userName, String password) throws AuthenticationException {
@@ -249,7 +249,11 @@ public boolean isVisible(AccessControllable node) {
}
}
-
+
+ public static boolean hasFlag(String resourceSignature, long flag) {
+ return (getResourceFlags(resourceSignature) & flag) == flag;
+ }
+
public static long getResourceFlags(String resource) {
String name = EntityContext.normalizeEntityName(resource);
View
2 structr/structr-core/src/main/java/org/structr/core/auth/Authenticator.java
@@ -50,7 +50,7 @@
* @param request
* @throws FrameworkException
*/
- public void examineRequest(SecurityContext securityContext, HttpServletRequest request, ResourceAccess resourceAccess, String propertyView) throws FrameworkException;
+ public void examineRequest(SecurityContext securityContext, HttpServletRequest request, String resourceSignature, ResourceAccess resourceAccess, String propertyView) throws FrameworkException;
/**
*
View
2 structr/structr-core/src/main/java/org/structr/core/auth/StructrAuthenticator.java
@@ -61,7 +61,7 @@
public void initializeAndExamineRequest(SecurityContext securityContext, HttpServletRequest request, HttpServletResponse response) throws FrameworkException {}
@Override
- public void examineRequest(SecurityContext securityContext, HttpServletRequest request, ResourceAccess resourceAccess, String propertyView) throws FrameworkException { }
+ public void examineRequest(SecurityContext securityContext, HttpServletRequest request, String resourceSignature, ResourceAccess resourceAccess, String propertyView) throws FrameworkException { }
@Override
public Principal doLogin(SecurityContext securityContext, HttpServletRequest request, HttpServletResponse response, String userName, String password) throws AuthenticationException {
View
2 structr/structr-rest/src/main/java/org/structr/rest/auth/RestAuthenticator.java
@@ -50,7 +50,7 @@
public void initializeAndExamineRequest(SecurityContext securityContext, HttpServletRequest request, HttpServletResponse response) throws FrameworkException {}
@Override
- public void examineRequest(SecurityContext securityContext, HttpServletRequest request, ResourceAccess resourceAccess, String propertyView) throws FrameworkException { }
+ public void examineRequest(SecurityContext securityContext, HttpServletRequest request, String resourceSignature, ResourceAccess resourceAccess, String propertyView) throws FrameworkException { }
@Override
public Principal doLogin(SecurityContext securityContext, HttpServletRequest request, HttpServletResponse response, String userName, String password) throws AuthenticationException {
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/EntityResolverResource.java
@@ -91,7 +91,7 @@ public RestMethodResult doPut(final Map<String, Object> propertySet) throws Fram
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
2 ...tr/structr-rest/src/main/java/org/structr/rest/resource/MaintenanceParameterResource.java
@@ -127,7 +127,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/MaintenanceResource.java
@@ -169,7 +169,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/NamedRelationIdResource.java
@@ -134,7 +134,7 @@ public UuidResource getIdResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/NamedRelationResource.java
@@ -162,7 +162,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/PagingResource.java
@@ -92,7 +92,7 @@ public void postProcessResultSet(Result result) {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
2 ...r/structr-rest/src/main/java/org/structr/rest/resource/RelationshipFollowingResource.java
@@ -464,7 +464,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
StringBuilder uri = new StringBuilder();
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/RelationshipIdResource.java
@@ -149,7 +149,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/RelationshipNodeResource.java
@@ -119,7 +119,7 @@ public Resource tryCombineWith(Resource next) throws FrameworkException {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/RelationshipResource.java
@@ -112,7 +112,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
40 structr/structr-rest/src/main/java/org/structr/rest/resource/Resource.java
@@ -97,7 +97,7 @@
public abstract String getUriPart();
- public abstract String getUriPartForAccessControl();
+ public abstract String getResourceSignature();
// ----- methods -----
public RestMethodResult doDelete() throws FrameworkException {
@@ -217,7 +217,7 @@ public void setSecurityContext(SecurityContext securityContext) {
}
public ResourceAccess getGrant() throws FrameworkException {
- return findOrCreateGrant();
+ return findGrant();
}
// ----- protected methods -----
@@ -307,10 +307,10 @@ protected void applyDefaultSorting(List<GraphObject> list) {
}
}
- protected ResourceAccess findOrCreateGrant() throws FrameworkException {
+ protected ResourceAccess findGrant() throws FrameworkException {
Command search = Services.command(SecurityContext.getSuperUserInstance(), SearchNodeCommand.class);
- String uriPart = EntityContext.normalizeEntityName(this.getUriPartForAccessControl());
+ String uriPart = EntityContext.normalizeEntityName(this.getResourceSignature());
List<SearchAttribute> searchAttributes = new LinkedList<SearchAttribute>();
AbstractNode topNode = null;
boolean includeDeleted = false;
@@ -322,21 +322,23 @@ protected ResourceAccess findOrCreateGrant() throws FrameworkException {
List<AbstractNode> nodes = (List<AbstractNode>)search.execute(topNode, includeDeleted, publicOnly, searchAttributes);
if(nodes.isEmpty()) {
-
- // create new grant
- final Command create = Services.command(SecurityContext.getSuperUserInstance(), CreateNodeCommand.class);
- final Map<String, Object> newGrantAttributes = new LinkedHashMap<String, Object>();
-
- newGrantAttributes.put(AbstractNode.Key.type.name(), ResourceAccess.class.getSimpleName());
- newGrantAttributes.put(ResourceAccess.Key.uri.name(), uriPart);
- newGrantAttributes.put(ResourceAccess.Key.flags.name(), SecurityContext.getResourceFlags(uriPart));
-
- grant = (ResourceAccess)Services.command(SecurityContext.getSuperUserInstance(), TransactionCommand.class).execute(new StructrTransaction() {
-
- @Override public Object execute() throws FrameworkException {
- return create.execute(newGrantAttributes);
- }
- });
+
+ logger.log(Level.INFO, "No resource access object found for {0}", uriPart);
+
+// // create new grant
+// final Command create = Services.command(SecurityContext.getSuperUserInstance(), CreateNodeCommand.class);
+// final Map<String, Object> newGrantAttributes = new LinkedHashMap<String, Object>();
+//
+// newGrantAttributes.put(AbstractNode.Key.type.name(), ResourceAccess.class.getSimpleName());
+// newGrantAttributes.put(ResourceAccess.Key.uri.name(), uriPart);
+// newGrantAttributes.put(ResourceAccess.Key.flags.name(), SecurityContext.getResourceFlags(uriPart));
+//
+// grant = (ResourceAccess)Services.command(SecurityContext.getSuperUserInstance(), TransactionCommand.class).execute(new StructrTransaction() {
+//
+// @Override public Object execute() throws FrameworkException {
+// return create.execute(newGrantAttributes);
+// }
+// });
} else {
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/SortResource.java
@@ -85,7 +85,7 @@ public void postProcessResultSet(Result result) {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
4 structr/structr-rest/src/main/java/org/structr/rest/resource/StaticRelationshipResource.java
@@ -483,7 +483,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
- return typedIdResource.getUriPartForAccessControl().concat("/").concat(typeResource.getUriPartForAccessControl());
+ public String getResourceSignature() {
+ return typedIdResource.getResourceSignature().concat("/").concat(typeResource.getResourceSignature());
}
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/TypeResource.java
@@ -257,7 +257,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/TypedIdResource.java
@@ -129,7 +129,7 @@ public String getUriPart() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return typeResource.getUriPart();
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/UuidResource.java
@@ -138,7 +138,7 @@ public boolean isCollectionResource() {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return "/";
}
}
View
2 structr/structr-rest/src/main/java/org/structr/rest/resource/ViewFilterResource.java
@@ -92,7 +92,7 @@ public void configurePropertyView(Value<String> propertyView) {
}
@Override
- public String getUriPartForAccessControl() {
+ public String getResourceSignature() {
return getUriPart();
}
}
View
10 structr/structr-rest/src/main/java/org/structr/rest/servlet/JsonRestServlet.java
@@ -245,7 +245,7 @@ protected void doDelete(final HttpServletRequest request, final HttpServletRespo
Resource resourceConstraint = optimizeConstraintChain(chain);
// let authenticator examine request again
- securityContext.examineRequest(request, resourceConstraint.getGrant(), propertyView.get());
+ securityContext.examineRequest(request, resourceConstraint.getResourceSignature(), resourceConstraint.getGrant(), propertyView.get());
// do action
RestMethodResult result = resourceConstraint.doDelete();
@@ -311,7 +311,7 @@ protected void doGet(final HttpServletRequest request, final HttpServletResponse
Resource resource = addSortingAndPaging(request, securityContext, optimizeConstraintChain(parsePath(securityContext, request)));
// let authenticator examine request again
- securityContext.examineRequest(request, resource.getGrant(), propertyView.get());
+ securityContext.examineRequest(request, resource.getResourceSignature(), resource.getGrant(), propertyView.get());
// do action
Result result = new Result(resource.doGet(), resource.isCollectionResource(), resource.isPrimitiveArray());
@@ -404,7 +404,7 @@ protected void doHead(HttpServletRequest request, HttpServletResponse response)
Resource resourceConstraint = optimizeConstraintChain(chain);
// let authenticator examine request again
- securityContext.examineRequest(request, resourceConstraint.getGrant(), propertyView.get());
+ securityContext.examineRequest(request, resourceConstraint.getResourceSignature(), resourceConstraint.getGrant(), propertyView.get());
// do action
RestMethodResult result = resourceConstraint.doHead();
@@ -465,7 +465,7 @@ protected void doOptions(HttpServletRequest request, HttpServletResponse respons
Resource resourceConstraint = optimizeConstraintChain(chain);
// let authenticator examine request again
- securityContext.examineRequest(request, resourceConstraint.getGrant(), propertyView.get());
+ securityContext.examineRequest(request, resourceConstraint.getResourceSignature(), resourceConstraint.getGrant(), propertyView.get());
// do action
RestMethodResult result = resourceConstraint.doOptions();
@@ -532,7 +532,7 @@ protected void doPost(final HttpServletRequest request, HttpServletResponse resp
Map<String, Object> properties = convertPropertySetToMap(propertySet);
// let authenticator examine request again
- securityContext.examineRequest(request, resourceConstraint.getGrant(), propertyView.get());
+ securityContext.examineRequest(request, resourceConstraint.getResourceSignature(), resourceConstraint.getGrant(), propertyView.get());
// do action
RestMethodResult result = resourceConstraint.doPost(properties);
View
2 structr/structr-ui/src/main/java/org/structr/web/auth/HttpAuthenticator.java
@@ -60,7 +60,7 @@
public void initializeAndExamineRequest(SecurityContext securityContext, HttpServletRequest request, HttpServletResponse response) throws FrameworkException {}
@Override
- public void examineRequest(SecurityContext securityContext, HttpServletRequest request, ResourceAccess resourceAccess, String propertyView) throws FrameworkException { }
+ public void examineRequest(SecurityContext securityContext, HttpServletRequest request, String resourceSignature, ResourceAccess resourceAccess, String propertyView) throws FrameworkException { }
@Override
public Principal doLogin(SecurityContext securityContext, HttpServletRequest request, HttpServletResponse response, String userName, String password) throws AuthenticationException {
View
2 structr/structr-ui/src/main/java/org/structr/web/auth/UiAuthenticator.java
@@ -48,7 +48,7 @@ public void initializeAndExamineRequest(SecurityContext securityContext, HttpSer
}
@Override
- public void examineRequest(SecurityContext securityContext, HttpServletRequest request, ResourceAccess resourceAccess, String propertyView) throws FrameworkException { }
+ public void examineRequest(SecurityContext securityContext, HttpServletRequest request, String resourceSignature, ResourceAccess resourceAccess, String propertyView) throws FrameworkException { }
@Override
public Principal doLogin(SecurityContext securityContext, HttpServletRequest request, HttpServletResponse response, String userName, String password) throws AuthenticationException {

0 comments on commit 58a5b31

Please sign in to comment.
Something went wrong with that request. Please try again.