Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 AT&T Foundry |
| 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 | */ |
alshabib | 6d52745 | 2016-06-01 18:00:47 -0700 | [diff] [blame] | 16 | package org.opencord.aaa; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 17 | |
Ray Milkey | 508cec5 | 2016-02-16 14:23:26 -0800 | [diff] [blame] | 18 | import java.io.IOException; |
| 19 | import java.net.DatagramPacket; |
| 20 | import java.net.DatagramSocket; |
| 21 | import java.net.InetAddress; |
A.R Karthick | 6af9f43 | 2016-03-11 20:24:33 -0800 | [diff] [blame] | 22 | import java.net.InetSocketAddress; |
Ray Milkey | 508cec5 | 2016-02-16 14:23:26 -0800 | [diff] [blame] | 23 | import java.nio.ByteBuffer; |
| 24 | import java.util.concurrent.ExecutorService; |
| 25 | import java.util.concurrent.Executors; |
| 26 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 27 | import org.apache.felix.scr.annotations.Activate; |
| 28 | import org.apache.felix.scr.annotations.Component; |
| 29 | import org.apache.felix.scr.annotations.Deactivate; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 30 | import org.apache.felix.scr.annotations.Reference; |
| 31 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 32 | import org.onlab.packet.DeserializationException; |
| 33 | import org.onlab.packet.EAP; |
| 34 | import org.onlab.packet.EAPOL; |
| 35 | import org.onlab.packet.EthType; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 36 | import org.onlab.packet.Ethernet; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 37 | import org.onlab.packet.MacAddress; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 38 | import org.onlab.packet.RADIUS; |
| 39 | import org.onlab.packet.RADIUSAttribute; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 40 | import org.onosproject.core.ApplicationId; |
| 41 | import org.onosproject.core.CoreService; |
| 42 | import org.onosproject.net.ConnectPoint; |
| 43 | import org.onosproject.net.DeviceId; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 44 | import org.onosproject.net.PortNumber; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 45 | import org.onosproject.net.config.ConfigFactory; |
| 46 | import org.onosproject.net.config.NetworkConfigEvent; |
| 47 | import org.onosproject.net.config.NetworkConfigListener; |
| 48 | import org.onosproject.net.config.NetworkConfigRegistry; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 49 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 50 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flow.TrafficSelector; |
| 52 | import org.onosproject.net.flow.TrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 53 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 54 | import org.onosproject.net.packet.InboundPacket; |
| 55 | import org.onosproject.net.packet.OutboundPacket; |
| 56 | import org.onosproject.net.packet.PacketContext; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 57 | import org.onosproject.net.packet.PacketProcessor; |
| 58 | import org.onosproject.net.packet.PacketService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 59 | import org.slf4j.Logger; |
| 60 | |
Ray Milkey | 508cec5 | 2016-02-16 14:23:26 -0800 | [diff] [blame] | 61 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 62 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 63 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 64 | import static org.onosproject.net.packet.PacketPriority.CONTROL; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 65 | import static org.slf4j.LoggerFactory.getLogger; |
| 66 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 67 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 68 | * AAA application for ONOS. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 69 | */ |
| 70 | @Component(immediate = true) |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 71 | public class AaaManager { |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 72 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 73 | // for verbose output |
| 74 | private final Logger log = getLogger(getClass()); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 75 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 76 | // a list of our dependencies : |
| 77 | // to register with ONOS as an application - described next |
| 78 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 79 | protected CoreService coreService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 80 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 81 | // to receive Packet-in events that we'll respond to |
| 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 83 | protected PacketService packetService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 84 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 86 | protected NetworkConfigRegistry netCfgService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 87 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 88 | // Parsed RADIUS server addresses |
| 89 | protected InetAddress radiusIpAddress; |
| 90 | protected String radiusMacAddress; |
| 91 | |
| 92 | // NAS IP address |
| 93 | protected InetAddress nasIpAddress; |
| 94 | protected String nasMacAddress; |
| 95 | |
| 96 | // RADIUS server secret |
| 97 | protected String radiusSecret; |
| 98 | |
| 99 | // ID of RADIUS switch |
| 100 | protected String radiusSwitch; |
| 101 | |
| 102 | // RADIUS port number |
| 103 | protected long radiusPort; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 104 | |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 105 | // RADIUS server TCP port number |
| 106 | protected short radiusServerPort; |
| 107 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 108 | // our application-specific event handler |
| 109 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 110 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 111 | // our unique identifier |
| 112 | private ApplicationId appId; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 113 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 114 | // Socket used for UDP communications with RADIUS server |
| 115 | private DatagramSocket radiusSocket; |
| 116 | |
| 117 | // Executor for RADIUS communication thread |
| 118 | private ExecutorService executor; |
| 119 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 120 | // Configuration properties factory |
| 121 | private final ConfigFactory factory = |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 122 | new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY, |
| 123 | AaaConfig.class, |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 124 | "AAA") { |
| 125 | @Override |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 126 | public AaaConfig createConfig() { |
| 127 | return new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 128 | } |
| 129 | }; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 130 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 131 | // Listener for config changes |
| 132 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 133 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 134 | /** |
| 135 | * Builds an EAPOL packet based on the given parameters. |
| 136 | * |
| 137 | * @param dstMac destination MAC address |
| 138 | * @param srcMac source MAC address |
| 139 | * @param vlan vlan identifier |
| 140 | * @param eapolType EAPOL type |
| 141 | * @param eap EAP payload |
| 142 | * @return Ethernet frame |
| 143 | */ |
| 144 | private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac, |
| 145 | short vlan, byte eapolType, EAP eap) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 146 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 147 | Ethernet eth = new Ethernet(); |
| 148 | eth.setDestinationMACAddress(dstMac.toBytes()); |
| 149 | eth.setSourceMACAddress(srcMac.toBytes()); |
| 150 | eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 151 | if (vlan != Ethernet.VLAN_UNTAGGED) { |
| 152 | eth.setVlanID(vlan); |
| 153 | } |
| 154 | //eapol header |
| 155 | EAPOL eapol = new EAPOL(); |
| 156 | eapol.setEapolType(eapolType); |
| 157 | eapol.setPacketLength(eap.getLength()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 158 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 159 | //eap part |
| 160 | eapol.setPayload(eap); |
| 161 | |
| 162 | eth.setPayload(eapol); |
| 163 | eth.setPad(true); |
| 164 | return eth; |
| 165 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 166 | |
Ray Milkey | fe4fe56 | 2016-01-05 13:14:43 -0800 | [diff] [blame] | 167 | private void initializeLocalState() { |
| 168 | try { |
A.R Karthick | 6af9f43 | 2016-03-11 20:24:33 -0800 | [diff] [blame] | 169 | radiusSocket = new DatagramSocket(null); |
| 170 | radiusSocket.setReuseAddress(true); |
| 171 | radiusSocket.bind(new InetSocketAddress(radiusServerPort)); |
Ray Milkey | fe4fe56 | 2016-01-05 13:14:43 -0800 | [diff] [blame] | 172 | } catch (Exception ex) { |
| 173 | log.error("Can't open RADIUS socket", ex); |
| 174 | } |
| 175 | |
| 176 | executor = Executors.newSingleThreadExecutor( |
| 177 | new ThreadFactoryBuilder() |
| 178 | .setNameFormat("AAA-radius-%d").build()); |
| 179 | executor.execute(radiusListener); |
| 180 | } |
| 181 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 182 | @Activate |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 183 | public void activate() { |
| 184 | netCfgService.addListener(cfgListener); |
| 185 | netCfgService.registerConfigFactory(factory); |
| 186 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 187 | // "org.onosproject.aaa" is the FQDN of our app |
| 188 | appId = coreService.registerApplication("org.onosproject.aaa"); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 189 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 190 | cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class)); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 191 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 192 | // register our event handler |
Brian O'Connor | d9c7da0 | 2015-07-29 17:49:24 -0700 | [diff] [blame] | 193 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 194 | requestIntercepts(); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 195 | |
| 196 | StateMachine.initializeMaps(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 197 | |
Ray Milkey | fe4fe56 | 2016-01-05 13:14:43 -0800 | [diff] [blame] | 198 | initializeLocalState(); |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 199 | log.info("Started"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | @Deactivate |
| 203 | public void deactivate() { |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 204 | withdrawIntercepts(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 205 | // de-register and null our handler |
| 206 | packetService.removeProcessor(processor); |
| 207 | processor = null; |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 208 | StateMachine.destroyMaps(); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 209 | radiusSocket.close(); |
| 210 | executor.shutdownNow(); |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 211 | log.info("Stopped"); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 214 | protected void sendRadiusPacket(RADIUS radiusPacket) { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 215 | |
| 216 | try { |
| 217 | final byte[] data = radiusPacket.serialize(); |
| 218 | final DatagramSocket socket = radiusSocket; |
| 219 | |
| 220 | DatagramPacket packet = |
| 221 | new DatagramPacket(data, data.length, |
| 222 | radiusIpAddress, radiusServerPort); |
| 223 | |
| 224 | socket.send(packet); |
| 225 | } catch (IOException e) { |
| 226 | log.info("Cannot send packet to RADIUS server", e); |
| 227 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 230 | /** |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 231 | * Request packet in via PacketService. |
| 232 | */ |
| 233 | private void requestIntercepts() { |
| 234 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 235 | selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 236 | packetService.requestPackets(selector.build(), |
| 237 | CONTROL, appId); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Cancel request for packet in via PacketService. |
| 242 | */ |
| 243 | private void withdrawIntercepts() { |
| 244 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 245 | selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 246 | packetService.cancelPackets(selector.build(), CONTROL, appId); |
| 247 | } |
| 248 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 249 | /** |
| 250 | * Send the ethernet packet to the supplicant. |
| 251 | * |
| 252 | * @param ethernetPkt the ethernet packet |
| 253 | * @param connectPoint the connect point to send out |
| 254 | */ |
| 255 | private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint) { |
| 256 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); |
| 257 | OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), |
| 258 | treatment, ByteBuffer.wrap(ethernetPkt.serialize())); |
| 259 | packetService.emit(packet); |
| 260 | } |
| 261 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 262 | // our handler defined as a private inner class |
| 263 | |
| 264 | /** |
| 265 | * Packet processor responsible for forwarding packets along their paths. |
| 266 | */ |
| 267 | private class ReactivePacketProcessor implements PacketProcessor { |
| 268 | @Override |
| 269 | public void process(PacketContext context) { |
| 270 | |
| 271 | // Extract the original Ethernet frame from the packet information |
| 272 | InboundPacket pkt = context.inPacket(); |
| 273 | Ethernet ethPkt = pkt.parsed(); |
| 274 | if (ethPkt == null) { |
| 275 | return; |
| 276 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 277 | try { |
| 278 | // identify if incoming packet comes from supplicant (EAP) or RADIUS |
| 279 | switch (EthType.EtherType.lookup(ethPkt.getEtherType())) { |
| 280 | case EAPOL: |
| 281 | handleSupplicantPacket(context.inPacket()); |
| 282 | break; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 283 | default: |
| 284 | log.trace("Skipping Ethernet packet type {}", |
| 285 | EthType.EtherType.lookup(ethPkt.getEtherType())); |
| 286 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 287 | } catch (StateMachineException e) { |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 288 | log.warn("Unable to process RADIUS packet:", e); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 292 | /** |
| 293 | * Creates and initializes common fields of a RADIUS packet. |
| 294 | * |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 295 | * @param stateMachine state machine for the request |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 296 | * @param eapPacket EAP packet |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 297 | * @return RADIUS packet |
| 298 | */ |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 299 | private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) { |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 300 | RADIUS radiusPayload = |
| 301 | new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
| 302 | eapPacket.getIdentifier()); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 303 | |
| 304 | // set Request Authenticator in StateMachine |
| 305 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
| 306 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 307 | radiusPayload.setIdentifier(identifier); |
| 308 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 309 | stateMachine.username()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 310 | |
| 311 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 312 | AaaManager.this.nasIpAddress.getAddress()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 313 | |
| 314 | radiusPayload.encapsulateMessage(eapPacket); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 315 | |
| 316 | return radiusPayload; |
| 317 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 318 | |
| 319 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 320 | * Handles PAE packets (supplicant). |
| 321 | * |
| 322 | * @param inPacket Ethernet packet coming from the supplicant |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 323 | */ |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 324 | private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException { |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 325 | Ethernet ethPkt = inPacket.parsed(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 326 | // Where does it come from? |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 327 | MacAddress srcMac = ethPkt.getSourceMAC(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 328 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 329 | DeviceId deviceId = inPacket.receivedFrom().deviceId(); |
| 330 | PortNumber portNumber = inPacket.receivedFrom().port(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 331 | String sessionId = deviceId.toString() + portNumber.toString(); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 332 | StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId); |
| 333 | if (stateMachine == null) { |
Ray Milkey | 508cec5 | 2016-02-16 14:23:26 -0800 | [diff] [blame] | 334 | stateMachine = new StateMachine(sessionId); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 337 | |
| 338 | EAPOL eapol = (EAPOL) ethPkt.getPayload(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 339 | |
| 340 | switch (eapol.getEapolType()) { |
| 341 | case EAPOL.EAPOL_START: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 342 | stateMachine.start(); |
| 343 | stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 344 | |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 345 | //send an EAP Request/Identify to the supplicant |
| 346 | EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 347 | Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress), |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 348 | ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, |
| 349 | eapPayload); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 350 | stateMachine.setSupplicantAddress(srcMac); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 351 | stateMachine.setVlanId(ethPkt.getVlanID()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 352 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 353 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 354 | |
| 355 | break; |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 356 | case EAPOL.EAPOL_LOGOFF: |
Ray Milkey | b34b496 | 2016-01-04 10:24:43 -0800 | [diff] [blame] | 357 | if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) { |
| 358 | stateMachine.logoff(); |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 362 | case EAPOL.EAPOL_PACKET: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 363 | RADIUS radiusPayload; |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 364 | // check if this is a Response/Identify or a Response/TLS |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 365 | EAP eapPacket = (EAP) eapol.getPayload(); |
| 366 | |
| 367 | byte dataType = eapPacket.getDataType(); |
| 368 | switch (dataType) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 369 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 370 | case EAP.ATTR_IDENTITY: |
| 371 | // request id access to RADIUS |
| 372 | stateMachine.setUsername(eapPacket.getData()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 373 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 374 | radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 375 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 376 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 377 | sendRadiusPacket(radiusPayload); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 378 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 379 | // change the state to "PENDING" |
| 380 | stateMachine.requestAccess(); |
| 381 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 382 | case EAP.ATTR_MD5: |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 383 | // verify if the EAP identifier corresponds to the |
| 384 | // challenge identifier from the client state |
| 385 | // machine. |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 386 | if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 387 | //send the RADIUS challenge response |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 388 | radiusPayload = |
| 389 | getRadiusPayload(stateMachine, |
| 390 | stateMachine.identifier(), |
| 391 | eapPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 392 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 393 | if (stateMachine.challengeState() != null) { |
| 394 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 395 | stateMachine.challengeState()); |
| 396 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 397 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
| 398 | sendRadiusPacket(radiusPayload); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 399 | } |
| 400 | break; |
| 401 | case EAP.ATTR_TLS: |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 402 | // request id access to RADIUS |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 403 | radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 404 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 405 | if (stateMachine.challengeState() != null) { |
| 406 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 407 | stateMachine.challengeState()); |
| 408 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 409 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 410 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 411 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
| 412 | sendRadiusPacket(radiusPayload); |
Ray Milkey | 5493b51 | 2015-10-21 12:13:49 -0700 | [diff] [blame] | 413 | |
Ray Milkey | f3790b8 | 2015-10-21 16:28:08 -0700 | [diff] [blame] | 414 | if (stateMachine.state() != StateMachine.STATE_PENDING) { |
| 415 | stateMachine.requestAccess(); |
| 416 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 417 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 418 | break; |
| 419 | default: |
| 420 | return; |
| 421 | } |
| 422 | break; |
| 423 | default: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 424 | log.trace("Skipping EAPOL message {}", eapol.getEapolType()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 425 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 426 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 427 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | class RadiusListener implements Runnable { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 431 | |
| 432 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 433 | * Handles RADIUS packets. |
| 434 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 435 | * @param radiusPacket RADIUS packet coming from the RADIUS server. |
Ray Milkey | 17d6c49 | 2015-10-27 10:39:42 -0700 | [diff] [blame] | 436 | * @throws StateMachineException if an illegal state transition is triggered |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 437 | */ |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 438 | protected void handleRadiusPacket(RADIUS radiusPacket) throws StateMachineException { |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 439 | StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 440 | if (stateMachine == null) { |
| 441 | log.error("Invalid session identifier, exiting..."); |
| 442 | return; |
| 443 | } |
| 444 | |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 445 | EAP eapPayload; |
| 446 | Ethernet eth; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 447 | switch (radiusPacket.getCode()) { |
| 448 | case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 449 | RADIUSAttribute radiusAttrState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE); |
| 450 | byte[] challengeState = null; |
| 451 | if (radiusAttrState != null) { |
| 452 | challengeState = radiusAttrState.getValue(); |
| 453 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 454 | eapPayload = radiusPacket.decapsulateMessage(); |
| 455 | stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 456 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 457 | MacAddress.valueOf(nasMacAddress), |
| 458 | stateMachine.vlanId(), |
| 459 | EAPOL.EAPOL_PACKET, |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 460 | eapPayload); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 461 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 462 | break; |
| 463 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 464 | //send an EAPOL - Success to the supplicant. |
ke han | 04e47f3 | 2016-10-28 14:15:43 +0800 | [diff] [blame] | 465 | byte[] eapMessageSuccess = |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 466 | radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); |
| 467 | eapPayload = new EAP(); |
ke han | 04e47f3 | 2016-10-28 14:15:43 +0800 | [diff] [blame] | 468 | eapPayload = (EAP) eapPayload.deserialize(eapMessageSuccess, 0, eapMessageSuccess.length); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 469 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 470 | MacAddress.valueOf(nasMacAddress), |
| 471 | stateMachine.vlanId(), |
| 472 | EAPOL.EAPOL_PACKET, |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 473 | eapPayload); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 474 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 475 | |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 476 | stateMachine.authorizeAccess(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 477 | break; |
| 478 | case RADIUS.RADIUS_CODE_ACCESS_REJECT: |
ke han | 04e47f3 | 2016-10-28 14:15:43 +0800 | [diff] [blame] | 479 | //send an EAPOL - Failure to the supplicant. |
ke han | 5dcfa52 | 2016-11-29 14:21:30 +0800 | [diff] [blame] | 480 | byte[] eapMessageFailure; |
ke han | 04e47f3 | 2016-10-28 14:15:43 +0800 | [diff] [blame] | 481 | eapPayload = new EAP(); |
ke han | 5dcfa52 | 2016-11-29 14:21:30 +0800 | [diff] [blame] | 482 | RADIUSAttribute radiusAttrEap = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE); |
| 483 | if (radiusAttrEap == null) { |
| 484 | eapPayload.setCode(EAP.FAILURE); |
| 485 | eapPayload.setIdentifier(stateMachine.challengeIdentifier()); |
| 486 | eapPayload.setLength(EAP.EAP_HDR_LEN_SUC_FAIL); |
| 487 | } else { |
| 488 | eapMessageFailure = radiusAttrEap.getValue(); |
| 489 | eapPayload = (EAP) eapPayload.deserialize(eapMessageFailure, 0, eapMessageFailure.length); |
| 490 | } |
ke han | 04e47f3 | 2016-10-28 14:15:43 +0800 | [diff] [blame] | 491 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 492 | MacAddress.valueOf(nasMacAddress), |
| 493 | stateMachine.vlanId(), |
| 494 | EAPOL.EAPOL_PACKET, |
| 495 | eapPayload); |
| 496 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
ke han | 5dcfa52 | 2016-11-29 14:21:30 +0800 | [diff] [blame] | 497 | stateMachine.denyAccess(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 498 | break; |
| 499 | default: |
| 500 | log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); |
| 501 | } |
| 502 | } |
| 503 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 504 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 505 | @Override |
| 506 | public void run() { |
| 507 | boolean done = false; |
| 508 | int packetNumber = 1; |
| 509 | |
| 510 | log.info("UDP listener thread starting up"); |
| 511 | RADIUS inboundRadiusPacket; |
| 512 | while (!done) { |
| 513 | try { |
Ray Milkey | 5493b51 | 2015-10-21 12:13:49 -0700 | [diff] [blame] | 514 | byte[] packetBuffer = new byte[RADIUS.RADIUS_MAX_LENGTH]; |
| 515 | DatagramPacket inboundBasePacket = |
| 516 | new DatagramPacket(packetBuffer, packetBuffer.length); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 517 | DatagramSocket socket = radiusSocket; |
| 518 | socket.receive(inboundBasePacket); |
| 519 | log.info("Packet #{} received", packetNumber++); |
| 520 | try { |
| 521 | inboundRadiusPacket = |
| 522 | RADIUS.deserializer() |
| 523 | .deserialize(inboundBasePacket.getData(), |
| 524 | 0, |
| 525 | inboundBasePacket.getLength()); |
| 526 | handleRadiusPacket(inboundRadiusPacket); |
| 527 | } catch (DeserializationException dex) { |
| 528 | log.error("Cannot deserialize packet", dex); |
| 529 | } catch (StateMachineException sme) { |
| 530 | log.error("Illegal state machine operation", sme); |
| 531 | } |
| 532 | |
| 533 | } catch (IOException e) { |
| 534 | log.info("Socket was closed, exiting listener thread"); |
| 535 | done = true; |
| 536 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 537 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 538 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 541 | RadiusListener radiusListener = new RadiusListener(); |
| 542 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 543 | private class InternalConfigListener implements NetworkConfigListener { |
| 544 | |
| 545 | /** |
Ray Milkey | c9e8dcc | 2015-12-30 10:31:32 -0800 | [diff] [blame] | 546 | * Reconfigures the AAA application according to the |
| 547 | * configuration parameters passed. |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 548 | * |
| 549 | * @param cfg configuration object |
| 550 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 551 | private void reconfigureNetwork(AaaConfig cfg) { |
| 552 | AaaConfig newCfg; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 553 | if (cfg == null) { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 554 | newCfg = new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 555 | } else { |
| 556 | newCfg = cfg; |
| 557 | } |
| 558 | if (newCfg.nasIp() != null) { |
| 559 | nasIpAddress = newCfg.nasIp(); |
| 560 | } |
| 561 | if (newCfg.radiusIp() != null) { |
| 562 | radiusIpAddress = newCfg.radiusIp(); |
| 563 | } |
| 564 | if (newCfg.radiusMac() != null) { |
| 565 | radiusMacAddress = newCfg.radiusMac(); |
| 566 | } |
| 567 | if (newCfg.nasMac() != null) { |
| 568 | nasMacAddress = newCfg.nasMac(); |
| 569 | } |
| 570 | if (newCfg.radiusSecret() != null) { |
| 571 | radiusSecret = newCfg.radiusSecret(); |
| 572 | } |
| 573 | if (newCfg.radiusSwitch() != null) { |
| 574 | radiusSwitch = newCfg.radiusSwitch(); |
| 575 | } |
| 576 | if (newCfg.radiusPort() != -1) { |
| 577 | radiusPort = newCfg.radiusPort(); |
| 578 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 579 | if (newCfg.radiusServerUdpPort() != -1) { |
| 580 | radiusServerPort = newCfg.radiusServerUdpPort(); |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 581 | } |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | @Override |
| 585 | public void event(NetworkConfigEvent event) { |
| 586 | |
| 587 | if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || |
| 588 | event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 589 | event.configClass().equals(AaaConfig.class)) { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 590 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 591 | AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 592 | reconfigureNetwork(cfg); |
Ray Milkey | fe4fe56 | 2016-01-05 13:14:43 -0800 | [diff] [blame] | 593 | radiusSocket.close(); |
| 594 | executor.shutdownNow(); |
| 595 | initializeLocalState(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 596 | log.info("Reconfigured"); |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 602 | } |