Search in sources :

Example 1 with SubjectIdentity

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);
}
Also used : SubjectOperations(ddf.security.SubjectOperations) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) CatalogProvider(ddf.catalog.source.CatalogProvider) PrivilegedAction(java.security.PrivilegedAction) SubjectIdentity(ddf.security.SubjectIdentity) Security(org.codice.ddf.security.Security) Subject(ddf.security.Subject) Callable(java.util.concurrent.Callable) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 2 with SubjectIdentity

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())));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) SubjectIdentity(ddf.security.SubjectIdentity) Subject(ddf.security.Subject) Test(org.junit.Test)

Aggregations

Subject (ddf.security.Subject)2 SubjectIdentity (ddf.security.SubjectIdentity)2 CreateRequest (ddf.catalog.operation.CreateRequest)1 CatalogProvider (ddf.catalog.source.CatalogProvider)1 SubjectOperations (ddf.security.SubjectOperations)1 SecurityLogger (ddf.security.audit.SecurityLogger)1 PrivilegedAction (java.security.PrivilegedAction)1 Callable (java.util.concurrent.Callable)1 UuidGenerator (org.codice.ddf.platform.util.uuidgenerator.UuidGenerator)1 Security (org.codice.ddf.security.Security)1 Before (org.junit.Before)1 Test (org.junit.Test)1