use of ddf.security.permission.impl.PermissionsImpl in project ddf by codice.
the class OperationPluginTest method makeDecision.
private Answer<Boolean> makeDecision() {
Map<String, List<String>> testRoleMap = new HashMap<String, List<String>>();
List<String> testRoles = new ArrayList<String>();
testRoles.add("A");
testRoles.add("B");
testRoleMap.put("Roles", testRoles);
final KeyValueCollectionPermission testUserPermission = new PermissionsImpl().buildKeyValueCollectionPermission(CollectionPermission.READ_ACTION, testRoleMap);
return new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
Permission incomingPermission = (Permission) args[1];
return testUserPermission.implies(incomingPermission);
}
};
}
use of ddf.security.permission.impl.PermissionsImpl 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());
}
use of ddf.security.permission.impl.PermissionsImpl 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);
}
use of ddf.security.permission.impl.PermissionsImpl in project ddf by codice.
the class ConfluenceSourceTest method setup.
@Before
public void setup() {
MetacardType type = new MetacardTypeImpl("confluence", MetacardImpl.BASIC_METACARD.getAttributeDescriptors());
transformer = new ConfluenceInputTransformer(type, Collections.emptyList());
encryptionService = mock(EncryptionService.class);
reader = mock(ResourceReader.class);
factory = mock(SecureCxfClientFactory.class);
clientBuilderFactory = mock(ClientBuilderFactory.class);
client = mock(SearchResource.class);
registry = mock(AttributeRegistry.class);
clientResponse = mock(Response.class);
when(factory.getClient()).thenReturn(client);
doReturn(clientResponse).when(client).search(anyString(), isNull(), isNull(), anyString(), anyInt(), anyInt(), anyBoolean());
when(encryptionService.decryptValue(anyString())).thenReturn("decryptedPass");
when(registry.lookup("attrib1")).thenReturn(Optional.of(new AttributeDescriptorImpl("attrib1", true, true, true, false, BasicTypes.STRING_TYPE)));
when(registry.lookup("attrib2")).thenReturn(Optional.of(new AttributeDescriptorImpl("attrib2", true, true, true, true, BasicTypes.STRING_TYPE)));
confluence = new TestConfluenceSource(adapter, encryptionService, transformer, reader, registry, factory, clientBuilderFactory);
confluence.setSecurityLogger(mock(SecurityLogger.class));
confluence.setPermissions(new PermissionsImpl());
confluence.setAvailabilityPollInterval(1);
confluence.setConfigurationPid("configPid");
confluence.setEndpointUrl("https://confluence/rest/api/content");
confluence.setExpandedSections(Collections.singletonList("expandedField"));
confluence.setUsername("username");
confluence.setPassword("password");
confluence.setIncludeArchivedSpaces(false);
List<String> additionalAttributes = new ArrayList<>();
additionalAttributes.add("attrib1=val1");
additionalAttributes.add("attrib2=val1,val2,val3");
confluence.setAttributeOverrides(additionalAttributes);
}
use of ddf.security.permission.impl.PermissionsImpl in project ddf by codice.
the class CatalogFrameworkImplTest method createFramework.
private CatalogFrameworkImpl createFramework(FrameworkProperties frameworkProperties) {
final SourcePoller<SourceStatus> mockStatusSourcePoller = mock(SourcePoller.class);
doAnswer(invocationOnMock -> Optional.of(((Source) invocationOnMock.getArguments()[0]).isAvailable() ? SourceStatus.AVAILABLE : SourceStatus.UNAVAILABLE)).when(mockStatusSourcePoller).getCachedValueForSource(any(Source.class));
final SourcePoller<Set<ContentType>> mockContentTypesSourcePoller = mock(SourcePoller.class);
doAnswer(invocationOnMock -> Optional.of(((Source) invocationOnMock.getArguments()[0]).getContentTypes())).when(mockContentTypesSourcePoller).getCachedValueForSource(any(Source.class));
OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
SourceOperations sourceOperations = new SourceOperations(frameworkProperties, mock(ActionRegistry.class), mockStatusSourcePoller, mockContentTypesSourcePoller);
QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
queryOperations.setSecurityLogger(mock(SecurityLogger.class));
queryOperations.setPermissions(new PermissionsImpl());
OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
CreateOperations createOperations = new CreateOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
UpdateOperations updateOperations = new UpdateOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
DeleteOperations deleteOperations = new DeleteOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacard);
ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
TransformOperations transformOperations = new TransformOperations(frameworkProperties);
Historian historian = new Historian();
historian.setHistoryEnabled(false);
updateOperations.setHistorian(historian);
deleteOperations.setHistorian(historian);
CatalogFrameworkImpl catalogFramework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, resourceOperations, sourceOperations, transformOperations);
// Conditionally bind objects if framework properties are setup
if (CollectionUtils.isNotEmpty(frameworkProperties.getCatalogProviders())) {
sourceOperations.bind(provider);
}
if (CollectionUtils.isNotEmpty(frameworkProperties.getStorageProviders())) {
sourceOperations.bind(storageProvider);
}
return catalogFramework;
}
Aggregations