@Test @Ignore("have to have a radius server set up") public void testResponse() throws Exception { final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>(); final ServiceMonitor monitor = new RadiusAuthMonitor(); final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddressUtils.addr("192.168.211.11"), "RADIUS"); m.put("user", "testing"); m.put("password", "password"); m.put("retry", "1"); m.put("secret", "testing123"); m.put("authtype", "chap"); final PollStatus status = monitor.poll(svc, m); MockUtil.println("Reason: "+status.getReason()); assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode()); }
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { final NetworkInterface<InetAddress> iface = svc.getNetInterface(); PollStatus status = PollStatus.unavailable(); if (parameters == null) { throw new NullPointerException(); } final TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT); int authport = ParameterMap.getKeyedInteger(parameters, "authport", DEFAULT_AUTH_PORT); int acctport = ParameterMap.getKeyedInteger(parameters, "acctport", DEFAULT_ACCT_PORT); String user = ParameterMap.getKeyedString(parameters, "user", DEFAULT_USER); String password = ParameterMap.getKeyedString(parameters, "password", DEFAULT_PASSWORD); String secret = ParameterMap.getKeyedString(parameters, "secret", DEFAULT_SECRET); String authType = ParameterMap.getKeyedString(parameters, "authtype", DEFAULT_AUTH_TYPE); String nasid = ParameterMap.getKeyedString(parameters, "nasid", DEFAULT_NASID); InetAddress addr = iface.getAddress(); AttributeFactory.loadAttributeDictionary("net.jradius.dictionary.AttributeDictionaryImpl"); int timeout = convertTimeoutToSeconds(ParameterMap.getKeyedInteger(parameters, "timeout", DEFAULT_TIMEOUT)); try { final RadiusClient rc = new RadiusClient(addr, secret, authport, acctport, timeout); for (tracker.reset(); tracker.shouldRetry(); tracker.nextAttempt()) { final AttributeList attributes = new AttributeList(); attributes.add(new Attr_UserName(user)); attributes.add(new Attr_NASIdentifier(nasid)); attributes.add(new Attr_UserPassword(password)); final AccessRequest accessRequest = new AccessRequest(rc, attributes); final RadiusAuthenticator auth; if (authType.equalsIgnoreCase("chap")) { auth = new CHAPAuthenticator(); } else if (authType.equalsIgnoreCase("pap")) { auth = new PAPAuthenticator(); } else if (authType.equalsIgnoreCase("mschapv1")) { auth = new MSCHAPv1Authenticator(); } else if (authType.equalsIgnoreCase("mschapv2")) { auth = new MSCHAPv2Authenticator(); } else if (authType.equalsIgnoreCase("eapmd5") || authType.equalsIgnoreCase("eap-md5")) { auth = new EAPMD5Authenticator(); } else if (authType.equalsIgnoreCase("eapmschapv2") || authType.equalsIgnoreCase("eap-mschapv2")) { auth = new EAPMSCHAPv2Authenticator(); } else { return logDown(Level.ERROR, "Unknown authenticator type '" + authType + "'"); } tracker.startAttempt(); RadiusPacket reply = rc.authenticate(accessRequest, auth, ParameterMap.getKeyedInteger(parameters, "retry", DEFAULT_RETRY)); if (reply instanceof AccessAccept) { double responseTime = tracker.elapsedTimeInMillis(); status = PollStatus.available(responseTime); LogUtils.debugf(this, "Radius service is AVAILABLE on: %s", addr.getCanonicalHostName()); LogUtils.debugf(this, "poll: responseTime= %fms", responseTime); break; } else if (reply != null) { LogUtils.debugf(this, "response returned, but request was not accepted: %s", reply); } status = logDown(Level.ERROR, "Invalid RADIUS reply: " + reply); } } catch (final Throwable e) { status = logDown(Level.ERROR, "Error while attempting to connect to the RADIUS service on " + addr.getCanonicalHostName(), e); } return status; }
RadiusAuthMonitor extends AbstractServiceMonitor { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { final NetworkInterface<InetAddress> iface = svc.getNetInterface(); PollStatus status = PollStatus.unavailable(); if (parameters == null) { throw new NullPointerException(); } final TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT); int authport = ParameterMap.getKeyedInteger(parameters, "authport", DEFAULT_AUTH_PORT); int acctport = ParameterMap.getKeyedInteger(parameters, "acctport", DEFAULT_ACCT_PORT); String user = ParameterMap.getKeyedString(parameters, "user", DEFAULT_USER); String password = ParameterMap.getKeyedString(parameters, "password", DEFAULT_PASSWORD); String secret = ParameterMap.getKeyedString(parameters, "secret", DEFAULT_SECRET); String authType = ParameterMap.getKeyedString(parameters, "authtype", DEFAULT_AUTH_TYPE); String nasid = ParameterMap.getKeyedString(parameters, "nasid", DEFAULT_NASID); InetAddress addr = iface.getAddress(); AttributeFactory.loadAttributeDictionary("net.jradius.dictionary.AttributeDictionaryImpl"); int timeout = convertTimeoutToSeconds(ParameterMap.getKeyedInteger(parameters, "timeout", DEFAULT_TIMEOUT)); try { final RadiusClient rc = new RadiusClient(addr, secret, authport, acctport, timeout); for (tracker.reset(); tracker.shouldRetry(); tracker.nextAttempt()) { final AttributeList attributes = new AttributeList(); attributes.add(new Attr_UserName(user)); attributes.add(new Attr_NASIdentifier(nasid)); attributes.add(new Attr_UserPassword(password)); final AccessRequest accessRequest = new AccessRequest(rc, attributes); final RadiusAuthenticator auth; if (authType.equalsIgnoreCase("chap")) { auth = new CHAPAuthenticator(); } else if (authType.equalsIgnoreCase("pap")) { auth = new PAPAuthenticator(); } else if (authType.equalsIgnoreCase("mschapv1")) { auth = new MSCHAPv1Authenticator(); } else if (authType.equalsIgnoreCase("mschapv2")) { auth = new MSCHAPv2Authenticator(); } else if (authType.equalsIgnoreCase("eapmd5") || authType.equalsIgnoreCase("eap-md5")) { auth = new EAPMD5Authenticator(); } else if (authType.equalsIgnoreCase("eapmschapv2") || authType.equalsIgnoreCase("eap-mschapv2")) { auth = new EAPMSCHAPv2Authenticator(); } else { return logDown(Level.ERROR, "Unknown authenticator type '" + authType + "'"); } tracker.startAttempt(); RadiusPacket reply = rc.authenticate(accessRequest, auth, ParameterMap.getKeyedInteger(parameters, "retry", DEFAULT_RETRY)); if (reply instanceof AccessAccept) { double responseTime = tracker.elapsedTimeInMillis(); status = PollStatus.available(responseTime); LogUtils.debugf(this, "Radius service is AVAILABLE on: %s", addr.getCanonicalHostName()); LogUtils.debugf(this, "poll: responseTime= %fms", responseTime); break; } else if (reply != null) { LogUtils.debugf(this, "response returned, but request was not accepted: %s", reply); } status = logDown(Level.ERROR, "Invalid RADIUS reply: " + reply); } } catch (final Throwable e) { status = logDown(Level.ERROR, "Error while attempting to connect to the RADIUS service on " + addr.getCanonicalHostName(), e); } return status; } }
RadiusAuthMonitor extends AbstractServiceMonitor { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { final NetworkInterface<InetAddress> iface = svc.getNetInterface(); PollStatus status = PollStatus.unavailable(); if (parameters == null) { throw new NullPointerException(); } final TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT); int authport = ParameterMap.getKeyedInteger(parameters, "authport", DEFAULT_AUTH_PORT); int acctport = ParameterMap.getKeyedInteger(parameters, "acctport", DEFAULT_ACCT_PORT); String user = ParameterMap.getKeyedString(parameters, "user", DEFAULT_USER); String password = ParameterMap.getKeyedString(parameters, "password", DEFAULT_PASSWORD); String secret = ParameterMap.getKeyedString(parameters, "secret", DEFAULT_SECRET); String authType = ParameterMap.getKeyedString(parameters, "authtype", DEFAULT_AUTH_TYPE); String nasid = ParameterMap.getKeyedString(parameters, "nasid", DEFAULT_NASID); InetAddress addr = iface.getAddress(); AttributeFactory.loadAttributeDictionary("net.jradius.dictionary.AttributeDictionaryImpl"); int timeout = convertTimeoutToSeconds(ParameterMap.getKeyedInteger(parameters, "timeout", DEFAULT_TIMEOUT)); try { final RadiusClient rc = new RadiusClient(addr, secret, authport, acctport, timeout); for (tracker.reset(); tracker.shouldRetry(); tracker.nextAttempt()) { final AttributeList attributes = new AttributeList(); attributes.add(new Attr_UserName(user)); attributes.add(new Attr_NASIdentifier(nasid)); attributes.add(new Attr_UserPassword(password)); final AccessRequest accessRequest = new AccessRequest(rc, attributes); final RadiusAuthenticator auth; if (authType.equalsIgnoreCase("chap")) { auth = new CHAPAuthenticator(); } else if (authType.equalsIgnoreCase("pap")) { auth = new PAPAuthenticator(); } else if (authType.equalsIgnoreCase("mschapv1")) { auth = new MSCHAPv1Authenticator(); } else if (authType.equalsIgnoreCase("mschapv2")) { auth = new MSCHAPv2Authenticator(); } else if (authType.equalsIgnoreCase("eapmd5") || authType.equalsIgnoreCase("eap-md5")) { auth = new EAPMD5Authenticator(); } else if (authType.equalsIgnoreCase("eapmschapv2") || authType.equalsIgnoreCase("eap-mschapv2")) { auth = new EAPMSCHAPv2Authenticator(); } else { return logDown(Level.ERROR, "Unknown authenticator type '" + authType + "'"); } tracker.startAttempt(); RadiusPacket reply = rc.authenticate(accessRequest, auth, ParameterMap.getKeyedInteger(parameters, "retry", DEFAULT_RETRY)); if (reply instanceof AccessAccept) { double responseTime = tracker.elapsedTimeInMillis(); status = PollStatus.available(responseTime); LogUtils.debugf(this, "Radius service is AVAILABLE on: %s", addr.getCanonicalHostName()); LogUtils.debugf(this, "poll: responseTime= %fms", responseTime); break; } else if (reply != null) { LogUtils.debugf(this, "response returned, but request was not accepted: %s", reply); } status = logDown(Level.ERROR, "Invalid RADIUS reply: " + reply); } } catch (final Throwable e) { status = logDown(Level.ERROR, "Error while attempting to connect to the RADIUS service on " + addr.getCanonicalHostName(), e); } return status; } RadiusAuthMonitor(); }
RadiusAuthMonitor extends AbstractServiceMonitor { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { final NetworkInterface<InetAddress> iface = svc.getNetInterface(); PollStatus status = PollStatus.unavailable(); if (parameters == null) { throw new NullPointerException(); } final TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT); int authport = ParameterMap.getKeyedInteger(parameters, "authport", DEFAULT_AUTH_PORT); int acctport = ParameterMap.getKeyedInteger(parameters, "acctport", DEFAULT_ACCT_PORT); String user = ParameterMap.getKeyedString(parameters, "user", DEFAULT_USER); String password = ParameterMap.getKeyedString(parameters, "password", DEFAULT_PASSWORD); String secret = ParameterMap.getKeyedString(parameters, "secret", DEFAULT_SECRET); String authType = ParameterMap.getKeyedString(parameters, "authtype", DEFAULT_AUTH_TYPE); String nasid = ParameterMap.getKeyedString(parameters, "nasid", DEFAULT_NASID); InetAddress addr = iface.getAddress(); AttributeFactory.loadAttributeDictionary("net.jradius.dictionary.AttributeDictionaryImpl"); int timeout = convertTimeoutToSeconds(ParameterMap.getKeyedInteger(parameters, "timeout", DEFAULT_TIMEOUT)); try { final RadiusClient rc = new RadiusClient(addr, secret, authport, acctport, timeout); for (tracker.reset(); tracker.shouldRetry(); tracker.nextAttempt()) { final AttributeList attributes = new AttributeList(); attributes.add(new Attr_UserName(user)); attributes.add(new Attr_NASIdentifier(nasid)); attributes.add(new Attr_UserPassword(password)); final AccessRequest accessRequest = new AccessRequest(rc, attributes); final RadiusAuthenticator auth; if (authType.equalsIgnoreCase("chap")) { auth = new CHAPAuthenticator(); } else if (authType.equalsIgnoreCase("pap")) { auth = new PAPAuthenticator(); } else if (authType.equalsIgnoreCase("mschapv1")) { auth = new MSCHAPv1Authenticator(); } else if (authType.equalsIgnoreCase("mschapv2")) { auth = new MSCHAPv2Authenticator(); } else if (authType.equalsIgnoreCase("eapmd5") || authType.equalsIgnoreCase("eap-md5")) { auth = new EAPMD5Authenticator(); } else if (authType.equalsIgnoreCase("eapmschapv2") || authType.equalsIgnoreCase("eap-mschapv2")) { auth = new EAPMSCHAPv2Authenticator(); } else { return logDown(Level.ERROR, "Unknown authenticator type '" + authType + "'"); } tracker.startAttempt(); RadiusPacket reply = rc.authenticate(accessRequest, auth, ParameterMap.getKeyedInteger(parameters, "retry", DEFAULT_RETRY)); if (reply instanceof AccessAccept) { double responseTime = tracker.elapsedTimeInMillis(); status = PollStatus.available(responseTime); LogUtils.debugf(this, "Radius service is AVAILABLE on: %s", addr.getCanonicalHostName()); LogUtils.debugf(this, "poll: responseTime= %fms", responseTime); break; } else if (reply != null) { LogUtils.debugf(this, "response returned, but request was not accepted: %s", reply); } status = logDown(Level.ERROR, "Invalid RADIUS reply: " + reply); } } catch (final Throwable e) { status = logDown(Level.ERROR, "Error while attempting to connect to the RADIUS service on " + addr.getCanonicalHostName(), e); } return status; } RadiusAuthMonitor(); PollStatus poll(MonitoredService svc, Map<String, Object> parameters); }
RadiusAuthMonitor extends AbstractServiceMonitor { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { final NetworkInterface<InetAddress> iface = svc.getNetInterface(); PollStatus status = PollStatus.unavailable(); if (parameters == null) { throw new NullPointerException(); } final TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT); int authport = ParameterMap.getKeyedInteger(parameters, "authport", DEFAULT_AUTH_PORT); int acctport = ParameterMap.getKeyedInteger(parameters, "acctport", DEFAULT_ACCT_PORT); String user = ParameterMap.getKeyedString(parameters, "user", DEFAULT_USER); String password = ParameterMap.getKeyedString(parameters, "password", DEFAULT_PASSWORD); String secret = ParameterMap.getKeyedString(parameters, "secret", DEFAULT_SECRET); String authType = ParameterMap.getKeyedString(parameters, "authtype", DEFAULT_AUTH_TYPE); String nasid = ParameterMap.getKeyedString(parameters, "nasid", DEFAULT_NASID); InetAddress addr = iface.getAddress(); AttributeFactory.loadAttributeDictionary("net.jradius.dictionary.AttributeDictionaryImpl"); int timeout = convertTimeoutToSeconds(ParameterMap.getKeyedInteger(parameters, "timeout", DEFAULT_TIMEOUT)); try { final RadiusClient rc = new RadiusClient(addr, secret, authport, acctport, timeout); for (tracker.reset(); tracker.shouldRetry(); tracker.nextAttempt()) { final AttributeList attributes = new AttributeList(); attributes.add(new Attr_UserName(user)); attributes.add(new Attr_NASIdentifier(nasid)); attributes.add(new Attr_UserPassword(password)); final AccessRequest accessRequest = new AccessRequest(rc, attributes); final RadiusAuthenticator auth; if (authType.equalsIgnoreCase("chap")) { auth = new CHAPAuthenticator(); } else if (authType.equalsIgnoreCase("pap")) { auth = new PAPAuthenticator(); } else if (authType.equalsIgnoreCase("mschapv1")) { auth = new MSCHAPv1Authenticator(); } else if (authType.equalsIgnoreCase("mschapv2")) { auth = new MSCHAPv2Authenticator(); } else if (authType.equalsIgnoreCase("eapmd5") || authType.equalsIgnoreCase("eap-md5")) { auth = new EAPMD5Authenticator(); } else if (authType.equalsIgnoreCase("eapmschapv2") || authType.equalsIgnoreCase("eap-mschapv2")) { auth = new EAPMSCHAPv2Authenticator(); } else { return logDown(Level.ERROR, "Unknown authenticator type '" + authType + "'"); } tracker.startAttempt(); RadiusPacket reply = rc.authenticate(accessRequest, auth, ParameterMap.getKeyedInteger(parameters, "retry", DEFAULT_RETRY)); if (reply instanceof AccessAccept) { double responseTime = tracker.elapsedTimeInMillis(); status = PollStatus.available(responseTime); LogUtils.debugf(this, "Radius service is AVAILABLE on: %s", addr.getCanonicalHostName()); LogUtils.debugf(this, "poll: responseTime= %fms", responseTime); break; } else if (reply != null) { LogUtils.debugf(this, "response returned, but request was not accepted: %s", reply); } status = logDown(Level.ERROR, "Invalid RADIUS reply: " + reply); } } catch (final Throwable e) { status = logDown(Level.ERROR, "Error while attempting to connect to the RADIUS service on " + addr.getCanonicalHostName(), e); } return status; } RadiusAuthMonitor(); PollStatus poll(MonitoredService svc, Map<String, Object> parameters); static final int DEFAULT_TIMEOUT; static final int DEFAULT_RETRY; static final int DEFAULT_AUTH_PORT; static final int DEFAULT_ACCT_PORT; static final String DEFAULT_AUTH_TYPE; static final String DEFAULT_USER; static final String DEFAULT_PASSWORD; static final String DEFAULT_SECRET; static final String DEFAULT_NASID; }