Search in sources :

Example 11 with Security

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

the class CommandJobTest method testUnableToGetSystemSubject.

/**
 * Tests that there is no exception when unable to get the system's {@link Subject}. This might
 * happen when the system is very slow to start up where not all of the required security bundles
 * are started yet.
 */
@Test
public void testUnableToGetSystemSubject() {
    // given
    CommandJob commandJob = new CommandJob(new Security()) {

        @Override
        public Subject getSystemSubject() {
            return null;
        }
    };
    String command = VALID_COMMAND;
    // when
    commandJob.execute(createMockJobExecutionContext(command));
}
Also used : Security(org.codice.ddf.security.impl.Security) Test(org.junit.Test)

Example 12 with Security

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

the class FilterPluginTest method testPluginFilterResourceNoStrategiesBad.

@Test(expected = StopProcessingException.class)
public void testPluginFilterResourceNoStrategiesBad() throws StopProcessingException {
    plugin = new FilterPlugin(new Security());
    plugin.setPermissions(new PermissionsImpl());
    plugin.processPostResource(resourceResponse, getMoreRolesMetacard());
}
Also used : FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) Security(org.codice.ddf.security.impl.Security) Test(org.junit.Test)

Example 13 with Security

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

the class FilterPluginTest method setup.

@Before
public void setup() {
    AuthorizingRealm realm = mock(AuthorizingRealm.class);
    when(realm.getName()).thenReturn("mockRealm");
    when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
    Collection<org.apache.shiro.realm.Realm> realms = new ArrayList<>();
    realms.add(realm);
    DefaultSecurityManager manager = new DefaultSecurityManager();
    manager.setRealms(realms);
    SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() {

        @Override
        public String getName() {
            return "testuser";
        }
    }, realm.getName());
    Subject systemSubject = new MockSubject(manager, principalCollection);
    plugin = new FilterPlugin(new Security()) {

        @Override
        protected Subject getSystemSubject() {
            return systemSubject;
        }
    };
    plugin.setPermissions(new PermissionsImpl());
    plugin.setSubjectOperations(new SubjectUtils());
    plugin.setSecurityLogger(mock(SecurityLogger.class));
    QueryRequestImpl request = getSampleRequest();
    Map<String, Serializable> properties = new HashMap<>();
    Subject subject = new MockSubject(manager, principalCollection);
    properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
    request.setProperties(properties);
    incomingResponse = new QueryResponseImpl(request);
    ResourceRequest resourceRequest = mock(ResourceRequest.class);
    when(resourceRequest.getProperties()).thenReturn(properties);
    resourceResponse = new ResourceResponseImpl(resourceRequest, mock(Resource.class));
    resourceResponse.setProperties(properties);
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    when(deleteRequest.getProperties()).thenReturn(properties);
    List<Metacard> deletedMetacards = new ArrayList<>();
    deletedMetacards.add(getExactRolesMetacard());
    deleteResponse = new DeleteResponseImpl(deleteRequest, properties, deletedMetacards);
    List<Metacard> badDeletedMetacards = new ArrayList<>();
    badDeletedMetacards.add(getMoreRolesMetacard());
    badDeleteResponse = new DeleteResponseImpl(deleteRequest, properties, badDeletedMetacards);
    createRequest = new CreateRequestImpl(getExactRolesMetacard());
    createRequest.setProperties(properties);
    badCreateRequest = new CreateRequestImpl(getMoreRolesMetacard());
    badCreateRequest.setProperties(properties);
    updateRequest = new UpdateRequestImpl(getExactRolesMetacard().getId(), getExactRolesMetacard());
    updateRequest.setProperties(properties);
    ResultImpl result1 = new ResultImpl(getMoreRolesMetacard());
    ResultImpl result2 = new ResultImpl(getMissingRolesMetacard());
    ResultImpl result3 = new ResultImpl(getExactRolesMetacard());
    ResultImpl result4 = new ResultImpl(getNoRolesMetacard());
    ResultImpl result5 = new ResultImpl(getNoSecurityAttributeMetacard());
    incomingResponse.addResult(result1, false);
    incomingResponse.addResult(result2, false);
    incomingResponse.addResult(result3, false);
    incomingResponse.addResult(result4, false);
    incomingResponse.addResult(result5, true);
}
Also used : SubjectUtils(ddf.security.service.impl.SubjectUtils) Serializable(java.io.Serializable) FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResultImpl(ddf.catalog.data.impl.ResultImpl) Security(org.codice.ddf.security.impl.Security) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) CollectionPermission(ddf.security.permission.CollectionPermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) DelegatingSubject(org.apache.shiro.subject.support.DelegatingSubject) Subject(ddf.security.Subject) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Principal(java.security.Principal) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 14 with Security

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

the class IndexInitializerTest method setUp.

@Before
public void setUp() throws Exception {
    GeoEntryExtractor extractor = mock(GeoEntryExtractor.class);
    indexer = mock(GeoEntryIndexer.class);
    executor = mock(ExecutorService.class);
    indexInitializer = new IndexInitializer(new Security());
    indexInitializer.setExecutor(executor);
    indexInitializer.setExtractor(extractor);
    indexInitializer.setIndexer(indexer);
    File dataDir = tempDir.newFolder("data");
    geonamesZip = new File(dataDir, "default_geonames_data.zip");
    geoIndexDir = new File(dataDir, "geonames-index");
    indexInitializer.setDefaultGeoNamesDataPath(geonamesZip.getAbsolutePath());
}
Also used : GeoEntryIndexer(org.codice.ddf.spatial.geocoding.GeoEntryIndexer) ExecutorService(java.util.concurrent.ExecutorService) Security(org.codice.ddf.security.impl.Security) File(java.io.File) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) Before(org.junit.Before)

Example 15 with Security

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

the class CswSourceTest method getCswSource.

private AbstractCswSource getCswSource(Csw csw, BundleContext context, String contentMapping, String queryTypeQName, String queryTypePrefix, EncryptionService encryptionService, Permissions permissions) {
    CswSourceConfiguration cswSourceConfiguration = getStandardCswSourceConfiguration(contentMapping, queryTypeQName, queryTypePrefix, encryptionService, permissions);
    cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, contentMapping);
    SecureCxfClientFactory<Csw> mockFactory = mock(SecureCxfClientFactory.class);
    doReturn(csw).when(mockFactory).getClient();
    doReturn(csw).when(mockFactory).getClientForSubject(any(Subject.class));
    doReturn(csw).when(mockFactory).getClientForSystemSubject(any(Subject.class));
    ClientBuilderFactory clientBuilderFactory = mock(ClientBuilderFactory.class);
    ClientBuilder<Csw> clientBuilder = new ClientBuilderImpl<Csw>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory<Csw> build() {
            return mockFactory;
        }
    };
    when(clientBuilderFactory.<Csw>getClientBuilder()).thenReturn(clientBuilder);
    CswSourceStub cswSource = new CswSourceStub(mockContext, cswSourceConfiguration, mockProvider, clientBuilderFactory, encryptionService, new Security(), permissions);
    cswSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
    cswSource.setFilterBuilder(builder);
    cswSource.setContext(context);
    cswSource.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    cswSource.setAvailabilityTask(mockAvailabilityTask);
    cswSource.configureCswSource();
    return cswSource;
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) SecurityManager(ddf.security.service.SecurityManager) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) Security(org.codice.ddf.security.impl.Security) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) Subject(org.apache.shiro.subject.Subject) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SecurityLogger(ddf.security.audit.SecurityLogger)

Aggregations

Security (org.codice.ddf.security.impl.Security)18 Test (org.junit.Test)14 FilterPlugin (ddf.catalog.security.filter.plugin.FilterPlugin)5 PermissionsImpl (ddf.security.permission.impl.PermissionsImpl)4 SecurityLogger (ddf.security.audit.SecurityLogger)3 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)2 Subject (ddf.security.Subject)2 SubjectUtils (ddf.security.service.impl.SubjectUtils)2 Before (org.junit.Before)2 AttributeRegistry (ddf.catalog.data.AttributeRegistry)1 Metacard (ddf.catalog.data.Metacard)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 DeleteRequest (ddf.catalog.operation.DeleteRequest)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 ResourceRequest (ddf.catalog.operation.ResourceRequest)1 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)1 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)1