All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.kickstart.execution.GraphQLInvokerSubjectProxy Maven / Gradle / Ivy

There is a newer version: 16.0.0
Show newest version
package graphql.kickstart.execution;

import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.kickstart.execution.context.GraphQLContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.CompletableFuture;
import javax.security.auth.Subject;

public class GraphQLInvokerSubjectProxy implements GraphQLInvokerProxy {

  @Override
  public CompletableFuture executeAsync(GraphQL graphQL, ExecutionInput executionInput) {
    GraphQLContext context = (GraphQLContext) executionInput.getContext();
    if (Subject.getSubject(AccessController.getContext()) == null && context.getSubject().isPresent()) {
      return Subject
          .doAs(context.getSubject().get(), (PrivilegedAction>) () -> {
            try {
              return graphQL.executeAsync(executionInput);
            } catch (Exception e) {
              throw new RuntimeException(e);
            }
          });
    }
    return graphQL.executeAsync(executionInput);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy