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

lambdify.apigateway.AuthPolicy Maven / Gradle / Ivy

package lambdify.apigateway;

import java.util.*;
import java.util.stream.Collectors;
import lambdify.apigateway.PolicyDocument.Statement;
import lombok.*;

@Value
public class AuthPolicy {

    public static final String
        VERSION = "Version",
        STATEMENT = "Statement",
        EFFECT = "Effect",
        ACTION = "Action",
        NOT_ACTION = "NotAction",
        RESOURCE = "Resource",
        NOT_RESOURCE = "NotResource",
        CONDITION = "Condition";

    String principalId;
    PolicyDocument policyDocument;
    Map context;
    String usageIdentifierKey;

    public Map getPolicyDocument(){
        val serializablePolicy = new HashMap();
        serializablePolicy.put(VERSION, policyDocument.version);
        val statements = policyDocument.getStatements();
        serializablePolicy.put(STATEMENT, statements.stream()
            .map( this::statementToMap ).collect(Collectors.toList() ) );
        return serializablePolicy;
    }

    private Map statementToMap(Statement statement) {
        val serializableStatement = new HashMap();
        serializableStatement.put(EFFECT, statement.effect);
        serializableStatement.put(ACTION, statement.action);
        serializableStatement.put(RESOURCE, statement.getResources());
        serializableStatement.put(CONDITION, statement.condition);
        return serializableStatement;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy