Skip to content
This repository was archived by the owner on Aug 19, 2020. It is now read-only.

Commit e875ad5

Browse files
committedAug 4, 2014
WIP
1 parent cea401f commit e875ad5

File tree

6 files changed

+35
-18
lines changed

6 files changed

+35
-18
lines changed
 

‎Security-Readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Dendrite - Security
2+
3+
Dendrite uses Spring security in two ways :
4+
5+
1. At the controller level - it filters incoming requests to check and see if it should honor a request.
6+
2. At the service level - it uses the pre-method invocation filter to check and see if the current user
7+
has access to the graph in question by checking the ownership of project.
8+

‎src/main/java/org/lab41/dendrite/metagraph/MetaGraphTx.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.tinkerpop.frames.FramedGraphFactory;
66
import com.tinkerpop.frames.FramedTransactionalGraph;
77

8+
import java.security.Principal;
9+
810
public class MetaGraphTx {
911

1012
private FramedTransactionalGraph<DendriteGraphTx> tx = null;
@@ -25,20 +27,27 @@ public Iterable<ProjectMetadata> getProjects() {
2527
return getVertices("project", ProjectMetadata.class);
2628
}
2729

30+
public UserMetadata getUser(String name)
31+
{
32+
return getVertex(name, "user", UserMetadata.class);
33+
}
34+
2835
public ProjectMetadata getProject(String projectId) {
2936
return getVertex(projectId, "project", ProjectMetadata.class);
3037
}
3138

32-
public ProjectMetadata createProject(String name) {
33-
return createProject(name, true);
39+
public ProjectMetadata createProject(String name, Principal principal) {
40+
return createProject(name, principal, true);
3441
}
3542

36-
public ProjectMetadata createProject(String name, boolean createBranch) {
43+
public ProjectMetadata createProject(String name, Principal principle, boolean createBranch) {
3744
Preconditions.checkArgument(!name.isEmpty());
3845

3946
ProjectMetadata projectMetadata = createVertex("project", ProjectMetadata.class);
4047
projectMetadata.setName(name);
4148

49+
UserMetadata userMetadata = createVertex("user", UserMetadata.class);
50+
4251
if (createBranch) {
4352
BranchMetadata branchMetadata = createBranch("master", projectMetadata);
4453
projectMetadata.setCurrentBranch(branchMetadata);

‎src/main/java/org/lab41/dendrite/metagraph/models/ProjectMetadata.java

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public interface ProjectMetadata extends NamedMetadata {
3232
@JavaHandler
3333
public GraphMetadata getCurrentGraph();
3434

35+
@Adjacency(label = "userOwnsProject", direction = Direction.OUT)
36+
public void setUserOwnsProject(UserMetadata user);
37+
38+
@Adjacency(label = "userOwnsProject", direction = Direction.OUT)
39+
public UserMetadata getUserOwnsProject();
40+
3541
@Adjacency(label = "ownsBranch", direction = Direction.OUT)
3642
public Iterable<BranchMetadata> getBranches();
3743

‎src/main/java/org/lab41/dendrite/metagraph/models/UserMetadata.java

+2-14
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
import com.tinkerpop.blueprints.Direction;
44
import com.tinkerpop.frames.Adjacency;
55
import com.tinkerpop.frames.Property;
6+
import com.tinkerpop.frames.modules.typedgraph.TypeValue;
67

78
/**
89
* Models a user. Keeps track of what projects they belong to.
910
*/
11+
@TypeValue("user")
1012
public interface UserMetadata extends NamedMetadata {
1113

12-
@Property("LDAPString")
13-
public String getLDAPString();
14-
15-
@Property("LDAPString")
16-
public void setLDAPString();
1714

1815
/**
1916
* Returns all the projects created by this user
@@ -24,14 +21,5 @@ public interface UserMetadata extends NamedMetadata {
2421
public Iterable<ProjectMetadata> getCreatedProjects();
2522

2623

27-
/**
28-
* Returns all the projects that have been shared with
29-
* this user by other users.
30-
*
31-
* @return
32-
*/
33-
@Adjacency(label = "sharedWith", direction = Direction.IN)
34-
public Iterable<ProjectMetadata> getSharedProjects();
35-
3624
}
3725

‎src/main/java/org/lab41/dendrite/services/MetaGraphService.java

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.springframework.beans.factory.annotation.Value;
1414
import org.springframework.core.io.Resource;
1515
import org.springframework.core.io.ResourceLoader;
16+
import org.springframework.security.access.prepost.PreAuthorize;
1617
import org.springframework.stereotype.Service;
1718

1819
import java.io.IOException;
@@ -45,6 +46,7 @@ public Set<String> getGraphNames() {
4546
return metaGraph.getGraphNames();
4647
}
4748

49+
4850
public Collection<DendriteGraph> getGraphs() {
4951
return metaGraph.getGraphs();
5052
}

‎src/main/java/org/lab41/dendrite/web/controller/ProjectController.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.springframework.web.util.UriComponentsBuilder;
1919

2020
import javax.validation.Valid;
21+
import java.security.Principal;
2122
import java.text.SimpleDateFormat;
2223
import java.util.*;
2324

@@ -78,10 +79,13 @@ public ResponseEntity<Map<String, Object>> getProject(@PathVariable String proje
7879
@RequestMapping(value = "/projects", method = RequestMethod.POST)
7980
public ResponseEntity<Map<String, Object>> createProject(@Valid @RequestBody CreateProjectBean item,
8081
BindingResult result,
81-
UriComponentsBuilder builder) {
82+
UriComponentsBuilder builder,
83+
Principal principal) {
8284

8385
Map<String, Object> response = new HashMap<>();
8486

87+
logger.debug("Principal" + principal.getName());
88+
8589
if (result.hasErrors()) {
8690
response.put("status", "error");
8791
response.put("msg", result.toString());

0 commit comments

Comments
 (0)