Search in sources :

Example 51 with Subject

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));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) Subject(ddf.security.Subject) Metacard(ddf.catalog.data.Metacard) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) HashSet(java.util.HashSet) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 52 with Subject

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Subject(ddf.security.Subject) HashSet(java.util.HashSet) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 53 with Subject

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Subject(ddf.security.Subject) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 54 with Subject

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;
        }
    };
}
Also used : Subject(ddf.security.Subject) Callable(java.util.concurrent.Callable)

Example 55 with 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;
}
Also used : QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) WebClient(org.apache.cxf.jaxrs.client.WebClient) Subject(ddf.security.Subject) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) MalformedURLException(java.net.MalformedURLException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) UnknownHostException(java.net.UnknownHostException)

Aggregations

Subject (ddf.security.Subject)94 Test (org.junit.Test)47 SecurityAssertion (ddf.security.assertion.SecurityAssertion)23 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)23 HashMap (java.util.HashMap)20 Metacard (ddf.catalog.data.Metacard)18 SecurityManager (ddf.security.service.SecurityManager)14 IOException (java.io.IOException)14 Serializable (java.io.Serializable)14 CollectionPermission (ddf.security.permission.CollectionPermission)13 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 CreateRequest (ddf.catalog.operation.CreateRequest)11 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)11 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)10 SecurityServiceException (ddf.security.service.SecurityServiceException)10 HashSet (java.util.HashSet)10 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)9 Before (org.junit.Before)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8