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