Search in sources :

Example 6 with MetricType

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);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) MetricType(org.gluu.model.metric.MetricType)

Example 7 with MetricType

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;
}
Also used : MetricType(org.gluu.model.metric.MetricType)

Aggregations

MetricType (org.gluu.model.metric.MetricType)7 MetricEntry (org.gluu.model.metric.ldap.MetricEntry)4 CounterMetricEntry (org.gluu.model.metric.counter.CounterMetricEntry)3 TimerMetricEntry (org.gluu.model.metric.timer.TimerMetricEntry)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timer (com.codahale.metrics.Timer)1 CounterMetricData (org.gluu.model.metric.counter.CounterMetricData)1 TimerMetricData (org.gluu.model.metric.timer.TimerMetricData)1 AuthenticationChartDto (org.gluu.oxtrust.model.AuthenticationChartDto)1 Filter (org.gluu.search.filter.Filter)1