Search in sources :

Example 1 with Synchronized

use of lombok.Synchronized in project cas by apereo.

the class AbstractMetadataResolverAdapter method buildMetadataResolverAggregate.

/**
 * Build metadata resolver aggregate. Loops through metadata resources
 * and attempts to resolve the metadata.
 *
 * @param entityId the entity id
 */
@Synchronized
@SneakyThrows
public void buildMetadataResolverAggregate(final String entityId) {
    LOGGER.debug("Building metadata resolver aggregate");
    this.metadataResolver = new ChainingMetadataResolver();
    final List<MetadataResolver> resolvers = new ArrayList<>();
    final Set<Map.Entry<Resource, MetadataFilterChain>> entries = this.metadataResources.entrySet();
    entries.forEach(entry -> {
        final Resource resource = entry.getKey();
        LOGGER.debug("Loading [{}]", resource.getFilename());
        resolvers.addAll(loadMetadataFromResource(entry.getValue(), resource, entityId));
    });
    this.metadataResolver.setId(ChainingMetadataResolver.class.getCanonicalName());
    this.metadataResolver.setResolvers(resolvers);
    LOGGER.info("Collected metadata from [{}] resolvers(s). Initializing aggregate resolver...", resolvers.size());
    this.metadataResolver.initialize();
    LOGGER.info("Metadata aggregate initialized successfully.");
}
Also used : ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) DOMMetadataResolver(org.opensaml.saml.metadata.resolver.impl.DOMMetadataResolver) Synchronized(lombok.Synchronized) SneakyThrows(lombok.SneakyThrows)

Example 2 with Synchronized

use of lombok.Synchronized in project cas by apereo.

the class JcifsSpnegoAuthenticationHandler method doAuthentication.

@Override
@Synchronized
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) throws GeneralSecurityException {
    final SpnegoCredential spnegoCredential = (SpnegoCredential) credential;
    final java.security.Principal principal;
    final byte[] nextToken;
    if (!this.ntlmAllowed && spnegoCredential.isNtlm()) {
        throw new FailedLoginException("NTLM not allowed");
    }
    try {
        this.authentication.reset();
        LOGGER.debug("Processing SPNEGO authentication");
        this.authentication.process(spnegoCredential.getInitToken());
        principal = this.authentication.getPrincipal();
        LOGGER.debug("Authenticated SPNEGO principal [{}]", principal != null ? principal.getName() : null);
        LOGGER.debug("Retrieving the next token for authentication");
        nextToken = this.authentication.getNextToken();
    } catch (final jcifs.spnego.AuthenticationException e) {
        LOGGER.debug("Processing SPNEGO authentication failed with exception", e);
        throw new FailedLoginException(e.getMessage());
    }
    if (nextToken != null) {
        LOGGER.debug("Setting nextToken in credential");
        spnegoCredential.setNextToken(nextToken);
    } else {
        LOGGER.debug("nextToken is null");
    }
    boolean success = false;
    if (principal != null) {
        if (spnegoCredential.isNtlm()) {
            LOGGER.debug("NTLM Credential is valid for user [{}]", principal.getName());
        } else {
            LOGGER.debug("Kerberos Credential is valid for user [{}]", principal.getName());
        }
        spnegoCredential.setPrincipal(getPrincipal(principal.getName(), spnegoCredential.isNtlm()));
        success = true;
    }
    if (!success) {
        throw new FailedLoginException("Principal is null, the processing of the SPNEGO Token failed");
    }
    return new DefaultAuthenticationHandlerExecutionResult(this, new BasicCredentialMetaData(credential), spnegoCredential.getPrincipal());
}
Also used : SpnegoCredential(org.apereo.cas.support.spnego.authentication.principal.SpnegoCredential) FailedLoginException(javax.security.auth.login.FailedLoginException) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) Synchronized(lombok.Synchronized)

Example 3 with Synchronized

use of lombok.Synchronized in project pravega by pravega.

the class SegmentInputStreamImpl method read.

/**
 * @see SegmentInputStream#read()
 */
@Override
@Synchronized
public ByteBuffer read(long timeout) throws EndOfSegmentException, SegmentTruncatedException {
    log.trace("Read called at offset {}", offset);
    Exceptions.checkNotClosed(asyncInput.isClosed(), this);
    long originalOffset = offset;
    boolean success = false;
    try {
        ByteBuffer result = readEventData(timeout);
        success = true;
        return result;
    } finally {
        if (!success) {
            outstandingRequest = null;
            offset = originalOffset;
            buffer.clear();
        }
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Synchronized(lombok.Synchronized)

Example 4 with Synchronized

use of lombok.Synchronized in project pravega by pravega.

the class SegmentMonitorLeader method takeLeadership.

/**
 * This function is called when the current instance is made the leader. The leadership is relinquished when this
 * function exits.
 *
 * @param client        The curator client.
 * @throws Exception    On any error. This would result in leadership being relinquished.
 */
@Override
@Synchronized
public void takeLeadership(CuratorFramework client) throws Exception {
    log.info("Obtained leadership to monitor the Host to Segment Container Mapping");
    // Attempt a rebalance whenever leadership is obtained to ensure no host events are missed.
    hostsChange.release();
    // Start cluster monitor.
    pravegaServiceCluster = new ClusterZKImpl(client, ClusterType.HOST);
    // Add listener to track host changes on the monitored pravega cluster.
    pravegaServiceCluster.addListener((type, host) -> {
        switch(type) {
            case HOST_ADDED:
            case HOST_REMOVED:
                // We don't keep track of the hosts and we always query for the entire set from the cluster
                // when changes occur. This is to avoid any inconsistencies if we miss any notifications.
                log.info("Received event: {} for host: {}. Wake up leader for rebalancing", type, host);
                hostsChange.release();
                break;
            case ERROR:
                // This event should be due to ZK connection errors and would have been received by the monitor too,
                // hence not handling it explicitly here.
                log.info("Received error event when monitoring the pravega host cluster, ignoring...");
                break;
        }
    });
    // Keep looping here as long as possible to stay as the leader and exclusively monitor the pravega cluster.
    while (true) {
        try {
            if (suspended.get()) {
                log.info("Monitor is suspended, waiting for notification to resume");
                suspendMonitor.acquire();
                log.info("Resuming monitor");
            }
            hostsChange.acquire();
            log.info("Received rebalance event");
            // Wait here until rebalance can be performed.
            waitForRebalance();
            // Clear all events that has been received until this point since this will be included in the current
            // rebalance operation.
            hostsChange.drainPermits();
            triggerRebalance();
        } catch (InterruptedException e) {
            log.warn("Leadership interrupted, releasing monitor thread");
            // Stop watching the pravega cluster.
            pravegaServiceCluster.close();
            throw e;
        } catch (Exception e) {
            // We will not release leadership if in suspended mode.
            if (!suspended.get()) {
                log.warn("Failed to perform rebalancing, relinquishing leadership");
                // Stop watching the pravega cluster.
                pravegaServiceCluster.close();
                throw e;
            }
        }
    }
}
Also used : ClusterZKImpl(io.pravega.common.cluster.zkImpl.ClusterZKImpl) IOException(java.io.IOException) ClusterException(io.pravega.common.cluster.ClusterException) Synchronized(lombok.Synchronized)

Example 5 with Synchronized

use of lombok.Synchronized in project pravega by pravega.

the class MockController method deleteStream.

@Override
@Synchronized
public CompletableFuture<Boolean> deleteStream(String scope, String streamName) {
    Stream stream = new StreamImpl(scope, streamName);
    if (createdStreams.get(stream) == null) {
        return CompletableFuture.completedFuture(false);
    }
    for (Segment segment : getSegmentsForStream(stream)) {
        deleteSegment(segment.getScopedName(), new PravegaNodeUri(endpoint, port));
    }
    createdStreams.remove(stream);
    createdScopes.get(scope).remove(stream);
    return CompletableFuture.completedFuture(true);
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Stream(io.pravega.client.stream.Stream) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Segment(io.pravega.client.segment.impl.Segment) DeleteSegment(io.pravega.shared.protocol.netty.WireCommands.DeleteSegment) Synchronized(lombok.Synchronized)

Aggregations

Synchronized (lombok.Synchronized)22 IOException (java.io.IOException)6 Segment (io.pravega.client.segment.impl.Segment)4 ArrayList (java.util.ArrayList)4 S3Exception (com.emc.object.s3.S3Exception)3 CreateSegment (io.pravega.shared.protocol.netty.WireCommands.CreateSegment)3 DeleteSegment (io.pravega.shared.protocol.netty.WireCommands.DeleteSegment)3 ScheduledReporter (com.codahale.metrics.ScheduledReporter)2 Stream (io.pravega.client.stream.Stream)2 StreamImpl (io.pravega.client.stream.impl.StreamImpl)2 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 FileChannel (java.nio.channels.FileChannel)2 Path (java.nio.file.Path)2 SneakyThrows (lombok.SneakyThrows)2 PersistentNode (org.apache.curator.framework.recipes.nodes.PersistentNode)2 ChainingMetadataResolver (org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)2 JmxReporter (com.codahale.metrics.JmxReporter)1