Search in sources :

Example 1 with PermissionsImpl

use of ddf.security.permission.impl.PermissionsImpl in project ddf by codice.

the class MetacardValidityFilterPluginTest method setUp.

@Before
public void setUp() {
    filterAdapter = new GeotoolsFilterAdapterImpl();
    filterBuilder = new GeotoolsFilterBuilder();
    errorsValidationQueryDelegate = new ValidationQueryDelegate(Validation.VALIDATION_ERRORS);
    warningsValidationQueryDelegate = new ValidationQueryDelegate(Validation.VALIDATION_WARNINGS);
    metacardValidityFilterPlugin = new MetacardValidityFilterPlugin(filterBuilder, Collections.singletonList(LOCAL_PROVIDER));
    metacardValidityFilterPlugin.setPermissions(new PermissionsImpl());
    metacardValidityFilterPlugin.setAttributeMap(ATTRIBUTE_MAPPING);
}
Also used : PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Before(org.junit.Before)

Example 2 with PermissionsImpl

use of ddf.security.permission.impl.PermissionsImpl in project ddf by codice.

the class AdminConfigPolicyTest method testInvalidPolicyConfigs.

@Test
public void testInvalidPolicyConfigs() {
    AdminConfigPolicy adminConfigPolicy = new AdminConfigPolicy();
    adminConfigPolicy.setPermissions(new PermissionsImpl());
    adminConfigPolicy.setFeaturePolicies(getValidPolicyPermissions());
    for (int i = 0; i < 3; i++) {
        List<KeyValueCollectionPermission> featurePolicyPermissions = adminConfigPolicy.featurePolicyPermissions.get(TEST_PERMISSION_VALUE + i);
        assertNotNull(featurePolicyPermissions);
        assertEquals(featurePolicyPermissions.size(), 1);
        KeyValuePermission featurePolicyPermission = (KeyValuePermission) featurePolicyPermissions.get(0).getPermissionList().get(0);
        assertEquals(featurePolicyPermission.getKey(), TEST_ATTRIBUTE_NAME + i);
        assertEquals(featurePolicyPermission.getValues(), Sets.newHashSet(TEST_ATTRIBUTE_VALUE + i));
    }
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) KeyValuePermission(ddf.security.permission.KeyValuePermission) Test(org.junit.Test)

Example 3 with PermissionsImpl

use of ddf.security.permission.impl.PermissionsImpl in project ddf by codice.

the class AdminConfigPolicyTest method testRemoveSomePermissions.

@Test
public void testRemoveSomePermissions() {
    AdminConfigPolicy adminConfigPolicy = new AdminConfigPolicy();
    adminConfigPolicy.setPermissions(new PermissionsImpl());
    List<String> featurePolicyPermissions = getValidPolicyPermissions();
    List<String> servicePolicyPermissions = getValidPolicyPermissions();
    featurePolicyPermissions.add(TEST_PERMISSION_VALUE + UNAUTHORIZED + "=\"" + TEST_ATTRIBUTE_NAME + UNAUTHORIZED + "=" + TEST_ATTRIBUTE_VALUE + UNAUTHORIZED + "\"");
    servicePolicyPermissions.add(TEST_PERMISSION_VALUE + UNAUTHORIZED + "=\"" + TEST_ATTRIBUTE_NAME + UNAUTHORIZED + "=" + TEST_ATTRIBUTE_VALUE + UNAUTHORIZED + "\"");
    adminConfigPolicy.setFeaturePolicies(featurePolicyPermissions);
    adminConfigPolicy.setServicePolicies(servicePolicyPermissions);
    List<KeyValuePermission> matchOneFeaturePermissions = getMatchOnePermissions(AdminConfigPolicy.FEATURE_NAME);
    matchOneFeaturePermissions.add(new KeyValuePermissionImpl(AdminConfigPolicy.FEATURE_NAME, Sets.newHashSet(TEST_PERMISSION_VALUE + UNAUTHORIZED)));
    List<KeyValuePermission> matchOneServicePermissions = getMatchOnePermissions(AdminConfigPolicy.SERVICE_PID);
    matchOneServicePermissions.add(new KeyValuePermissionImpl(AdminConfigPolicy.SERVICE_PID, Sets.newHashSet(TEST_PERMISSION_VALUE + UNAUTHORIZED)));
    List<KeyValuePermission> matchOneInvalidActionPermission = new ArrayList<>();
    matchOneInvalidActionPermission.add(new KeyValuePermissionImpl("UNKNOWN_ACTION", Sets.newHashSet(TEST_PERMISSION_VALUE)));
    KeyValueCollectionPermission requestedFeaturePermissions = new KeyValueCollectionPermissionImpl(AdminConfigPolicy.VIEW_FEATURE_ACTION, matchOneFeaturePermissions.stream().toArray(KeyValuePermissionImpl[]::new));
    KeyValueCollectionPermission requestedServicePermissions = new KeyValueCollectionPermissionImpl(AdminConfigPolicy.VIEW_SERVICE_ACTION, matchOneServicePermissions.stream().toArray(KeyValuePermissionImpl[]::new));
    KeyValueCollectionPermission requestedInvalidActionPermissions = new KeyValueCollectionPermissionImpl("UNKNOWN_ACTION", matchOneInvalidActionPermission.stream().toArray(KeyValuePermissionImpl[]::new));
    assertEquals(1, adminConfigPolicy.isPermittedMatchOne(getSubjectPermissions(), requestedFeaturePermissions, requestedFeaturePermissions).getPermissionList().size());
    assertEquals(1, adminConfigPolicy.isPermittedMatchOne(getSubjectPermissions(), requestedServicePermissions, requestedServicePermissions).getPermissionList().size());
    assertEquals(1, adminConfigPolicy.isPermittedMatchOne(getSubjectPermissions(), requestedServicePermissions, requestedServicePermissions).getPermissionList().size());
    assertEquals(1, adminConfigPolicy.isPermittedMatchOne(getSubjectPermissions(), requestedInvalidActionPermissions, requestedInvalidActionPermissions).getPermissionList().size());
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) KeyValuePermissionImpl(ddf.security.permission.impl.KeyValuePermissionImpl) ArrayList(java.util.ArrayList) KeyValueCollectionPermissionImpl(ddf.security.permission.impl.KeyValueCollectionPermissionImpl) KeyValuePermission(ddf.security.permission.KeyValuePermission) Test(org.junit.Test)

Example 4 with PermissionsImpl

use of ddf.security.permission.impl.PermissionsImpl in project ddf by codice.

the class CswQueryFactoryTest method setUp.

@org.junit.Before
public void setUp() throws URISyntaxException, SourceUnavailableException, UnsupportedQueryException, FederationException, ParseException, IngestException {
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    FilterAdapter filterAdapter = new GeotoolsFilterAdapterImpl();
    CswRecordMap cswRecordMap = new MetacardCswRecordMap();
    queryFactory = new CswQueryFactory(cswRecordMap, filterBuilder, filterAdapter, new PermissionsImpl());
    AttributeRegistryImpl attributeRegistry = new AttributeRegistryImpl();
    attributeRegistry.registerMetacardType(getCswMetacardType());
    queryFactory.setAttributeRegistry(attributeRegistry);
    polygon = new WKTReader().read(POLYGON_STR);
    gmlObjectFactory = new net.opengis.gml.v_3_1_1.ObjectFactory();
    filterObjectFactory = new ObjectFactory();
    queryFilterTransformerProvider = mock(QueryFilterTransformerProvider.class);
    QueryFilterTransformer cswQueryFilter = new CswQueryFilterTransformer(new MetacardCswRecordMap(), attributeRegistry);
    when(queryFilterTransformerProvider.getTransformer(new QName(CswConstants.CSW_OUTPUT_SCHEMA, "Record"))).thenReturn(Optional.of(cswQueryFilter));
    when(queryFilterTransformerProvider.getTransformer(anyString())).thenReturn(Optional.of(cswQueryFilter));
    queryFactory.setQueryFilterTransformerProvider(queryFilterTransformerProvider);
}
Also used : AttributeRegistryImpl(ddf.catalog.data.impl.AttributeRegistryImpl) QueryFilterTransformerProvider(ddf.catalog.transform.QueryFilterTransformerProvider) QName(javax.xml.namespace.QName) FilterAdapter(ddf.catalog.filter.FilterAdapter) CswQueryFilterTransformer(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswQueryFilterTransformer) CswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswRecordMap) MetacardCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.MetacardCswRecordMap) WKTReader(org.locationtech.jts.io.WKTReader) ObjectFactory(net.opengis.filter.v_1_1_0.ObjectFactory) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) MetacardCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.MetacardCswRecordMap) QueryFilterTransformer(ddf.catalog.transform.QueryFilterTransformer) CswQueryFilterTransformer(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswQueryFilterTransformer)

Example 5 with PermissionsImpl

use of ddf.security.permission.impl.PermissionsImpl in project ddf by codice.

the class OperationPluginTest method setup.

@Before
public void setup() {
    plugin = new OperationPlugin();
    plugin.setPermissions(new PermissionsImpl());
    AuthorizingRealm realm = mock(AuthorizingRealm.class);
    when(realm.getName()).thenReturn("mockRealm");
    when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
    Collection<Realm> realms = new ArrayList<Realm>();
    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 = new MockSubject(manager, principalCollection);
}
Also used : ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) 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) Realm(org.apache.shiro.realm.Realm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) Principal(java.security.Principal) Before(org.junit.Before)

Aggregations

PermissionsImpl (ddf.security.permission.impl.PermissionsImpl)17 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)7 SecurityLogger (ddf.security.audit.SecurityLogger)6 Before (org.junit.Before)5 FilterPlugin (ddf.catalog.security.filter.plugin.FilterPlugin)4 ByteSource (com.google.common.io.ByteSource)3 Metacard (ddf.catalog.data.Metacard)3 QueryOperations (ddf.catalog.impl.operations.QueryOperations)3 ResourceOperations (ddf.catalog.impl.operations.ResourceOperations)3 SourceOperations (ddf.catalog.impl.operations.SourceOperations)3 ResourceRequest (ddf.catalog.operation.ResourceRequest)3 FederatedSource (ddf.catalog.source.FederatedSource)3 Source (ddf.catalog.source.Source)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 SourceStatus (org.codice.ddf.catalog.sourcepoller.SourceStatus)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3