Example usage for com.amazonaws.services.identitymanagement.model PutGroupPolicyRequest PutGroupPolicyRequest

List of usage examples for com.amazonaws.services.identitymanagement.model PutGroupPolicyRequest PutGroupPolicyRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.identitymanagement.model PutGroupPolicyRequest PutGroupPolicyRequest.

Prototype

public PutGroupPolicyRequest(String groupName, String policyName, String policyDocument) 

Source Link

Document

Constructs a new PutGroupPolicyRequest object.

Usage

From source file:org.dasein.prototype.iamc.AWS.java

License:Apache License

public boolean grantAccessToUser(String username, Service service) {
    String entityName;/*from   w w w. j a va2 s  .c  o m*/
    Action action;
    switch (service) {
    case ElasticBeanstalk:
        entityName = "iamc-eb";
        action = ElasticBeanstalkActions.AllElasticBeanstalkActions;
        break;
    case EC2:
        entityName = "iamc-ec2";
        action = EC2Actions.AllEC2Actions;
        break;
    default:
        return false;
    }
    try {
        iamClient.getGroup(new GetGroupRequest(entityName));
    } catch (NoSuchEntityException e) {
        iamClient.createGroup(new CreateGroupRequest(entityName));
    }
    Policy policy = new Policy(entityName).withStatements(
            new Statement(Statement.Effect.Allow).withActions(action).withResources(new Resource("*")));
    iamClient.putGroupPolicy(new PutGroupPolicyRequest(entityName, entityName, policy.toJson()));
    iamClient.addUserToGroup(new AddUserToGroupRequest(entityName, username));
    return true;
}