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;
});
}
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;
});
}
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);
}
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;
}
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());
}
}
}
Aggregations