| 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.vcloud.domain.network.firewall; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import org.jclouds.javax.annotation.Nullable; |
| 24 | |
| 25 | /** |
| 26 | * The FirewallRule element defines a single firewall rule. |
| 27 | * |
| 28 | * @author Adrian Cole |
| 29 | * @since vcloud api 0.8 |
| 30 | */ |
| 31 | public class FirewallRule { |
| 32 | |
| 33 | private final boolean enabled; |
| 34 | @Nullable |
| 35 | private final String description; |
| 36 | @Nullable |
| 37 | private final FirewallPolicy policy; |
| 38 | @Nullable |
| 39 | private final FirewallProtocols protocols; |
| 40 | private final int port; |
| 41 | private final String destinationIp; |
| 42 | |
| 43 | public FirewallRule(boolean enabled, @Nullable String description, @Nullable FirewallPolicy policy, |
| 44 | @Nullable FirewallProtocols protocols, int port, String destinationIp) { |
| 45 | this.enabled = enabled; |
| 46 | this.description = description; |
| 47 | this.policy = policy; |
| 48 | this.protocols = protocols; |
| 49 | this.port = port; |
| 50 | this.destinationIp = checkNotNull(destinationIp, "destinationIp"); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @return true if the rule is enabled |
| 55 | */ |
| 56 | public boolean isEnabled() { |
| 57 | return enabled; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return description of the rule |
| 62 | */ |
| 63 | @Nullable |
| 64 | public String getDescription() { |
| 65 | return description; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return specifies how packets are handled by the firewall |
| 70 | */ |
| 71 | @Nullable |
| 72 | public FirewallPolicy getPolicy() { |
| 73 | return policy; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @return specifies the protocols to which this firewall rule applies |
| 78 | */ |
| 79 | @Nullable |
| 80 | public FirewallProtocols getProtocols() { |
| 81 | return protocols; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @return specifies the network port to which this firewall rule applies. A value of ?1 matches |
| 86 | * any port. |
| 87 | */ |
| 88 | public int getPort() { |
| 89 | return port; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @return specifies the destination IP address, inside the firewall, to which this firewall rule |
| 94 | * applies |
| 95 | */ |
| 96 | public String getDestinationIp() { |
| 97 | return destinationIp; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public int hashCode() { |
| 102 | final int prime = 31; |
| 103 | int result = 1; |
| 104 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 105 | result = prime * result + ((destinationIp == null) ? 0 : destinationIp.hashCode()); |
| 106 | result = prime * result + (enabled ? 1231 : 1237); |
| 107 | result = prime * result + ((policy == null) ? 0 : policy.hashCode()); |
| 108 | result = prime * result + port; |
| 109 | result = prime * result + ((protocols == null) ? 0 : protocols.hashCode()); |
| 110 | return result; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public boolean equals(Object obj) { |
| 115 | if (this == obj) |
| 116 | return true; |
| 117 | if (obj == null) |
| 118 | return false; |
| 119 | if (getClass() != obj.getClass()) |
| 120 | return false; |
| 121 | FirewallRule other = (FirewallRule) obj; |
| 122 | if (description == null) { |
| 123 | if (other.description != null) |
| 124 | return false; |
| 125 | } else if (!description.equals(other.description)) |
| 126 | return false; |
| 127 | if (destinationIp == null) { |
| 128 | if (other.destinationIp != null) |
| 129 | return false; |
| 130 | } else if (!destinationIp.equals(other.destinationIp)) |
| 131 | return false; |
| 132 | if (enabled != other.enabled) |
| 133 | return false; |
| 134 | if (policy == null) { |
| 135 | if (other.policy != null) |
| 136 | return false; |
| 137 | } else if (!policy.equals(other.policy)) |
| 138 | return false; |
| 139 | if (port != other.port) |
| 140 | return false; |
| 141 | if (protocols == null) { |
| 142 | if (other.protocols != null) |
| 143 | return false; |
| 144 | } else if (!protocols.equals(other.protocols)) |
| 145 | return false; |
| 146 | return true; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public String toString() { |
| 151 | return "[description=" + description + ", destinationIp=" + destinationIp + ", enabled=" + enabled + ", policy=" |
| 152 | + policy + ", port=" + port + ", protocols=" + protocols + "]"; |
| 153 | } |
| 154 | |
| 155 | } |