Committed by
Gerrit Code Review
More AAA app refactoring
- cleaned up exception handling a little - reformatting of the code to be easier to read and group similar code together - fixed some style problems found by IntelliJ Change-Id: I932ac48d82b598b1f59c906477fb5e4deded413f
Showing
1 changed file
with
123 additions
and
113 deletions
... | @@ -79,62 +79,85 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -79,62 +79,85 @@ import static org.slf4j.LoggerFactory.getLogger; |
79 | public class AAA { | 79 | public class AAA { |
80 | // RADIUS server IP address | 80 | // RADIUS server IP address |
81 | private static final String DEFAULT_RADIUS_IP = "192.168.1.10"; | 81 | private static final String DEFAULT_RADIUS_IP = "192.168.1.10"; |
82 | + | ||
82 | // NAS IP address | 83 | // NAS IP address |
83 | private static final String DEFAULT_NAS_IP = "192.168.1.11"; | 84 | private static final String DEFAULT_NAS_IP = "192.168.1.11"; |
85 | + | ||
84 | // RADIUS uplink port | 86 | // RADIUS uplink port |
85 | private static final int DEFAULT_RADIUS_UPLINK = 2; | 87 | private static final int DEFAULT_RADIUS_UPLINK = 2; |
88 | + | ||
86 | // RADIUS server shared secret | 89 | // RADIUS server shared secret |
87 | private static final String DEFAULT_RADIUS_SECRET = "ONOSecret"; | 90 | private static final String DEFAULT_RADIUS_SECRET = "ONOSecret"; |
91 | + | ||
88 | // RADIUS MAC address | 92 | // RADIUS MAC address |
89 | private static final String RADIUS_MAC_ADDRESS = "00:00:00:00:01:10"; | 93 | private static final String RADIUS_MAC_ADDRESS = "00:00:00:00:01:10"; |
94 | + | ||
90 | // NAS MAC address | 95 | // NAS MAC address |
91 | private static final String NAS_MAC_ADDRESS = "00:00:00:00:10:01"; | 96 | private static final String NAS_MAC_ADDRESS = "00:00:00:00:10:01"; |
97 | + | ||
92 | // Radius Switch Id | 98 | // Radius Switch Id |
93 | private static final String DEFAULT_RADIUS_SWITCH = "of:90e2ba82f97791e9"; | 99 | private static final String DEFAULT_RADIUS_SWITCH = "of:90e2ba82f97791e9"; |
100 | + | ||
94 | // Radius Port Number | 101 | // Radius Port Number |
95 | private static final String DEFAULT_RADIUS_PORT = "129"; | 102 | private static final String DEFAULT_RADIUS_PORT = "129"; |
103 | + | ||
96 | // for verbose output | 104 | // for verbose output |
97 | private final Logger log = getLogger(getClass()); | 105 | private final Logger log = getLogger(getClass()); |
106 | + | ||
98 | // a list of our dependencies : | 107 | // a list of our dependencies : |
99 | // to register with ONOS as an application - described next | 108 | // to register with ONOS as an application - described next |
100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
101 | protected CoreService coreService; | 110 | protected CoreService coreService; |
111 | + | ||
102 | // to receive Packet-in events that we'll respond to | 112 | // to receive Packet-in events that we'll respond to |
103 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
104 | protected PacketService packetService; | 114 | protected PacketService packetService; |
115 | + | ||
105 | // end host information | 116 | // end host information |
106 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 117 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
107 | protected HostService hostService; | 118 | protected HostService hostService; |
119 | + | ||
108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
109 | protected VoltTenantService voltTenantService; | 121 | protected VoltTenantService voltTenantService; |
122 | + | ||
123 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
124 | + protected ComponentConfigService cfgService; | ||
125 | + | ||
110 | // Parsed RADIUS server IP address | 126 | // Parsed RADIUS server IP address |
111 | protected InetAddress parsedRadiusIpAddress; | 127 | protected InetAddress parsedRadiusIpAddress; |
112 | // Parsed NAS IP address | 128 | // Parsed NAS IP address |
113 | protected InetAddress parsedNasIpAddress; | 129 | protected InetAddress parsedNasIpAddress; |
114 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 130 | + |
115 | - protected ComponentConfigService cfgService; | ||
116 | // our application-specific event handler | 131 | // our application-specific event handler |
117 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); | 132 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
133 | + | ||
118 | // our unique identifier | 134 | // our unique identifier |
119 | private ApplicationId appId; | 135 | private ApplicationId appId; |
136 | + | ||
120 | @Property(name = "radiusIpAddress", value = DEFAULT_RADIUS_IP, | 137 | @Property(name = "radiusIpAddress", value = DEFAULT_RADIUS_IP, |
121 | label = "RADIUS IP Address") | 138 | label = "RADIUS IP Address") |
122 | private String radiusIpAddress = DEFAULT_RADIUS_IP; | 139 | private String radiusIpAddress = DEFAULT_RADIUS_IP; |
140 | + | ||
123 | @Property(name = "nasIpAddress", value = DEFAULT_NAS_IP, | 141 | @Property(name = "nasIpAddress", value = DEFAULT_NAS_IP, |
124 | label = "NAS IP Address") | 142 | label = "NAS IP Address") |
125 | private String nasIpAddress = DEFAULT_NAS_IP; | 143 | private String nasIpAddress = DEFAULT_NAS_IP; |
144 | + | ||
126 | @Property(name = "radiusMacAddress", value = RADIUS_MAC_ADDRESS, | 145 | @Property(name = "radiusMacAddress", value = RADIUS_MAC_ADDRESS, |
127 | label = "RADIUS MAC Address") | 146 | label = "RADIUS MAC Address") |
128 | private String radiusMacAddress = RADIUS_MAC_ADDRESS; | 147 | private String radiusMacAddress = RADIUS_MAC_ADDRESS; |
148 | + | ||
129 | @Property(name = "nasMacAddress", value = NAS_MAC_ADDRESS, | 149 | @Property(name = "nasMacAddress", value = NAS_MAC_ADDRESS, |
130 | label = "NAS MAC Address") | 150 | label = "NAS MAC Address") |
131 | private String nasMacAddress = NAS_MAC_ADDRESS; | 151 | private String nasMacAddress = NAS_MAC_ADDRESS; |
152 | + | ||
132 | @Property(name = "radiusSecret", value = DEFAULT_RADIUS_SECRET, | 153 | @Property(name = "radiusSecret", value = DEFAULT_RADIUS_SECRET, |
133 | label = "RADIUS shared secret") | 154 | label = "RADIUS shared secret") |
134 | private String radiusSecret = DEFAULT_RADIUS_SECRET; | 155 | private String radiusSecret = DEFAULT_RADIUS_SECRET; |
156 | + | ||
135 | @Property(name = "radiusSwitchId", value = DEFAULT_RADIUS_SWITCH, | 157 | @Property(name = "radiusSwitchId", value = DEFAULT_RADIUS_SWITCH, |
136 | label = "Radius switch") | 158 | label = "Radius switch") |
137 | private String radiusSwitch = DEFAULT_RADIUS_SWITCH; | 159 | private String radiusSwitch = DEFAULT_RADIUS_SWITCH; |
160 | + | ||
138 | @Property(name = "radiusPortNumber", value = DEFAULT_RADIUS_PORT, | 161 | @Property(name = "radiusPortNumber", value = DEFAULT_RADIUS_PORT, |
139 | label = "Radius port") | 162 | label = "Radius port") |
140 | private String radiusPort = DEFAULT_RADIUS_PORT; | 163 | private String radiusPort = DEFAULT_RADIUS_PORT; |
... | @@ -181,14 +204,14 @@ public class AAA { | ... | @@ -181,14 +204,14 @@ public class AAA { |
181 | parsedRadiusIpAddress = InetAddress.getByName(s); | 204 | parsedRadiusIpAddress = InetAddress.getByName(s); |
182 | radiusIpAddress = Strings.isNullOrEmpty(s) ? DEFAULT_RADIUS_IP : s; | 205 | radiusIpAddress = Strings.isNullOrEmpty(s) ? DEFAULT_RADIUS_IP : s; |
183 | } catch (UnknownHostException e) { | 206 | } catch (UnknownHostException e) { |
184 | - log.error("Invalid RADIUS IP address specification: {}", s); | 207 | + log.error("Invalid RADIUS IP address specification: {}", s, e); |
185 | } | 208 | } |
186 | try { | 209 | try { |
187 | s = Tools.get(properties, "nasIpAddress"); | 210 | s = Tools.get(properties, "nasIpAddress"); |
188 | parsedNasIpAddress = InetAddress.getByName(s); | 211 | parsedNasIpAddress = InetAddress.getByName(s); |
189 | nasIpAddress = Strings.isNullOrEmpty(s) ? DEFAULT_NAS_IP : s; | 212 | nasIpAddress = Strings.isNullOrEmpty(s) ? DEFAULT_NAS_IP : s; |
190 | } catch (UnknownHostException e) { | 213 | } catch (UnknownHostException e) { |
191 | - log.error("Invalid NAS IP address specification: {}", s); | 214 | + log.error("Invalid NAS IP address specification: {}", s, e); |
192 | } | 215 | } |
193 | 216 | ||
194 | s = Tools.get(properties, "radiusMacAddress"); | 217 | s = Tools.get(properties, "radiusMacAddress"); |
... | @@ -284,32 +307,33 @@ public class AAA { | ... | @@ -284,32 +307,33 @@ public class AAA { |
284 | if (ethPkt == null) { | 307 | if (ethPkt == null) { |
285 | return; | 308 | return; |
286 | } | 309 | } |
287 | - // identify if incoming packet comes from supplicant (EAP) or RADIUS | 310 | + try { |
288 | - switch (EthType.EtherType.lookup(ethPkt.getEtherType())) { | 311 | + // identify if incoming packet comes from supplicant (EAP) or RADIUS |
289 | - case EAPOL: | 312 | + switch (EthType.EtherType.lookup(ethPkt.getEtherType())) { |
290 | - handleSupplicantPacket(context.inPacket()); | 313 | + case EAPOL: |
291 | - break; | 314 | + handleSupplicantPacket(context.inPacket()); |
292 | - case IPV4: | 315 | + break; |
293 | - IPv4 ipv4Packet = (IPv4) ethPkt.getPayload(); | 316 | + case IPV4: |
294 | - Ip4Address srcIp = Ip4Address.valueOf(ipv4Packet.getSourceAddress()); | 317 | + IPv4 ipv4Packet = (IPv4) ethPkt.getPayload(); |
295 | - Ip4Address radiusIp4Address = Ip4Address.valueOf(parsedRadiusIpAddress); | 318 | + Ip4Address srcIp = Ip4Address.valueOf(ipv4Packet.getSourceAddress()); |
296 | - if (srcIp.equals(radiusIp4Address) && ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) { | 319 | + Ip4Address radiusIp4Address = Ip4Address.valueOf(parsedRadiusIpAddress); |
297 | - // TODO: check for port as well when it's configurable | 320 | + if (srcIp.equals(radiusIp4Address) && ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) { |
298 | - UDP udpPacket = (UDP) ipv4Packet.getPayload(); | 321 | + // TODO: check for port as well when it's configurable |
299 | - | 322 | + UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
300 | - byte[] datagram = udpPacket.getPayload().serialize(); | 323 | + |
301 | - RADIUS radiusPacket; | 324 | + byte[] datagram = udpPacket.getPayload().serialize(); |
302 | - try { | 325 | + RADIUS radiusPacket; |
303 | radiusPacket = RADIUS.deserializer().deserialize(datagram, 0, datagram.length); | 326 | radiusPacket = RADIUS.deserializer().deserialize(datagram, 0, datagram.length); |
304 | - } catch (DeserializationException e) { | 327 | + handleRadiusPacket(radiusPacket); |
305 | - log.warn("Unable to deserialize RADIUS packet:", e); | ||
306 | - return; | ||
307 | } | 328 | } |
308 | - handleRadiusPacket(radiusPacket); | 329 | + |
309 | - } | 330 | + break; |
310 | - break; | 331 | + default: |
311 | - default: | 332 | + log.trace("Skipping Ethernet packet type {}", |
312 | - return; | 333 | + EthType.EtherType.lookup(ethPkt.getEtherType())); |
334 | + } | ||
335 | + } catch (DeserializationException | StateMachineException e) { | ||
336 | + log.warn("Unable to process RADIUS packet:", e); | ||
313 | } | 337 | } |
314 | } | 338 | } |
315 | 339 | ||
... | @@ -319,7 +343,7 @@ public class AAA { | ... | @@ -319,7 +343,7 @@ public class AAA { |
319 | * | 343 | * |
320 | * @param inPacket Ethernet packet coming from the supplicant | 344 | * @param inPacket Ethernet packet coming from the supplicant |
321 | */ | 345 | */ |
322 | - private void handleSupplicantPacket(InboundPacket inPacket) { | 346 | + private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException { |
323 | Ethernet ethPkt = inPacket.parsed(); | 347 | Ethernet ethPkt = inPacket.parsed(); |
324 | // Where does it come from? | 348 | // Where does it come from? |
325 | MacAddress srcMAC = ethPkt.getSourceMAC(); | 349 | MacAddress srcMAC = ethPkt.getSourceMAC(); |
... | @@ -337,62 +361,59 @@ public class AAA { | ... | @@ -337,62 +361,59 @@ public class AAA { |
337 | 361 | ||
338 | switch (eapol.getEapolType()) { | 362 | switch (eapol.getEapolType()) { |
339 | case EAPOL.EAPOL_START: | 363 | case EAPOL.EAPOL_START: |
340 | - try { | 364 | + stateMachine.start(); |
341 | - stateMachine.start(); | 365 | + stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); |
342 | - stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); | 366 | + |
343 | - | 367 | + //send an EAP Request/Identify to the supplicant |
344 | - //send an EAP Request/Identify to the supplicant | 368 | + EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); |
345 | - EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); | 369 | + Ethernet eth = buildEapolResponse(srcMAC, MacAddress.valueOf(1L), |
346 | - Ethernet eth = buildEapolResponse(srcMAC, MacAddress.valueOf(1L), | 370 | + ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, |
347 | - ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, | 371 | + eapPayload); |
348 | - eapPayload); | 372 | + stateMachine.setSupplicantAddress(srcMAC); |
349 | - stateMachine.setSupplicantAddress(srcMAC); | 373 | + stateMachine.setVlanId(ethPkt.getVlanID()); |
350 | - stateMachine.setVlanId(ethPkt.getVlanID()); | 374 | + |
351 | - | 375 | + this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
352 | - this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); | ||
353 | - } catch (StateMachineException e) { | ||
354 | - e.printStackTrace(); | ||
355 | - } | ||
356 | 376 | ||
357 | break; | 377 | break; |
358 | case EAPOL.EAPOL_PACKET: | 378 | case EAPOL.EAPOL_PACKET: |
379 | + RADIUS radiusPayload; | ||
359 | //check if this is a Response/Identify or a Response/TLS | 380 | //check if this is a Response/Identify or a Response/TLS |
360 | EAP eapPacket = (EAP) eapol.getPayload(); | 381 | EAP eapPacket = (EAP) eapol.getPayload(); |
361 | 382 | ||
362 | byte dataType = eapPacket.getDataType(); | 383 | byte dataType = eapPacket.getDataType(); |
363 | switch (dataType) { | 384 | switch (dataType) { |
364 | - case EAP.ATTR_IDENTITY: | ||
365 | - try { | ||
366 | - //request id access to RADIUS | ||
367 | - RADIUS radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, | ||
368 | - eapPacket.getIdentifier()); | ||
369 | - radiusPayload.setIdentifier(stateMachine.identifier()); | ||
370 | - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, | ||
371 | - eapPacket.getData()); | ||
372 | - stateMachine.setUsername(eapPacket.getData()); | ||
373 | - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, | ||
374 | - AAA.this.parsedNasIpAddress.getAddress()); | ||
375 | 385 | ||
376 | - radiusPayload.encapsulateMessage(eapPacket); | 386 | + case EAP.ATTR_IDENTITY: |
387 | + //request id access to RADIUS | ||
388 | + stateMachine.setUsername(eapPacket.getData()); | ||
377 | 389 | ||
378 | - // set Request Authenticator in StateMachine | 390 | + radiusPayload = |
379 | - stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); | 391 | + new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
380 | - radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret); | 392 | + eapPacket.getIdentifier()); |
381 | - sendRadiusMessage(radiusPayload); | 393 | + radiusPayload.setIdentifier(stateMachine.identifier()); |
394 | + radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, | ||
395 | + eapPacket.getData()); | ||
382 | 396 | ||
383 | - //change the state to "PENDING" | 397 | + radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, |
384 | - stateMachine.requestAccess(); | 398 | + AAA.this.parsedNasIpAddress.getAddress()); |
385 | - } catch (StateMachineException e) { | 399 | + |
386 | - e.printStackTrace(); | 400 | + radiusPayload.encapsulateMessage(eapPacket); |
387 | - } | 401 | + |
388 | - break; | 402 | + // set Request Authenticator in StateMachine |
403 | + stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); | ||
404 | + radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret); | ||
405 | + sendRadiusMessage(radiusPayload); | ||
406 | + | ||
407 | + //change the state to "PENDING" | ||
408 | + stateMachine.requestAccess(); | ||
409 | + break; | ||
389 | case EAP.ATTR_MD5: | 410 | case EAP.ATTR_MD5: |
390 | //verify if the EAP identifier corresponds to the challenge identifier from the client state | 411 | //verify if the EAP identifier corresponds to the challenge identifier from the client state |
391 | //machine. | 412 | //machine. |
392 | if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { | 413 | if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { |
393 | //send the RADIUS challenge response | 414 | //send the RADIUS challenge response |
394 | - RADIUS radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, | 415 | + radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
395 | - eapPacket.getIdentifier()); | 416 | + eapPacket.getIdentifier()); |
396 | radiusPayload.setIdentifier(stateMachine.challengeIdentifier()); | 417 | radiusPayload.setIdentifier(stateMachine.challengeIdentifier()); |
397 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, | 418 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, |
398 | stateMachine.username()); | 419 | stateMachine.username()); |
... | @@ -408,37 +429,34 @@ public class AAA { | ... | @@ -408,37 +429,34 @@ public class AAA { |
408 | } | 429 | } |
409 | break; | 430 | break; |
410 | case EAP.ATTR_TLS: | 431 | case EAP.ATTR_TLS: |
411 | - try { | 432 | + //request id access to RADIUS |
412 | - //request id access to RADIUS | 433 | + radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
413 | - RADIUS radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, | 434 | + eapPacket.getIdentifier()); |
414 | - eapPacket.getIdentifier()); | 435 | + radiusPayload.setIdentifier(stateMachine.identifier()); |
415 | - radiusPayload.setIdentifier(stateMachine.identifier()); | 436 | + radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, |
416 | - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, | 437 | + stateMachine.username()); |
417 | - stateMachine.username()); | 438 | + radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, |
418 | - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, | 439 | + AAA.this.parsedNasIpAddress.getAddress()); |
419 | - AAA.this.parsedNasIpAddress.getAddress()); | ||
420 | 440 | ||
421 | - radiusPayload.encapsulateMessage(eapPacket); | 441 | + radiusPayload.encapsulateMessage(eapPacket); |
422 | 442 | ||
423 | - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, | 443 | + radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
424 | - stateMachine.challengeState()); | 444 | + stateMachine.challengeState()); |
425 | - stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); | 445 | + stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
426 | 446 | ||
427 | - radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret); | 447 | + radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret); |
448 | + | ||
449 | + sendRadiusMessage(radiusPayload); | ||
450 | + // TODO: this gets called on every fragment, should only be called at TLS-Start | ||
451 | + stateMachine.requestAccess(); | ||
428 | 452 | ||
429 | - sendRadiusMessage(radiusPayload); | ||
430 | - // TODO: this gets called on every fragment, should only be called at TLS-Start | ||
431 | - stateMachine.requestAccess(); | ||
432 | - } catch (StateMachineException e) { | ||
433 | - e.printStackTrace(); | ||
434 | - } | ||
435 | break; | 453 | break; |
436 | default: | 454 | default: |
437 | return; | 455 | return; |
438 | } | 456 | } |
439 | break; | 457 | break; |
440 | default: | 458 | default: |
441 | - return; | 459 | + log.trace("Skipping EAPOL message {}", eapol.getEapolType()); |
442 | } | 460 | } |
443 | } | 461 | } |
444 | 462 | ||
... | @@ -447,15 +465,15 @@ public class AAA { | ... | @@ -447,15 +465,15 @@ public class AAA { |
447 | * | 465 | * |
448 | * @param radiusPacket RADIUS packet coming from the RADIUS server. | 466 | * @param radiusPacket RADIUS packet coming from the RADIUS server. |
449 | */ | 467 | */ |
450 | - private void handleRadiusPacket(RADIUS radiusPacket) { | 468 | + private void handleRadiusPacket(RADIUS radiusPacket) throws StateMachineException { |
451 | StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier()); | 469 | StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier()); |
452 | if (stateMachine == null) { | 470 | if (stateMachine == null) { |
453 | log.error("Invalid session identifier, exiting..."); | 471 | log.error("Invalid session identifier, exiting..."); |
454 | return; | 472 | return; |
455 | } | 473 | } |
456 | 474 | ||
457 | - EAP eapPayload = new EAP(); | 475 | + EAP eapPayload; |
458 | - Ethernet eth = null; | 476 | + Ethernet eth; |
459 | switch (radiusPacket.getCode()) { | 477 | switch (radiusPacket.getCode()) { |
460 | case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: | 478 | case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: |
461 | byte[] challengeState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE).getValue(); | 479 | byte[] challengeState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE).getValue(); |
... | @@ -467,28 +485,20 @@ public class AAA { | ... | @@ -467,28 +485,20 @@ public class AAA { |
467 | this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); | 485 | this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
468 | break; | 486 | break; |
469 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: | 487 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: |
470 | - try { | 488 | + //send an EAPOL - Success to the supplicant. |
471 | - //send an EAPOL - Success to the supplicant. | 489 | + byte[] eapMessage = |
472 | - byte[] eapMessage = | 490 | + radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); |
473 | - radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); | 491 | + eapPayload = new EAP(); |
474 | - eapPayload = new EAP(); | 492 | + eapPayload = (EAP) eapPayload.deserialize(eapMessage, 0, eapMessage.length); |
475 | - eapPayload = (EAP) eapPayload.deserialize(eapMessage, 0, eapMessage.length); | 493 | + eth = buildEapolResponse(stateMachine.supplicantAddress(), |
476 | - eth = buildEapolResponse(stateMachine.supplicantAddress(), | 494 | + MacAddress.valueOf(1L), stateMachine.vlanId(), EAPOL.EAPOL_PACKET, |
477 | - MacAddress.valueOf(1L), stateMachine.vlanId(), EAPOL.EAPOL_PACKET, | 495 | + eapPayload); |
478 | - eapPayload); | 496 | + this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); |
479 | - this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); | 497 | + |
480 | - | 498 | + stateMachine.authorizeAccess(); |
481 | - stateMachine.authorizeAccess(); | ||
482 | - } catch (StateMachineException e) { | ||
483 | - e.printStackTrace(); | ||
484 | - } | ||
485 | break; | 499 | break; |
486 | case RADIUS.RADIUS_CODE_ACCESS_REJECT: | 500 | case RADIUS.RADIUS_CODE_ACCESS_REJECT: |
487 | - try { | 501 | + stateMachine.denyAccess(); |
488 | - stateMachine.denyAccess(); | ||
489 | - } catch (StateMachineException e) { | ||
490 | - e.printStackTrace(); | ||
491 | - } | ||
492 | break; | 502 | break; |
493 | default: | 503 | default: |
494 | log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); | 504 | log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); | ... | ... |
-
Please register or login to post a comment