Search in sources :

Example 11 with Objects

use of java.util.Objects in project caffeine by ben-manes.

the class LoadingCacheProxy method loadAll.

@Override
public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) {
    requireNotClosed();
    keys.forEach(Objects::requireNonNull);
    CompletionListener listener = (completionListener == null) ? NullCompletionListener.INSTANCE : completionListener;
    executor.execute(() -> {
        try {
            if (replaceExistingValues) {
                int[] ignored = { 0 };
                Map<K, V> loaded = cacheLoader.get().loadAll(keys);
                for (Map.Entry<? extends K, ? extends V> entry : loaded.entrySet()) {
                    putNoCopyOrAwait(entry.getKey(), entry.getValue(), /* publishToWriter */
                    false, ignored);
                }
            } else {
                getAll(keys, /* updateAccessTime */
                false);
            }
            listener.onCompletion();
        } catch (Exception e) {
            listener.onException(e);
        } finally {
            dispatcher.ignoreSynchronous();
        }
    });
}
Also used : CompletionListener(javax.cache.integration.CompletionListener) Objects(java.util.Objects) Map(java.util.Map) CacheException(javax.cache.CacheException)

Example 12 with Objects

use of java.util.Objects in project cas by apereo.

the class AbstractCRLRevocationChecker method check.

@Override
public void check(final X509Certificate cert) throws GeneralSecurityException {
    if (cert == null) {
        throw new IllegalArgumentException("Certificate cannot be null.");
    }
    LOGGER.debug("Evaluating certificate revocation status for [{}]", CertUtils.toString(cert));
    final Collection<X509CRL> crls = getCRLs(cert);
    if (crls == null || crls.isEmpty()) {
        LOGGER.warn("CRL data is not available for [{}]", CertUtils.toString(cert));
        this.unavailableCRLPolicy.apply(null);
        return;
    }
    final List<X509CRL> expiredCrls = new ArrayList<>();
    final List<X509CRLEntry> revokedCrls;
    crls.stream().filter(CertUtils::isExpired).forEach(crl -> {
        LOGGER.warn("CRL data expired on [{}]", crl.getNextUpdate());
        expiredCrls.add(crl);
    });
    if (crls.size() == expiredCrls.size()) {
        LOGGER.warn("All CRLs retrieved have expired. Applying CRL expiration policy...");
        for (final X509CRL crl : expiredCrls) {
            this.expiredCRLPolicy.apply(crl);
        }
    } else {
        crls.removeAll(expiredCrls);
        LOGGER.debug("Valid CRLs [{}] found that are not expired yet", crls);
        revokedCrls = crls.stream().map(crl -> crl.getRevokedCertificate(cert)).filter(Objects::nonNull).collect(Collectors.toList());
        if (revokedCrls.size() == crls.size()) {
            final X509CRLEntry entry = revokedCrls.get(0);
            LOGGER.warn("All CRL entries have been revoked. Rejecting the first entry [{}]", entry);
            throw new RevokedCertificateException(entry);
        }
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) RevocationPolicy(org.apereo.cas.adaptors.x509.authentication.revocation.policy.RevocationPolicy) X509CRLEntry(java.security.cert.X509CRLEntry) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) X509CRL(java.security.cert.X509CRL) Collectors(java.util.stream.Collectors) RevokedCertificateException(org.apereo.cas.adaptors.x509.authentication.revocation.RevokedCertificateException) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) DenyRevocationPolicy(org.apereo.cas.adaptors.x509.authentication.revocation.policy.DenyRevocationPolicy) GeneralSecurityException(java.security.GeneralSecurityException) CertUtils(org.apereo.cas.adaptors.x509.util.CertUtils) ThresholdExpiredCRLRevocationPolicy(org.apereo.cas.adaptors.x509.authentication.revocation.policy.ThresholdExpiredCRLRevocationPolicy) X509CRLEntry(java.security.cert.X509CRLEntry) X509CRL(java.security.cert.X509CRL) RevokedCertificateException(org.apereo.cas.adaptors.x509.authentication.revocation.RevokedCertificateException) ArrayList(java.util.ArrayList) Objects(java.util.Objects)

Example 13 with Objects

use of java.util.Objects in project cas by apereo.

the class CRLDistributionPointRevocationChecker method getDistributionPoints.

/**
     * Gets the distribution points.
     *
     * @param cert the cert
     * @return the url distribution points
     */
private URI[] getDistributionPoints(final X509Certificate cert) {
    final List<DistributionPoint> points;
    try {
        points = new ExtensionReader(cert).readCRLDistributionPoints();
    } catch (final RuntimeException e) {
        LOGGER.error("Error reading CRLDistributionPoints extension field on [{}]", CertUtils.toString(cert), e);
        return new URI[0];
    }
    final List<URI> urls = new ArrayList<>();
    if (points != null) {
        points.stream().map(DistributionPoint::getDistributionPoint).filter(Objects::nonNull).forEach(pointName -> {
            final ASN1Sequence nameSequence = ASN1Sequence.getInstance(pointName.getName());
            IntStream.range(0, nameSequence.size()).mapToObj(i -> GeneralName.getInstance(nameSequence.getObjectAt(i))).forEach(name -> {
                LOGGER.debug("Found CRL distribution point [{}].", name);
                try {
                    addURL(urls, DERIA5String.getInstance(name.getName()).getString());
                } catch (final RuntimeException e) {
                    LOGGER.warn("[{}] not supported. String or GeneralNameList expected.", pointName);
                }
            });
        });
    }
    return urls.toArray(new URI[urls.size()]);
}
Also used : X509Certificate(java.security.cert.X509Certificate) IntStream(java.util.stream.IntStream) RevocationPolicy(org.apereo.cas.adaptors.x509.authentication.revocation.policy.RevocationPolicy) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Arrays(java.util.Arrays) URLDecoder(java.net.URLDecoder) URL(java.net.URL) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) LoggerFactory(org.slf4j.LoggerFactory) X509CRL(java.security.cert.X509CRL) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ArrayList(java.util.ArrayList) CertUtils(org.apereo.cas.adaptors.x509.util.CertUtils) URI(java.net.URI) DERIA5String(org.bouncycastle.asn1.DERIA5String) Logger(org.slf4j.Logger) CRLFetcher(org.apereo.cas.adaptors.x509.authentication.CRLFetcher) MalformedURLException(java.net.MalformedURLException) Throwables(com.google.common.base.Throwables) Element(net.sf.ehcache.Element) StandardCharsets(java.nio.charset.StandardCharsets) ExtensionReader(org.cryptacular.x509.ExtensionReader) Objects(java.util.Objects) GeneralName(org.bouncycastle.asn1.x509.GeneralName) List(java.util.List) ResourceCRLFetcher(org.apereo.cas.adaptors.x509.authentication.ResourceCRLFetcher) Cache(net.sf.ehcache.Cache) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ArrayList(java.util.ArrayList) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) URI(java.net.URI) ExtensionReader(org.cryptacular.x509.ExtensionReader)

Example 14 with Objects

use of java.util.Objects in project robo4j by Robo4J.

the class TestClientImageController method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    SimpleLoggingUtil.print(getClass(), "camera client init");
    Map<String, String> parameters = new HashMap<>();
    //64
    parameters.put(KEY_WIDTH, configuration.getString(KEY_WIDTH, "320"));
    //45
    parameters.put(KEY_HEIGHT, configuration.getString(KEY_HEIGHT, "240"));
    StringBuilder sb = new StringBuilder(RASPI_CAMERA).append(SPACE).append(parameters.entrySet().stream().map(e -> {
        StringBuilder c = new StringBuilder();
        if (raspistillProperties.containsKey(e.getKey())) {
            return c.append(raspistillProperties.get(e.getKey())).append(SPACE).append(e.getValue()).toString();
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.joining(SPACE))).append(SPACE).append(DEFAULT_SETUP);
    cameraCommand = sb.toString();
    SimpleLoggingUtil.print(getClass(), "camera cameraCommand: " + cameraCommand);
    targetOut = configuration.getString("targetOut", null);
    String tmpClient = configuration.getString("client", null);
    if (tmpClient == null || targetOut == null) {
        throw ConfigurationException.createMissingConfigNameException("targetOut, client");
    }
    try {
        InetAddress inetAddress = InetAddress.getByName(tmpClient);
        String clientPort = configuration.getString("clientPort", null);
        client = clientPort == null ? inetAddress.getHostAddress() : inetAddress.getHostAddress().concat(":").concat(clientPort);
        clientUri = configuration.getString("clientUri", Constants.EMPTY_STRING);
    } catch (UnknownHostException e) {
        SimpleLoggingUtil.error(getClass(), "unknown ip address", e);
        throw ConfigurationException.createMissingConfigNameException("unknown ip address");
    }
}
Also used : LifecycleState(com.robo4j.core.LifecycleState) CameraMessageCodec(com.robo4j.core.httpunit.codec.CameraMessageCodec) IOException(java.io.IOException) HashMap(java.util.HashMap) ConfigurationException(com.robo4j.core.ConfigurationException) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) RoboUnit(com.robo4j.core.RoboUnit) InetAddress(java.net.InetAddress) Objects(java.util.Objects) Base64(java.util.Base64) RoboHttpUtils(com.robo4j.core.client.util.RoboHttpUtils) CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage) PropertyMapBuilder(com.robo4j.core.httpunit.test.util.PropertyMapBuilder) RoboClassLoader(com.robo4j.core.client.util.RoboClassLoader) SimpleLoggingUtil(com.robo4j.core.logging.SimpleLoggingUtil) Map(java.util.Map) RoboContext(com.robo4j.core.RoboContext) Configuration(com.robo4j.core.configuration.Configuration) Constants(com.robo4j.core.httpunit.Constants) InputStream(java.io.InputStream) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) Objects(java.util.Objects) InetAddress(java.net.InetAddress)

Example 15 with Objects

use of java.util.Objects in project robo4j by Robo4J.

the class PersistenceDescriptorFactory method scanForEntities.

private List<String> scanForEntities(ClassLoader loader, String... entityPackages) {
    ReflectionScan scan = new ReflectionScan(loader);
    List<String> classesNames = processClassesWithAnnotation(loader, scan.scanForEntities(entityPackages));
    registeredClasses = classesNames.stream().map(cn -> {
        try {
            return RoboClassLoader.getInstance().getClassLoader().loadClass(cn);
        } catch (ClassNotFoundException e) {
            SimpleLoggingUtil.error(getClass(), "failed to load class: ", e);
            return null;
        }
    }).filter(Objects::nonNull).collect(Collectors.toList());
    return classesNames;
}
Also used : Objects(java.util.Objects) Entity(javax.persistence.Entity) List(java.util.List) Properties(java.util.Properties) RoboClassLoader(com.robo4j.core.client.util.RoboClassLoader) SimpleLoggingUtil(com.robo4j.core.logging.SimpleLoggingUtil) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) ReflectionScan(com.robo4j.core.reflect.ReflectionScan) DataSourceType(com.robo4j.db.sql.support.DataSourceType) RoboDbException(com.robo4j.db.sql.RoboDbException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ReflectionScan(com.robo4j.core.reflect.ReflectionScan)

Aggregations

Objects (java.util.Objects)55 List (java.util.List)29 Map (java.util.Map)24 Collectors (java.util.stream.Collectors)22 ArrayList (java.util.ArrayList)20 Set (java.util.Set)19 Optional (java.util.Optional)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)14 Collections (java.util.Collections)13 HashSet (java.util.HashSet)10 ImmutableSet (com.google.common.collect.ImmutableSet)9 Result (ddf.catalog.data.Result)9 Stream (java.util.stream.Stream)9 Metacard (ddf.catalog.data.Metacard)8 TimeUnit (java.util.concurrent.TimeUnit)8 LoggerFactory (org.slf4j.LoggerFactory)8 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 Path (java.nio.file.Path)7 Logger (org.slf4j.Logger)7