| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.ec2.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.Set; |
| 24 | |
| 25 | import com.google.common.collect.Iterables; |
| 26 | import com.google.common.collect.Sets; |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-LaunchPermissionItemType.html" |
| 31 | * /> |
| 32 | * @author Adrian Cole |
| 33 | */ |
| 34 | public class Permission { |
| 35 | private final Set<String> groups = Sets.newHashSet(); |
| 36 | private final Set<String> userIds = Sets.newHashSet(); |
| 37 | |
| 38 | public Permission(Iterable<String> userIds, Iterable<String> groups) { |
| 39 | Iterables.addAll(this.userIds, checkNotNull(userIds, "userIds")); |
| 40 | Iterables.addAll(this.groups, checkNotNull(groups, "groups")); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public int hashCode() { |
| 45 | final int prime = 31; |
| 46 | int result = 1; |
| 47 | result = prime * result + ((groups == null) ? 0 : groups.hashCode()); |
| 48 | result = prime * result + ((userIds == null) ? 0 : userIds.hashCode()); |
| 49 | return result; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public boolean equals(Object obj) { |
| 54 | if (this == obj) |
| 55 | return true; |
| 56 | if (obj == null) |
| 57 | return false; |
| 58 | if (getClass() != obj.getClass()) |
| 59 | return false; |
| 60 | Permission other = (Permission) obj; |
| 61 | if (groups == null) { |
| 62 | if (other.groups != null) |
| 63 | return false; |
| 64 | } else if (!groups.equals(other.groups)) |
| 65 | return false; |
| 66 | if (userIds == null) { |
| 67 | if (other.userIds != null) |
| 68 | return false; |
| 69 | } else if (!userIds.equals(other.userIds)) |
| 70 | return false; |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * |
| 76 | * @return Name of the group. Currently supports \"all.\" |
| 77 | */ |
| 78 | public Set<String> getGroups() { |
| 79 | return groups; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * |
| 84 | * @return AWS Access Key ID. |
| 85 | */ |
| 86 | public Set<String> getUserIds() { |
| 87 | return userIds; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return "LaunchPermission [groups=" + groups + ", userIds=" + userIds + "]"; |
| 93 | } |
| 94 | |
| 95 | } |