use of ddf.security.SubjectIdentity in project ddf by codice.
the class HistorianTest method setup.
@Before
public void setup() {
historian = new Historian();
uuidGenerator = mock(UuidGenerator.class);
when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
historian.setUuidGenerator(uuidGenerator);
catalogProvider = mock(CatalogProvider.class);
historian.setCatalogProviders(Collections.singletonList(catalogProvider));
storageProvider = new InMemoryStorageProvider();
historian.setStorageProviders(Collections.singletonList(storageProvider));
historian.setMetacardTypes(Collections.singletonList(MetacardImpl.BASIC_METACARD));
SubjectIdentity subjectIdentity = mock(SubjectIdentity.class);
when(subjectIdentity.getUniqueIdentifier(any())).thenReturn("test");
historian.setSubjectIdentity(subjectIdentity);
SubjectOperations subjectOperations = mock(SubjectOperations.class);
when(subjectOperations.getEmailAddress(any(Subject.class))).thenReturn("test@test.com");
when(subjectOperations.getName(any(Subject.class))).thenReturn("test");
historian.setSubjectOperations(subjectOperations);
historian.setSecurityLogger(mock(SecurityLogger.class));
Security security = mock(Security.class);
Subject subject = mock(MockSubject.class);
when(subject.execute(any(Callable.class))).thenCallRealMethod();
when(security.runAsAdmin(any(PrivilegedAction.class))).thenReturn(subject);
historian.setSecurity(security);
}
use of ddf.security.SubjectIdentity in project ddf by codice.
the class SecurityPluginTest method testNominalCaseCreateWithoutId.
@Test
public void testNominalCaseCreateWithoutId() throws Exception {
Subject mockSubject = mock(Subject.class);
ThreadContext.bind(mockSubject);
CreateRequest request = new MockCreateRequest();
SubjectIdentity noId = mock(SubjectIdentity.class);
when(noId.getUniqueIdentifier(any())).thenReturn(null);
SecurityPlugin plugin = new SecurityPlugin(noId);
request = plugin.processPreCreate(request);
assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
assertThat(request.getMetacards().size(), is(2));
request.getMetacards().forEach(metacard -> assertThat(metacard.getAttribute(Metacard.POINT_OF_CONTACT), is(nullValue())));
}
Aggregations