Search in sources :

Example 11 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class ReliableResourceDownloaderTest method testIOExceptionDuringRead.

@Test
public void testIOExceptionDuringRead() throws Exception {
    ResourceResponse mockResponse = getMockResourceResponse(mockStream);
    when(mockStream.read(any(byte[].class))).thenThrow(new IOException());
    int retries = 5;
    downloaderConfig.setMaxRetryAttempts(retries);
    DownloadStatusInfoImpl downloadStatusInfo = new DownloadStatusInfoImpl();
    downloadStatusInfo.setSubjectOperations(new SubjectUtils());
    ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), DOWNLOAD_ID, mockResponse, getMockRetriever());
    downloader.setupDownload(mockMetacard, downloadStatusInfo);
    downloader.run();
    verify(mockPublisher, times(retries)).postRetrievalStatus(any(ResourceResponse.class), eq(ProductRetrievalStatus.RETRYING), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SubjectUtils(ddf.security.service.impl.SubjectUtils) Metacard(ddf.catalog.data.Metacard) ResourceResponse(ddf.catalog.operation.ResourceResponse) DownloadStatusInfoImpl(ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class ReliableResourceDownloaderTest method testCacheExceptionDuringWrite.

@Test
public void testCacheExceptionDuringWrite() throws Exception {
    downloaderConfig.setCacheEnabled(true);
    ResourceCacheImpl mockCache = mock(ResourceCacheImpl.class);
    when(mockCache.isPending(anyString())).thenReturn(false);
    when(mockCache.getProductCacheDirectory()).thenReturn(productCacheDirectory);
    downloaderConfig.setResourceCache(mockCache);
    mis = new MockInputStream(productInputFilename);
    ResourceResponse mockResponse = getMockResourceResponse(mis);
    ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), "123", mockResponse, getMockRetriever());
    DownloadStatusInfoImpl downloadStatusInfo = new DownloadStatusInfoImpl();
    downloadStatusInfo.setSubjectOperations(new SubjectUtils());
    downloader.setupDownload(mockMetacard, downloadStatusInfo);
    FileOutputStream mockFos = mock(FileOutputStream.class);
    doThrow(new IOException()).when(mockFos).write(any(byte[].class), anyInt(), anyInt());
    downloader.setFileOutputStream(mockFos);
    downloader.run();
    verify(mockPublisher, times(1)).postRetrievalStatus(any(ResourceResponse.class), eq(ProductRetrievalStatus.RETRYING), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));
    verify(mockCache, times(1)).removePendingCacheEntry(anyString());
    assertThat(downloaderConfig.isCacheEnabled(), is(false));
}
Also used : MockInputStream(ddf.catalog.cache.MockInputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SubjectUtils(ddf.security.service.impl.SubjectUtils) Metacard(ddf.catalog.data.Metacard) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) DownloadStatusInfoImpl(ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils 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);
}
Also used : SubjectUtils(ddf.security.service.impl.SubjectUtils) Serializable(java.io.Serializable) FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResultImpl(ddf.catalog.data.impl.ResultImpl) Security(org.codice.ddf.security.impl.Security) 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) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) DelegatingSubject(org.apache.shiro.subject.support.DelegatingSubject) Subject(ddf.security.Subject) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Principal(java.security.Principal) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 14 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class ActivityEventPublisherTest method setupPublisher.

@Override
protected void setupPublisher() {
    actionProvider = mock(ActionProvider.class);
    Action downloadAction = mock(Action.class);
    try {
        when(actionProvider.getAction(metacard)).thenReturn(downloadAction);
        when(downloadAction.getUrl()).thenReturn(new URL("http://example.com/download"));
    } catch (Exception e) {
        LOGGER.warn("Could not set download action URL", e);
    }
    publisher = new DownloadsStatusEventPublisher(eventAdmin, ImmutableList.of(actionProvider));
    publisher.setSubjectOperations(new SubjectUtils());
    publisher.setNotificationEnabled(false);
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) SubjectUtils(ddf.security.service.impl.SubjectUtils) URL(java.net.URL)

Example 15 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class NotificationEventPublisherTest method setupPublisher.

@Override
protected void setupPublisher() {
    actionProvider = mock(ActionProvider.class);
    Action downloadAction = mock(Action.class);
    try {
        when(actionProvider.getAction(metacard)).thenReturn(downloadAction);
        when(downloadAction.getUrl()).thenReturn(new URL("http://example.com/download"));
    } catch (Exception e) {
        LOGGER.warn("Could not set download action URL", e);
    }
    publisher = new DownloadsStatusEventPublisher(eventAdmin, ImmutableList.of(actionProvider));
    publisher.setSubjectOperations(new SubjectUtils());
    publisher.setActivityEnabled(false);
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) SubjectUtils(ddf.security.service.impl.SubjectUtils) URL(java.net.URL)

Aggregations

SubjectUtils (ddf.security.service.impl.SubjectUtils)20 Test (org.junit.Test)10 Metacard (ddf.catalog.data.Metacard)5 DownloadStatusInfoImpl (ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl)5 Before (org.junit.Before)5 Action (ddf.action.Action)4 ResourceCacheImpl (ddf.catalog.cache.impl.ResourceCacheImpl)4 ResourceResponse (ddf.catalog.operation.ResourceResponse)4 HashMap (java.util.HashMap)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ActionProvider (ddf.action.ActionProvider)3 Claim (ddf.security.claims.Claim)3 ClaimsCollection (ddf.security.claims.ClaimsCollection)3 ClaimsParameters (ddf.security.claims.ClaimsParameters)3 ClaimsParametersImpl (ddf.security.claims.impl.ClaimsParametersImpl)3 HashSet (java.util.HashSet)3 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)3 MockInputStream (ddf.catalog.cache.MockInputStream)2 SecurityLoggerImpl (ddf.security.audit.impl.SecurityLoggerImpl)2 IOException (java.io.IOException)2