Search in sources :

Example 1 with DefaultCasBanner

use of org.apereo.cas.util.spring.boot.DefaultCasBanner in project cas by apereo.

the class CasEmbeddedContainerUtils method getCasBannerInstance.

/**
 * Gets cas banner instance.
 *
 * @return the cas banner instance
 */
public static Banner getCasBannerInstance() {
    final String packageName = CasEmbeddedContainerUtils.class.getPackage().getName();
    final Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().includePackage(packageName)).setUrls(ClasspathHelper.forPackage(packageName)).setScanners(new SubTypesScanner(true)));
    final Set<Class<? extends AbstractCasBanner>> subTypes = reflections.getSubTypesOf(AbstractCasBanner.class);
    subTypes.remove(DefaultCasBanner.class);
    if (subTypes.isEmpty()) {
        return new DefaultCasBanner();
    }
    try {
        final Class<? extends AbstractCasBanner> clz = subTypes.iterator().next();
        LOGGER.debug("Created banner [{}]", clz);
        return clz.getDeclaredConstructor().newInstance();
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return new DefaultCasBanner();
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) AbstractCasBanner(org.apereo.cas.util.spring.boot.AbstractCasBanner) FilterBuilder(org.reflections.util.FilterBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) DefaultCasBanner(org.apereo.cas.util.spring.boot.DefaultCasBanner) UtilityClass(lombok.experimental.UtilityClass) Reflections(org.reflections.Reflections)

Example 2 with DefaultCasBanner

use of org.apereo.cas.util.spring.boot.DefaultCasBanner in project cas by apereo.

the class CasBannerProvider method getBanner.

@Override
public String getBanner() {
    if (CasCommandLineParser.isSkippingBanner(environment)) {
        return null;
    }
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        final PrintStream ps = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
        new DefaultCasBanner().printBanner(environment, getClass(), ps);
        final String content = new String(baos.toByteArray(), StandardCharsets.UTF_8);
        return content;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return "CAS";
}
Also used : PrintStream(java.io.PrintStream) DefaultCasBanner(org.apereo.cas.util.spring.boot.DefaultCasBanner) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

DefaultCasBanner (org.apereo.cas.util.spring.boot.DefaultCasBanner)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 UtilityClass (lombok.experimental.UtilityClass)1 AbstractCasBanner (org.apereo.cas.util.spring.boot.AbstractCasBanner)1 Reflections (org.reflections.Reflections)1 SubTypesScanner (org.reflections.scanners.SubTypesScanner)1 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)1 FilterBuilder (org.reflections.util.FilterBuilder)1