use of org.gluu.model.metric.MetricType in project oxCore by GluuFederation.
the class MetricService method initTimer.
public void initTimer(int metricInterval, int entryLifetimeInDays) {
this.metricRegistry = new MetricRegistry();
this.registeredMetricTypes = new HashSet<MetricType>();
this.entryLifetimeInDays = entryLifetimeInDays;
this.ldapEntryReporter = LdapEntryReporter.forRegistry(this.metricRegistry, getMetricServiceInstance()).build();
int metricReporterInterval = metricInterval;
if (metricReporterInterval <= 0) {
metricReporterInterval = DEFAULT_METRIC_REPORTER_INTERVAL;
}
ldapEntryReporter.start(metricReporterInterval, TimeUnit.SECONDS);
}
use of org.gluu.model.metric.MetricType in project oxAuth by GluuFederation.
the class AuthenticationService method authenticate.
/**
* Authenticate user.
*
* @param userName
* The username.
* @param password
* The user's password.
* @return <code>true</code> if success, otherwise <code>false</code>.
*/
public boolean authenticate(String userName, String password) {
log.debug("Authenticating user with LDAP: username: '{}', credentials: '{}'", userName, System.identityHashCode(credentials));
boolean authenticated = false;
boolean protectionServiceEnabled = authenticationProtectionService.isEnabled();
com.codahale.metrics.Timer.Context timerContext = null;
timerContext = metricService.getTimer(MetricType.OXAUTH_USER_AUTHENTICATION_RATE).time();
try {
if ((this.ldapAuthConfigs == null) || (this.ldapAuthConfigs.size() == 0)) {
authenticated = localAuthenticate(userName, password);
} else {
authenticated = externalAuthenticate(userName, password);
}
} finally {
timerContext.stop();
}
String userId = userName;
if ((identity.getUser() != null) && StringHelper.isNotEmpty(identity.getUser().getUserId())) {
userId = identity.getUser().getUserId();
}
setAuthenticatedUserSessionAttribute(userId, authenticated);
MetricType metricType;
if (authenticated) {
metricType = MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS;
} else {
metricType = MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES;
}
metricService.incCounter(metricType);
if (protectionServiceEnabled) {
authenticationProtectionService.storeAttempt(userId, authenticated);
authenticationProtectionService.doDelayIfNeeded(userId);
}
return authenticated;
}
Aggregations