Search in sources :

Example 11 with Subject

use of ddf.security.Subject in project ddf by codice.

the class SecurityPluginTest method testSubjectExists.

@Test
public void testSubjectExists() throws Exception {
    Subject mockSubject = mock(Subject.class);
    CreateRequest request = new MockCreateRequest();
    request.getProperties().put(SecurityConstants.SECURITY_SUBJECT, mockSubject);
    SecurityPlugin plugin = new SecurityPlugin();
    request = plugin.processPreCreate(request);
    assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 12 with Subject

use of ddf.security.Subject in project ddf by codice.

the class SecurityPluginTest method testNominalCaseResource.

@Test
public void testNominalCaseResource() throws Exception {
    Subject mockSubject = mock(Subject.class);
    ThreadContext.bind(mockSubject);
    ResourceRequest request = new MockResourceRequest();
    SecurityPlugin plugin = new SecurityPlugin();
    request = plugin.processPreResource(request);
    assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
}
Also used : ResourceRequest(ddf.catalog.operation.ResourceRequest) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 13 with Subject

use of ddf.security.Subject in project ddf by codice.

the class SecurityPluginTest method testNominalCaseCreateWithEmailAndResourceTag.

@Test
public void testNominalCaseCreateWithEmailAndResourceTag() throws Exception {
    Subject mockSubject = setupMockSubject();
    ThreadContext.bind(mockSubject);
    MetacardImpl metacardWithTags = new MetacardImpl();
    Set<String> setOfTags = new HashSet<String>();
    setOfTags.add("resource");
    metacardWithTags.setTags(setOfTags);
    CreateRequest request = new CreateRequestImpl(metacardWithTags);
    SecurityPlugin plugin = new SecurityPlugin();
    request = plugin.processPreCreate(request);
    assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
    assertThat(request.getMetacards().size(), is(1));
    assertThat(request.getMetacards().get(0).getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(TEST_USER));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) XSString(org.opensaml.core.xml.schema.XSString) Subject(ddf.security.Subject) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with Subject

use of ddf.security.Subject in project ddf by codice.

the class SecurityPluginTest method testNominalCaseDelete.

@Test
public void testNominalCaseDelete() throws Exception {
    Subject mockSubject = mock(Subject.class);
    ThreadContext.bind(mockSubject);
    DeleteRequest request = new MockDeleteRequest();
    SecurityPlugin plugin = new SecurityPlugin();
    request = plugin.processPreDelete(request);
    request = plugin.processPreDelete(request);
    assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
}
Also used : DeleteRequest(ddf.catalog.operation.DeleteRequest) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 15 with Subject

use of ddf.security.Subject in project ddf by codice.

the class FtpRequestHandler method onRenameStart.

@Override
public FtpletResult onRenameStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
    FtpFile fromFtpFile = session.getRenameFrom();
    String toFilename = request.getArgument();
    if (isDotFile(fromFtpFile.getName())) {
        Optional<TemporaryFileBackedOutputStream> tfbosOpt = findTempFileInSession(session, fromFtpFile.getAbsolutePath());
        if (!tfbosOpt.isPresent()) {
            session.write(new DefaultFtpReply(FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "file not found: " + fromFtpFile.getAbsolutePath()));
            return FtpletResult.SKIP;
        }
        try (TemporaryFileBackedOutputStream tfbos = tfbosOpt.get()) {
            Subject shiroSubject = (Subject) session.getAttribute(SUBJECT);
            if (shiroSubject == null) {
                return FtpletResult.DISCONNECT;
            }
            CreateStorageRequest createRequest = getCreateStorageRequest(toFilename, tfbos);
            storeObject(shiroSubject, toFilename, createRequest);
        } finally {
            removeTempFileFromSession(session, fromFtpFile.getAbsolutePath());
        }
    }
    session.write(new DefaultFtpReply(FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "RNTO successful"));
    return FtpletResult.SKIP;
}
Also used : TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) FtpFile(org.apache.ftpserver.ftplet.FtpFile) DefaultFtpReply(org.apache.ftpserver.ftplet.DefaultFtpReply) Subject(ddf.security.Subject) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest)

Aggregations

Subject (ddf.security.Subject)94 Test (org.junit.Test)47 SecurityAssertion (ddf.security.assertion.SecurityAssertion)23 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)23 HashMap (java.util.HashMap)20 Metacard (ddf.catalog.data.Metacard)18 SecurityManager (ddf.security.service.SecurityManager)14 IOException (java.io.IOException)14 Serializable (java.io.Serializable)14 CollectionPermission (ddf.security.permission.CollectionPermission)13 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 CreateRequest (ddf.catalog.operation.CreateRequest)11 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)11 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)10 SecurityServiceException (ddf.security.service.SecurityServiceException)10 HashSet (java.util.HashSet)10 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)9 Before (org.junit.Before)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8