use of org.codice.ddf.security.common.Security in project ddf by codice.
the class TestApplicationService method beforeExam.
@BeforeExam
public void beforeExam() throws Exception {
try {
waitForSystemReady();
Security security = Security.getInstance();
systemSubject = security.runAsAdmin(security::getSystemSubject);
} catch (Exception e) {
LoggingUtils.failWithThrowableStacktrace(e, "Failed in @BeforeExam: ");
}
}
use of org.codice.ddf.security.common.Security in project ddf by codice.
the class RegistryMetacardHandler method processEvent.
private void processEvent(Metacard mcard, String topic) {
try {
Security security = Security.getInstance();
security.runAsAdminWithException(() -> {
if (topic.equals(EventProcessor.EVENTS_TOPIC_DELETED)) {
processMetacardDelete(mcard);
} else if (topic.equals(EventProcessor.EVENTS_TOPIC_CREATED) || topic.equals(EventProcessor.EVENTS_TOPIC_UPDATED)) {
processMetacardCreateUpdate(mcard);
}
return null;
});
} catch (PrivilegedActionException e) {
LOGGER.debug("Error processing registry metacard event.", e);
}
}
use of org.codice.ddf.security.common.Security in project ddf by codice.
the class RegistryStoreCleanupHandler method handleEvent.
@Override
public void handleEvent(Event event) {
Object eventProperty = event.getProperty(EventConstants.EVENT);
if (!cleanupRelatedMetacards || eventProperty == null || !(eventProperty instanceof ServiceEvent)) {
return;
}
if (((ServiceEvent) eventProperty).getType() != ServiceEvent.UNREGISTERING) {
return;
}
Object servicePid = ((ServiceEvent) event.getProperty(EventConstants.EVENT)).getServiceReference().getProperty(Constants.SERVICE_PID);
if (servicePid == null) {
return;
}
RegistryStore service = registryStorePidToServiceMap.get(servicePid);
if (service == null) {
return;
}
registryStorePidToServiceMap.remove(servicePid);
LOGGER.info("Removing registry entries associated with remote registry {}", service.getId());
executor.execute(() -> {
String registryId = service.getRegistryId();
try {
Security security = Security.getInstance();
List<Metacard> metacards = security.runAsAdminWithException(() -> federationAdminService.getInternalRegistryMetacards().stream().filter(m -> RegistryUtility.getStringAttribute(m, RegistryObjectMetacardType.REMOTE_REGISTRY_ID, "").equals(registryId)).collect(Collectors.toList()));
List<String> idsToDelete = metacards.stream().map(Metacard::getId).collect(Collectors.toList());
if (!idsToDelete.isEmpty()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Removing {} registry entries that came from {}. Removed entries: {}", metacards.size(), service.getId(), metacards.stream().map(m -> m.getTitle() + ":" + m.getId()).collect(Collectors.joining(", ")));
}
security.runAsAdminWithException(() -> {
federationAdminService.deleteRegistryEntriesByMetacardIds(idsToDelete);
return null;
});
}
} catch (PrivilegedActionException e) {
LOGGER.info("Unable to clean up registry metacards after registry store {} was deleted", service.getId(), e);
}
});
}
use of org.codice.ddf.security.common.Security in project ddf by codice.
the class GuestInterceptor method internalHandleMessage.
private void internalHandleMessage(SoapMessage message, SOAPMessage soapMessage) throws Fault {
//Check if security header exists; if not, execute GuestInterceptor logic
String actor = (String) getOption(WSHandlerConstants.ACTOR);
if (actor == null) {
actor = (String) message.getContextualProperty(SecurityConstants.ACTOR);
}
Element existingSecurityHeader = null;
try {
LOGGER.debug("Checking for security header.");
existingSecurityHeader = WSSecurityUtil.getSecurityHeader(soapMessage.getSOAPPart(), actor);
} catch (WSSecurityException e1) {
LOGGER.debug("Issue with getting security header", e1);
}
if (existingSecurityHeader != null) {
LOGGER.debug("SOAP message contains security header, no action taken by the GuestInterceptor.");
return;
}
LOGGER.debug("Current request has no security header, continuing with GuestInterceptor");
AssertionInfoMap assertionInfoMap = message.get(AssertionInfoMap.class);
boolean hasAddressingAssertion = assertionInfoMap.entrySet().stream().flatMap(p -> p.getValue().stream()).filter(info -> MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(info.getAssertion().getName())).findFirst().isPresent();
if (hasAddressingAssertion) {
createAddressing(message, soapMessage);
}
LOGGER.debug("Creating guest security token.");
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
SecurityToken securityToken = createSecurityToken(request.getRemoteAddr());
message.put(SecurityConstants.TOKEN, securityToken);
if (!MessageUtils.isRequestor(message)) {
try {
message.put(Message.REQUESTOR_ROLE, true);
policyBasedWss4jOutInterceptor.handleMessage(message);
} finally {
message.remove(Message.REQUESTOR_ROLE);
}
} else {
policyBasedWss4jOutInterceptor.handleMessage(message);
}
}
use of org.codice.ddf.security.common.Security in project ddf by codice.
the class IdentityNodeInitialization method init.
public void init() {
try {
Security security = Security.getInstance();
security.runAsAdminWithException(() -> {
Optional<Metacard> optional = federationAdminService.getLocalRegistryIdentityMetacard();
if (optional.isPresent()) {
Metacard metacard = optional.get();
System.setProperty(RegistryConstants.REGISTRY_ID_PROPERTY, RegistryUtility.getRegistryId(metacard));
if (!metacard.getTitle().equals(SystemInfo.getSiteName())) {
updateIdentityNodeName(metacard);
}
}
if (!optional.isPresent()) {
createIdentityNode();
}
return null;
});
} catch (PrivilegedActionException e) {
LOGGER.debug("Error checking for local registry identity node. Will try again later");
executorService.schedule(this::init, RETRY_INTERVAL, TimeUnit.SECONDS);
}
}
Aggregations