如何在AWS API Gateway中使用Java 8编写的自定义授权程序中读取请求标头

时间:2018-02-06 21:05:56

标签: java amazon-web-services aws-api-gateway

我正在尝试使用Java 8在AWS API Gateway中创建基于令牌的自定义授权程序。但不确定如何读取Token哪个客户端将在Request Header中发送。 在下面的代码中,Token POJO Class被映射到Request Body。但我需要从请求标题中读取令牌。

public AccessPolicy handleRequest (Token t, Context context) {

        System.out.println("Token : "+t.getToken());
        context.getLogger().log("Token : "+t.getToken());
        context.
        if(t.getToken()!=null) {
            AccessPolicy policy = new AccessPolicy();

            Statement statement = new Statement();
            statement.setEffect(t.getToken());

            List<String> action = new ArrayList<String>();
            action.add("execute-api:Invoke");
            statement.setAction(action);

            List<String> resource = new ArrayList<String>();
            resource.add("*");
            statement.setResource(resource);

            policy.setVersion("2012-10-17");
            policy.setStatement(statement);

            return policy;
        }
        return null;
}

public class AccessPolicy {

    private String Version;
    private Statement Statement;
    public String getVersion() {
        return Version;
    }
    public void setVersion(String version) {
        this.Version = version;
    }
    public Statement getStatement() {
        return Statement;
    }
    public void setStatement(Statement statement) {
        this.Statement = statement;
    }
}

0 个答案:

没有答案