Search in sources :

Example 1 with EnvironmentCheck

use of org.apache.archiva.redback.system.check.EnvironmentCheck in project archiva by apache.

the class SecuritySynchronization method executeEnvironmentChecks.

private void executeEnvironmentChecks() throws ArchivaException {
    if ((checkers == null) || CollectionUtils.isEmpty(checkers.values())) {
        throw new ArchivaException("Unable to initialize the Redback Security Environment, " + "no Environment Check components found.");
    }
    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();
    List<String> violations = new ArrayList<>();
    for (Entry<String, EnvironmentCheck> entry : checkers.entrySet()) {
        EnvironmentCheck check = entry.getValue();
        List<String> v = new ArrayList<>();
        check.validateEnvironment(v);
        log.info("Environment Check: {} -> {} violation(s)", entry.getKey(), v.size());
        for (String s : v) {
            violations.add("[" + entry.getKey() + "] " + s);
        }
    }
    if (CollectionUtils.isNotEmpty(violations)) {
        StringBuilder msg = new StringBuilder();
        msg.append("EnvironmentCheck Failure.\n");
        msg.append("======================================================================\n");
        msg.append(" ENVIRONMENT FAILURE !! \n");
        msg.append("\n");
        for (String violation : violations) {
            msg.append(violation).append("\n");
        }
        msg.append("\n");
        msg.append("======================================================================");
        log.error(msg.toString());
        throw new ArchivaException("Unable to initialize Redback Security Environment, [" + violations.size() + "] violation(s) encountered, See log for details.");
    }
    stopWatch.stop();
    log.info("time to execute all EnvironmentCheck: {} ms", stopWatch.getTime());
}
Also used : ArrayList(java.util.ArrayList) ArchivaException(org.apache.archiva.common.ArchivaException) EnvironmentCheck(org.apache.archiva.redback.system.check.EnvironmentCheck) StopWatch(org.apache.commons.lang.time.StopWatch)

Aggregations

ArrayList (java.util.ArrayList)1 ArchivaException (org.apache.archiva.common.ArchivaException)1 EnvironmentCheck (org.apache.archiva.redback.system.check.EnvironmentCheck)1 StopWatch (org.apache.commons.lang.time.StopWatch)1