Search in sources :

Example 6 with Security

use of org.codice.ddf.security.common.Security in project alliance by codice.

the class UdpStreamProcessor method shutdown.

/**
 * Shutdown the stream processor. Attempts to flush and ingest any partial stream data regardless
 * of IDR boundaries.
 */
public void shutdown() {
    LOGGER.trace("Shutting down stream processor.");
    packetBuffer.cancelTimer();
    Security security = Security.getInstance();
    security.runAsAdmin(() -> {
        if (streamCreationSubject == null) {
            streamCreationSubject = security.getSystemSubject();
        }
        streamCreationSubject.execute(() -> {
            try {
                streamShutdownPlugin.onShutdown(context);
            } catch (StreamShutdownException e) {
                LOGGER.debug("unable to run stream shutdown plugin", e);
            }
            return null;
        });
        return null;
    });
}
Also used : StreamShutdownException(org.codice.alliance.video.stream.mpegts.plugins.StreamShutdownException) Security(org.codice.ddf.security.common.Security)

Example 7 with Security

use of org.codice.ddf.security.common.Security in project alliance by codice.

the class UdpStreamProcessor method init.

/**
 * Initializes the processor. Users should call {@link #isReady()} first to make sure the
 * processor is ready to run.
 */
public void init() {
    Security security = Security.getInstance();
    security.runAsAdmin(() -> {
        if (streamCreationSubject == null) {
            streamCreationSubject = security.getSystemSubject();
        }
        streamCreationSubject.execute(() -> {
            try {
                streamCreationPlugin.onCreate(context);
            } catch (StreamCreationException e) {
                LOGGER.debug("unable to run stream creation plugin", e);
            }
            return null;
        });
        return null;
    });
}
Also used : StreamCreationException(org.codice.alliance.video.stream.mpegts.plugins.StreamCreationException) Security(org.codice.ddf.security.common.Security)

Example 8 with Security

use of org.codice.ddf.security.common.Security in project ddf by codice.

the class RegistryStorePublisher method registryPublish.

void registryPublish(RegistryStore registryStore, String publish) {
    if (registryStore.getRegistryId().isEmpty()) {
        LOGGER.info(String.format("RegistryStore missing id. Unable to complete %s request.", publish));
        return;
    }
    executor.schedule(() -> {
        try {
            Security security = Security.getInstance();
            Optional<Metacard> registryIdentityMetacardOpt = security.runAsAdminWithException(() -> federationAdminService.getLocalRegistryIdentityMetacard());
            if (registryIdentityMetacardOpt.isPresent()) {
                Metacard registryIdentityMetacard = registryIdentityMetacardOpt.get();
                String localRegistryId = RegistryUtility.getRegistryId(registryIdentityMetacard);
                if (localRegistryId == null) {
                    throw new EventException();
                }
                security.runAsAdminWithException(() -> {
                    if (publish.equals(PUBLISH)) {
                        registryPublicationService.publish(localRegistryId, registryStore.getRegistryId());
                    } else {
                        registryPublicationService.unpublish(localRegistryId, registryStore.getRegistryId());
                    }
                    return null;
                });
            }
        } catch (Exception e) {
            LOGGER.debug("Failed to {} registry configuration to {}", publish, ((RegistryStoreImpl) registryStore).getId());
        }
    }, 3, TimeUnit.SECONDS);
}
Also used : Metacard(ddf.catalog.data.Metacard) EventException(ddf.catalog.event.EventException) Security(org.codice.ddf.security.common.Security) EventException(ddf.catalog.event.EventException)

Example 9 with Security

use of org.codice.ddf.security.common.Security in project ddf by codice.

the class ProfileInstallCommandTest method createSecurityMock.

private Security createSecurityMock() {
    Subject subject = mock(Subject.class);
    when(subject.execute(Matchers.<Callable<Object>>any())).thenAnswer(invocation -> {
        Callable<Object> callable = (Callable<Object>) invocation.getArguments()[0];
        return callable.call();
    });
    security = mock(Security.class);
    when(security.getSystemSubject()).thenReturn(subject);
    return security;
}
Also used : Security(org.codice.ddf.security.common.Security) Subject(ddf.security.Subject) Callable(java.util.concurrent.Callable)

Example 10 with Security

use of org.codice.ddf.security.common.Security in project ddf by codice.

the class RegistryPublicationHandler method processUpdate.

private void processUpdate(Metacard mcard) {
    if (RegistryUtility.getListOfStringAttribute(mcard, RegistryObjectMetacardType.PUBLISHED_LOCATIONS).isEmpty()) {
        return;
    }
    Attribute lastPublished = mcard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED);
    Date datePublished = null;
    if (lastPublished != null) {
        datePublished = (Date) lastPublished.getValue();
    }
    //since the last time we published send an update to the remote location
    if ((datePublished == null || datePublished.before(mcard.getModifiedDate()))) {
        try {
            Security security = Security.getInstance();
            security.runAsAdminWithException(() -> {
                registryPublicationService.update(mcard);
                return null;
            });
        } catch (PrivilegedActionException e) {
            LOGGER.warn("Unable to send update for {}. Try unpublishing and republishing {}", mcard.getTitle(), mcard.getTitle());
        }
    }
}
Also used : Attribute(ddf.catalog.data.Attribute) PrivilegedActionException(java.security.PrivilegedActionException) Security(org.codice.ddf.security.common.Security) Date(java.util.Date)

Aggregations

Security (org.codice.ddf.security.common.Security)12 Metacard (ddf.catalog.data.Metacard)5 Subject (ddf.security.Subject)4 PrivilegedActionException (java.security.PrivilegedActionException)4 CatalogFramework (ddf.catalog.CatalogFramework)2 MetacardType (ddf.catalog.data.MetacardType)2 CreateRequest (ddf.catalog.operation.CreateRequest)2 CreateResponse (ddf.catalog.operation.CreateResponse)2 Context (org.codice.alliance.video.stream.mpegts.Context)2 UdpStreamProcessor (org.codice.alliance.video.stream.mpegts.netty.UdpStreamProcessor)2 Before (org.junit.Before)2 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 Attribute (ddf.catalog.data.Attribute)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 EventException (ddf.catalog.event.EventException)1 Update (ddf.catalog.operation.Update)1 UpdateResponse (ddf.catalog.operation.UpdateResponse)1