Search in sources :

Example 1 with MetricType

use of org.gluu.model.metric.MetricType in project oxAuth by GluuFederation.

the class AuthenticationService method authenticate.

/*
	 * Utility method which can be used in custom scripts
	 */
public boolean authenticate(GluuLdapConfiguration ldapAuthConfig, PersistenceEntryManager ldapAuthEntryManager, String keyValue, String password, String primaryKey, String localPrimaryKey, boolean updateMetrics) {
    boolean authenticated = false;
    boolean protectionServiceEnabled = authenticationProtectionService.isEnabled();
    com.codahale.metrics.Timer.Context timerContext = null;
    if (updateMetrics) {
        timerContext = metricService.getTimer(MetricType.OXAUTH_USER_AUTHENTICATION_RATE).time();
    }
    try {
        authenticated = authenticateImpl(ldapAuthConfig, ldapAuthEntryManager, keyValue, password, primaryKey, localPrimaryKey);
    } finally {
        if (updateMetrics) {
            timerContext.stop();
        }
    }
    String userId = keyValue;
    if ((identity.getUser() != null) && StringHelper.isNotEmpty(identity.getUser().getUserId())) {
        userId = identity.getUser().getUserId();
    }
    setAuthenticatedUserSessionAttribute(userId, authenticated);
    if (updateMetrics) {
        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)

Example 2 with MetricType

use of org.gluu.model.metric.MetricType in project oxCore by GluuFederation.

the class LdapEntryReporter method builCounterEntries.

private List<MetricEntry> builCounterEntries(SortedMap<String, Counter> counters, Set<MetricType> registeredMetricTypes) {
    List<MetricEntry> result = new ArrayList<MetricEntry>();
    Set<MetricType> currentRegisteredMetricTypes = new HashSet<MetricType>(registeredMetricTypes);
    for (MetricType metricType : currentRegisteredMetricTypes) {
        Counter counter = counters.get(metricType.getValue());
        if (counter != null) {
            long count = counter.getCount();
            // Remove to avoid writing not changed statistic
            // registeredMetricTypes.remove(metricType);
            CounterMetricData counterMetricData = new CounterMetricData(count);
            CounterMetricEntry counterMetricEntry = new CounterMetricEntry();
            counterMetricEntry.setMetricData(counterMetricData);
            counterMetricEntry.setMetricType(metricType);
            result.add(counterMetricEntry);
        }
    }
    return result;
}
Also used : MetricType(org.gluu.model.metric.MetricType) TimerMetricEntry(org.gluu.model.metric.timer.TimerMetricEntry) MetricEntry(org.gluu.model.metric.ldap.MetricEntry) CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry) CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry) CounterMetricData(org.gluu.model.metric.counter.CounterMetricData)

Example 3 with MetricType

use of org.gluu.model.metric.MetricType in project oxCore by GluuFederation.

the class MetricService method findMetricEntry.

public Map<MetricType, List<? extends MetricEntry>> findMetricEntry(ApplicationType applicationType, List<MetricType> metricTypes, Date startDate, Date endDate, String... returnAttributes) {
    prepareBranch(null, applicationType);
    Map<MetricType, List<? extends MetricEntry>> result = new HashMap<MetricType, List<? extends MetricEntry>>();
    if ((metricTypes == null) || (metricTypes.size() == 0)) {
        return result;
    }
    // Prepare list of DNs
    Set<String> metricDns = getBaseDnForPeriod(applicationType, startDate, endDate);
    if (metricDns.size() == 0) {
        return result;
    }
    for (MetricType metricType : metricTypes) {
        List<MetricEntry> metricTypeResult = new LinkedList<MetricEntry>();
        for (String metricDn : metricDns) {
            List<Filter> metricTypeFilters = new ArrayList<Filter>();
            Filter applicationTypeFilter = Filter.createEqualityFilter("oxApplicationType", applicationType.getValue());
            Filter eventTypeTypeFilter = Filter.createEqualityFilter("oxMetricType", metricType.getValue());
            Filter startDateFilter = Filter.createGreaterOrEqualFilter("oxStartDate", getEntryManager().encodeTime(metricDn, (startDate)));
            Filter endDateFilter = Filter.createLessOrEqualFilter("oxEndDate", getEntryManager().encodeTime(metricDn, endDate));
            metricTypeFilters.add(applicationTypeFilter);
            metricTypeFilters.add(eventTypeTypeFilter);
            metricTypeFilters.add(startDateFilter);
            metricTypeFilters.add(endDateFilter);
            Filter filter = Filter.createANDFilter(metricTypeFilters);
            List<? extends MetricEntry> metricTypeMonthResult = (List<? extends MetricEntry>) getEntryManager().findEntries(metricDn, metricType.getMetricEntryType(), filter, returnAttributes);
            metricTypeResult.addAll(metricTypeMonthResult);
        }
        // Sort entries to avoid calculation errors
        getEntryManager().sortListByProperties(MetricEntry.class, metricTypeResult, false, "creationDate");
        result.put(metricType, metricTypeResult);
    }
    return result;
}
Also used : MetricType(org.gluu.model.metric.MetricType) MetricEntry(org.gluu.model.metric.ldap.MetricEntry) Filter(org.gluu.search.filter.Filter)

Example 4 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)

Example 5 with MetricType

use of org.gluu.model.metric.MetricType in project oxCore by GluuFederation.

the class LdapEntryReporter method builTimerEntries.

private List<MetricEntry> builTimerEntries(SortedMap<String, Timer> timers, Set<MetricType> registeredMetricTypes) {
    List<MetricEntry> result = new ArrayList<MetricEntry>();
    for (MetricType metricType : registeredMetricTypes) {
        Timer timer = timers.get(metricType.getValue());
        if (timer != null) {
            Snapshot snapshot = timer.getSnapshot();
            TimerMetricData timerMetricData = new TimerMetricData(timer.getCount(), convertRate(timer.getMeanRate()), convertRate(timer.getOneMinuteRate()), convertRate(timer.getFiveMinuteRate()), convertRate(timer.getFifteenMinuteRate()), getRateUnit(), convertDuration(snapshot.getMin()), convertDuration(snapshot.getMax()), convertDuration(snapshot.getMean()), convertDuration(snapshot.getStdDev()), convertDuration(snapshot.getMedian()), convertDuration(snapshot.get75thPercentile()), convertDuration(snapshot.get95thPercentile()), convertDuration(snapshot.get98thPercentile()), convertDuration(snapshot.get99thPercentile()), convertDuration(snapshot.get999thPercentile()), getDurationUnit());
            TimerMetricEntry timerMetricEntry = new TimerMetricEntry();
            timerMetricEntry.setMetricData(timerMetricData);
            timerMetricEntry.setMetricType(metricType);
            result.add(timerMetricEntry);
        }
    }
    return result;
}
Also used : Timer(com.codahale.metrics.Timer) MetricType(org.gluu.model.metric.MetricType) TimerMetricEntry(org.gluu.model.metric.timer.TimerMetricEntry) MetricEntry(org.gluu.model.metric.ldap.MetricEntry) CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry) TimerMetricData(org.gluu.model.metric.timer.TimerMetricData) TimerMetricEntry(org.gluu.model.metric.timer.TimerMetricEntry)

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