Simon Hunt | ce55af5 | 2017-10-24 16:57:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.opencord.aaa.api; |
| 17 | |
| 18 | import org.onlab.packet.MacAddress; |
| 19 | import org.onlab.packet.VlanId; |
| 20 | import org.onosproject.event.AbstractEvent; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | /** |
| 26 | * Describes an authentication event. Note that the subject of the event |
| 27 | * is a {@link ConnectPoint}, but the event also carries fields for |
| 28 | * a {@link VlanId VLAN} and {@link org.onlab.packet.MacAddress MAC} to |
| 29 | * be specified if desired. |
| 30 | */ |
| 31 | public class AaaEvent extends AbstractEvent<AaaEvent.Type, ConnectPoint> { |
| 32 | |
| 33 | /** |
| 34 | * Designates the type of authentication event. |
| 35 | */ |
| 36 | public enum Type { |
| 37 | /** |
| 38 | * A supplicant has started an authorization request handshake. |
| 39 | */ |
| 40 | AUTH_START, |
| 41 | |
| 42 | /** |
| 43 | * A supplicant has submitted an authorization request. |
| 44 | */ |
| 45 | AUTH_REQUEST_ACCESS, |
| 46 | |
| 47 | /** |
| 48 | * The authorization request has been accepted. |
| 49 | */ |
| 50 | ACCESS_AUTHORIZED, |
| 51 | |
| 52 | /** |
| 53 | * The authorization request has been denied. |
| 54 | */ |
| 55 | ACCESS_DENIED, |
| 56 | |
| 57 | /** |
| 58 | * The supplicant has terminated the authenticated session. |
| 59 | */ |
| 60 | AUTH_LOGOFF |
| 61 | } |
| 62 | |
| 63 | // a VLAN associated with the event |
| 64 | private final VlanId vlanId; |
| 65 | |
| 66 | // a MAC address associated with the event |
| 67 | private final MacAddress macAddress; |
| 68 | |
| 69 | /** |
| 70 | * Creates an event of the given type, for the specified connect point and |
| 71 | * the current time. |
| 72 | * The VLAN and MAC fields are left as null. |
| 73 | * |
| 74 | * @param type authentication event type |
| 75 | * @param subject event connect point subject |
| 76 | */ |
| 77 | public AaaEvent(Type type, ConnectPoint subject) { |
| 78 | super(type, subject); |
| 79 | vlanId = null; |
| 80 | macAddress = null; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Creates an event of the given type, for the specified connect point, |
| 85 | * and time. |
| 86 | * The VLAN and MAC fields are left as null. |
| 87 | * |
| 88 | * @param type authentication event type |
| 89 | * @param subject event connect point subject |
| 90 | * @param time occurrence time |
| 91 | */ |
| 92 | public AaaEvent(Type type, ConnectPoint subject, long time) { |
| 93 | super(type, subject, time); |
| 94 | vlanId = null; |
| 95 | macAddress = null; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Creates an event of the given type, for the specified connect point and |
| 100 | * the current time. |
| 101 | * Additionally, associated VLAN and MAC may be defined (null permitted). |
| 102 | * |
| 103 | * @param type authentication event type |
| 104 | * @param subject event connect point subject |
| 105 | * @param vlanId a VLAN associated with this event (or null) |
| 106 | * @param macAddress a MAC address associated with ths event (or null) |
| 107 | */ |
| 108 | public AaaEvent(Type type, ConnectPoint subject, VlanId vlanId, |
| 109 | MacAddress macAddress) { |
| 110 | super(type, subject); |
| 111 | this.vlanId = vlanId; |
| 112 | this.macAddress = macAddress; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Creates an event of the given type, for the specified connect point, |
| 117 | * and time. |
| 118 | * Additionally, associated VLAN and MAC may be defined (null permitted). |
| 119 | * |
| 120 | * @param type authentication event type |
| 121 | * @param subject event connect point subject |
| 122 | * @param time occurrence time |
| 123 | * @param vlanId a VLAN associated with this event |
| 124 | * @param macAddress a MAC address associated with ths event (or null) |
| 125 | */ |
| 126 | public AaaEvent(Type type, ConnectPoint subject, long time, VlanId vlanId, |
| 127 | MacAddress macAddress) { |
| 128 | super(type, subject, time); |
| 129 | this.vlanId = vlanId; |
| 130 | this.macAddress = macAddress; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Returns the VLAN ID associated with this event (may be null). |
| 135 | * |
| 136 | * @return the associated VLAN ID |
| 137 | */ |
| 138 | public VlanId vlanId() { |
| 139 | return vlanId; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Returns the MAC address associated with this event (may be null). |
| 144 | * |
| 145 | * @return the associated MAC address |
| 146 | */ |
| 147 | public MacAddress macAddress() { |
| 148 | return macAddress; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | @Override |
| 153 | public boolean equals(Object o) { |
| 154 | if (this == o) { |
| 155 | return true; |
| 156 | } |
| 157 | if (o instanceof AaaEvent) { |
| 158 | final AaaEvent other = (AaaEvent) o; |
| 159 | return Objects.equals(this.type(), other.type()) && |
| 160 | Objects.equals(this.subject(), other.subject()) && |
| 161 | Objects.equals(this.time(), other.time()) && |
| 162 | Objects.equals(this.vlanId(), other.vlanId()) && |
| 163 | Objects.equals(this.macAddress(), other.macAddress()); |
| 164 | } |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public int hashCode() { |
| 170 | return Objects.hash(type(), subject(), time(), vlanId(), macAddress()); |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public String toString() { |
| 175 | StringBuilder sb = new StringBuilder(super.toString()); |
| 176 | int len = sb.length(); |
| 177 | sb.replace(len - 1, len, ", "); |
| 178 | sb.append("vlanId=").append(vlanId) |
| 179 | .append(", mac=").append(macAddress) |
| 180 | .append("}"); |
| 181 | return sb.toString(); |
| 182 | } |
| 183 | } |