Created
August 30, 2016 13:01
-
-
Save gonzalad/b547c70b36f32bee2ad17a0e304a74d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProjectController { | |
private List<ProjectResource> projectResources = Arrays.asList(new ProjectResource("myProject1"), new ProjectResource("myProject2")); | |
@PreAuthorize("#oauth2.hasScope('urn:talend:project:read')") | |
@RequestMapping(method = RequestMethod.GET) | |
public List<ProjectResource> findAllProjects(Authentication authentication) { | |
// get projects from repository | |
List<ProjectResource> projectResources = this.projectResources; | |
OAuth2Request clientAuthentication = ((OAuth2Authentication) authentication).getOAuth2Request(); | |
// filter with OAuth scopes | |
List<ProjectResource> filteredProjectResources = projectResources.stream() | |
.filter( | |
project -> clientAuthentication.getScope().contains("urn:talend:project:" +project.getName()+":read") | |
).collect(Collectors.toList()); | |
return filteredProjectResources; | |
} | |
@PreAuthorize("#oauth2.hasScope('urn:talend:project:' + #name + ':read')") | |
@RequestMapping(value = "/{name}", method = RequestMethod.GET) | |
public ProjectResource getProjectDetails(@PathVariable("name") String name) { | |
return projectResources.stream() | |
.filter( | |
project -> project.getName().equals(name) | |
).findAny().get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment