Skip to content

Instantly share code, notes, and snippets.

@gonzalad
Created August 30, 2016 13:01
Show Gist options
  • Save gonzalad/b547c70b36f32bee2ad17a0e304a74d5 to your computer and use it in GitHub Desktop.
Save gonzalad/b547c70b36f32bee2ad17a0e304a74d5 to your computer and use it in GitHub Desktop.
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