use of ddf.security.Subject in project ddf by codice.
the class FederationAdminServiceImplTest method testAddRegistryEntryStringWithDestinations.
@Test
public void testAddRegistryEntryStringWithDestinations() throws Exception {
Metacard metacard = testMetacard;
Metacard createdMetacard = testMetacard;
Set<String> destinations = new HashSet<>();
destinations.add(TEST_DESTINATION);
Subject systemSubject = security.getSystemSubject();
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);
CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard), properties, destinations);
CreateResponse response = new CreateResponseImpl(request, null, Collections.singletonList(createdMetacard));
when(registryTransformer.transform(any(InputStream.class))).thenReturn(metacard);
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);
String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(TEST_XML_STRING, destinations);
assertThat(createdMetacardId, is(equalTo(RegistryObjectMetacardType.REGISTRY_ID)));
verify(registryTransformer).transform(any(InputStream.class));
verify(catalogFramework).create(any(CreateRequest.class));
}
use of ddf.security.Subject in project ddf by codice.
the class FederationAdminServiceImplTest method testAddRegistryEntry.
@Test
public void testAddRegistryEntry() throws Exception {
String destination = TEST_DESTINATION;
Metacard metacard = testMetacard;
Metacard createdMetacard = testMetacard;
Set<String> destinations = new HashSet<>();
destinations.add(destination);
Subject systemSubject = security.getSystemSubject();
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);
CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard), properties, destinations);
CreateResponse response = new CreateResponseImpl(request, null, Collections.singletonList(createdMetacard));
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);
String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(metacard, destinations);
assertThat(createdMetacardId, is(equalTo(RegistryObjectMetacardType.REGISTRY_ID)));
verify(catalogFramework).create(any(CreateRequest.class));
}
use of ddf.security.Subject in project ddf by codice.
the class FederationAdminServiceImplTest method testAddRegistryEntryWithNullDestinations.
@Test
public void testAddRegistryEntryWithNullDestinations() throws Exception {
String registryId = RegistryObjectMetacardType.REGISTRY_ID;
Metacard metacard = testMetacard;
Metacard createdMetacard = testMetacard;
Set<String> destinations = null;
Subject systemSubject = security.getSystemSubject();
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);
CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard), properties, destinations);
CreateResponse response = new CreateResponseImpl(request, null, Collections.singletonList(createdMetacard));
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);
String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(metacard, destinations);
assertThat(createdMetacardId, is(equalTo(registryId)));
verify(catalogFramework).create(any(CreateRequest.class));
}
use of ddf.security.Subject in project ddf by codice.
the class ApplicationConfigInstallerTest method getApplicationConfigInstaller.
ApplicationConfigInstaller getApplicationConfigInstaller(String fileName, ApplicationService appService, FeaturesService featuresService, String postInstallFeatureStart, String postInstallFeatureStop) {
return new ApplicationConfigInstaller(fileName, appService, featuresService, postInstallFeatureStart, postInstallFeatureStop) {
@SuppressWarnings("unchecked")
@Override
public Subject getSystemSubject() {
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();
});
return subject;
}
};
}
use of ddf.security.Subject in project ddf by codice.
the class SendEvent method send.
private boolean send(String operation, CswRecordCollection recordCollection) {
WebClient webClient = cxfClientFactory.getWebClient();
try {
Response response = webClient.invoke(operation, recordCollection);
Subject pingSubject = (Subject) response.getHeaders().getFirst(Subject.class.toString());
if (pingSubject == null && ip != null) {
subject = security.getGuestSubject(ip);
} else {
subject = pingSubject;
}
lastPing = System.currentTimeMillis();
retryCount.set(0);
return true;
} catch (Exception e) {
LOGGER.debug("Error contacting event callback url {}", callbackUrl, e);
lastPing = System.currentTimeMillis();
retryCount.incrementAndGet();
}
return false;
}
Aggregations