Search in sources :

Example 1 with AuthenticationUser

use of com.yahoo.elide.spring.security.AuthenticationUser in project elide by yahoo.

the class JsonApiController method elideGet.

@GetMapping(value = "/**", produces = JSON_API_CONTENT_TYPE)
public Callable<ResponseEntity<String>> elideGet(@RequestHeader HttpHeaders requestHeaders, @RequestParam MultiValueMap<String, String> allRequestParams, HttpServletRequest request, Authentication authentication) {
    final String apiVersion = HeaderUtils.resolveApiVersion(requestHeaders);
    final Map<String, List<String>> requestHeadersCleaned = HeaderUtils.lowercaseAndRemoveAuthHeaders(requestHeaders);
    final String pathname = getJsonApiPath(request, settings.getJsonApi().getPath());
    final User user = new AuthenticationUser(authentication);
    final String baseUrl = getBaseUrlEndpoint();
    return new Callable<ResponseEntity<String>>() {

        @Override
        public ResponseEntity<String> call() throws Exception {
            ElideResponse response = elide.get(baseUrl, pathname, convert(allRequestParams), requestHeadersCleaned, user, apiVersion, UUID.randomUUID());
            return ResponseEntity.status(response.getResponseCode()).body(response.getBody());
        }
    };
}
Also used : User(com.yahoo.elide.core.security.User) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) ElideResponse(com.yahoo.elide.ElideResponse) List(java.util.List) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) Callable(java.util.concurrent.Callable) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with AuthenticationUser

use of com.yahoo.elide.spring.security.AuthenticationUser in project elide by yahoo.

the class GraphqlController method post.

/**
 * Single entry point for GraphQL requests.
 *
 * @param requestHeaders request headers
 * @param graphQLDocument post data as json document
 * @param principal The user principal
 * @return response
 */
@PostMapping(value = { "/**", "" }, consumes = JSON_CONTENT_TYPE, produces = JSON_CONTENT_TYPE)
public Callable<ResponseEntity<String>> post(@RequestHeader HttpHeaders requestHeaders, @RequestBody String graphQLDocument, Authentication principal) {
    final User user = new AuthenticationUser(principal);
    final String apiVersion = HeaderUtils.resolveApiVersion(requestHeaders);
    final Map<String, List<String>> requestHeadersCleaned = HeaderUtils.lowercaseAndRemoveAuthHeaders(requestHeaders);
    final QueryRunner runner = runners.getRunner(apiVersion);
    final String baseUrl = getBaseUrlEndpoint();
    return new Callable<ResponseEntity<String>>() {

        @Override
        public ResponseEntity<String> call() throws Exception {
            ElideResponse response;
            if (runner == null) {
                response = buildErrorResponse(mapper, new InvalidOperationException("Invalid API Version"), false);
            } else {
                Elide elide = runner.getElide();
                response = runner.run(baseUrl, graphQLDocument, user, UUID.randomUUID(), requestHeadersCleaned);
            }
            return ResponseEntity.status(response.getResponseCode()).body(response.getBody());
        }
    };
}
Also used : User(com.yahoo.elide.core.security.User) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) ElideResponse(com.yahoo.elide.ElideResponse) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) List(java.util.List) Elide(com.yahoo.elide.Elide) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) QueryRunner(com.yahoo.elide.graphql.QueryRunner) Callable(java.util.concurrent.Callable) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with AuthenticationUser

use of com.yahoo.elide.spring.security.AuthenticationUser in project elide by yahoo.

the class JsonApiController method elidePost.

@PostMapping(value = "/**", consumes = JSON_API_CONTENT_TYPE, produces = JSON_API_CONTENT_TYPE)
public Callable<ResponseEntity<String>> elidePost(@RequestHeader HttpHeaders requestHeaders, @RequestParam MultiValueMap<String, String> allRequestParams, @RequestBody String body, HttpServletRequest request, Authentication authentication) {
    final String apiVersion = HeaderUtils.resolveApiVersion(requestHeaders);
    final Map<String, List<String>> requestHeadersCleaned = HeaderUtils.lowercaseAndRemoveAuthHeaders(requestHeaders);
    final String pathname = getJsonApiPath(request, settings.getJsonApi().getPath());
    final User user = new AuthenticationUser(authentication);
    final String baseUrl = getBaseUrlEndpoint();
    return new Callable<ResponseEntity<String>>() {

        @Override
        public ResponseEntity<String> call() throws Exception {
            ElideResponse response = elide.post(baseUrl, pathname, body, convert(allRequestParams), requestHeadersCleaned, user, apiVersion, UUID.randomUUID());
            return ResponseEntity.status(response.getResponseCode()).body(response.getBody());
        }
    };
}
Also used : User(com.yahoo.elide.core.security.User) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) ElideResponse(com.yahoo.elide.ElideResponse) List(java.util.List) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) Callable(java.util.concurrent.Callable) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with AuthenticationUser

use of com.yahoo.elide.spring.security.AuthenticationUser in project elide by yahoo.

the class JsonApiController method elideDeleteRelation.

@DeleteMapping(value = "/**", consumes = JSON_API_CONTENT_TYPE)
public Callable<ResponseEntity<String>> elideDeleteRelation(@RequestHeader HttpHeaders requestHeaders, @RequestParam MultiValueMap<String, String> allRequestParams, @RequestBody String body, HttpServletRequest request, Authentication authentication) {
    final String apiVersion = HeaderUtils.resolveApiVersion(requestHeaders);
    final Map<String, List<String>> requestHeadersCleaned = HeaderUtils.lowercaseAndRemoveAuthHeaders(requestHeaders);
    final String pathname = getJsonApiPath(request, settings.getJsonApi().getPath());
    final User user = new AuthenticationUser(authentication);
    final String baseUrl = getBaseUrlEndpoint();
    return new Callable<ResponseEntity<String>>() {

        @Override
        public ResponseEntity<String> call() throws Exception {
            ElideResponse response = elide.delete(baseUrl, pathname, body, convert(allRequestParams), requestHeadersCleaned, user, apiVersion, UUID.randomUUID());
            return ResponseEntity.status(response.getResponseCode()).body(response.getBody());
        }
    };
}
Also used : User(com.yahoo.elide.core.security.User) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) ElideResponse(com.yahoo.elide.ElideResponse) List(java.util.List) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) Callable(java.util.concurrent.Callable) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 5 with AuthenticationUser

use of com.yahoo.elide.spring.security.AuthenticationUser in project elide by yahoo.

the class JsonApiController method elidePatch.

@PatchMapping(value = "/**", consumes = { JSON_API_CONTENT_TYPE, JSON_API_PATCH_CONTENT_TYPE })
public Callable<ResponseEntity<String>> elidePatch(@RequestHeader HttpHeaders requestHeaders, @RequestParam MultiValueMap<String, String> allRequestParams, @RequestBody String body, HttpServletRequest request, Authentication authentication) {
    final String apiVersion = HeaderUtils.resolveApiVersion(requestHeaders);
    final Map<String, List<String>> requestHeadersCleaned = HeaderUtils.lowercaseAndRemoveAuthHeaders(requestHeaders);
    final String pathname = getJsonApiPath(request, settings.getJsonApi().getPath());
    final User user = new AuthenticationUser(authentication);
    final String baseUrl = getBaseUrlEndpoint();
    return new Callable<ResponseEntity<String>>() {

        @Override
        public ResponseEntity<String> call() throws Exception {
            ElideResponse response = elide.patch(baseUrl, request.getContentType(), request.getContentType(), pathname, body, convert(allRequestParams), requestHeadersCleaned, user, apiVersion, UUID.randomUUID());
            return ResponseEntity.status(response.getResponseCode()).body(response.getBody());
        }
    };
}
Also used : User(com.yahoo.elide.core.security.User) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) ElideResponse(com.yahoo.elide.ElideResponse) List(java.util.List) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) Callable(java.util.concurrent.Callable) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Aggregations

ElideResponse (com.yahoo.elide.ElideResponse)6 User (com.yahoo.elide.core.security.User)6 AuthenticationUser (com.yahoo.elide.spring.security.AuthenticationUser)6 List (java.util.List)6 Callable (java.util.concurrent.Callable)6 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 Elide (com.yahoo.elide.Elide)1 InvalidOperationException (com.yahoo.elide.core.exceptions.InvalidOperationException)1 QueryRunner (com.yahoo.elide.graphql.QueryRunner)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1