Search in sources :

Example 6 with SecurityServiceException

use of ddf.security.service.SecurityServiceException in project ddf by codice.

the class SecurityTest method testRunWithSubjectOrElevateWhenUserSubjectExistsAndCallableThrowsException.

@Test
public void testRunWithSubjectOrElevateWhenUserSubjectExistsAndCallableThrowsException() throws Exception {
    when(SecurityUtils.getSubject()).thenReturn(shiroSubject);
    when(shiroSubject.execute(callable)).thenThrow(new ExecutionException(new UnsupportedOperationException()));
    try {
        security.runWithSubjectOrElevate(callable);
        fail("InvocationTargetException expected");
    } catch (SecurityServiceException e) {
        throw e;
    } catch (InvocationTargetException e) {
        assertThat(e.getCause(), is(instanceOf(UnsupportedOperationException.class)));
    }
}
Also used : SecurityServiceException(ddf.security.service.SecurityServiceException) ExecutionException(org.apache.shiro.subject.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with SecurityServiceException

use of ddf.security.service.SecurityServiceException in project ddf by codice.

the class FederationAdminServiceImpl method updateRegistryEntry.

@Override
public void updateRegistryEntry(Metacard updateMetacard, Set<String> destinations) throws FederationAdminException {
    validateRegistryMetacards(Collections.singletonList(updateMetacard));
    Map<String, Serializable> properties = new HashMap<>();
    String mcardId = updateMetacard.getId();
    if (isRemoteMetacard(updateMetacard) || CollectionUtils.isNotEmpty(destinations)) {
        Filter idFilter = filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(updateMetacard.getId());
        Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().like().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
        List<Metacard> results = this.getRegistryMetacardsByFilter(filterBuilder.allOf(tagFilter, idFilter), destinations);
        if (results.size() != 1) {
            throw new FederationAdminException("Could not find metacard to update.");
        }
        mcardId = results.get(0).getId();
        LOGGER.debug("Looked up remote-mcard-id {} and got id {}", updateMetacard.getId(), mcardId);
    }
    List<Map.Entry<Serializable, Metacard>> updateList = new ArrayList<>();
    updateList.add(new AbstractMap.SimpleEntry<>(mcardId, updateMetacard));
    UpdateRequest updateRequest = new UpdateRequestImpl(updateList, Metacard.ID, properties, destinations);
    try {
        UpdateResponse updateResponse = security.runWithSubjectOrElevate(() -> catalogFramework.update(updateRequest));
        if (!updateResponse.getProcessingErrors().isEmpty()) {
            throw new FederationAdminException("Processing error occurred while updating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(updateResponse.getProcessingErrors()));
        }
    } catch (SecurityServiceException | InvocationTargetException e) {
        String message = "Error updating registry entry.";
        LOGGER.debug("{} Metacard ID: {}", message, updateMetacard.getId());
        throw new FederationAdminException(message, e);
    }
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractMap(java.util.AbstractMap) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl)

Example 8 with SecurityServiceException

use of ddf.security.service.SecurityServiceException in project ddf by codice.

the class FederationAdminServiceImpl method getRegistryMetacardsByFilter.

private List<Metacard> getRegistryMetacardsByFilter(Filter filter, Set<String> sourceIds) throws FederationAdminException {
    if (filter == null) {
        throw new FederationAdminException("Error getting registry metacards. Null filter provided.");
    }
    PropertyName propertyName = new PropertyNameImpl(Metacard.MODIFIED);
    SortBy sortBy = new SortByImpl(propertyName, SortOrder.ASCENDING);
    QueryImpl query = new QueryImpl(filter);
    query.setSortBy(sortBy);
    query.setPageSize(PAGE_SIZE);
    QueryRequest queryRequest = new QueryRequestImpl(query, sourceIds);
    try {
        QueryResponse queryResponse = security.runWithSubjectOrElevate(() -> catalogFramework.query(queryRequest));
        return queryResponse.getResults().stream().map(Result::getMetacard).filter(Objects::nonNull).collect(Collectors.toList());
    } catch (SecurityServiceException | InvocationTargetException e) {
        String message = "Error querying for registry metacards.";
        LOGGER.debug("{} For Filter: {}", message, filter);
        throw new FederationAdminException(message, e);
    }
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) PropertyName(org.opengis.filter.expression.PropertyName) SecurityServiceException(ddf.security.service.SecurityServiceException) QueryRequest(ddf.catalog.operation.QueryRequest) SortBy(org.opengis.filter.sort.SortBy) InvocationTargetException(java.lang.reflect.InvocationTargetException) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(org.geotools.filter.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl)

Example 9 with SecurityServiceException

use of ddf.security.service.SecurityServiceException in project ddf by codice.

the class SubjectCommandsTest method doExecuteWhenRunWithSubjectOrElevateThrowsSecurityServiceException.

@Test
public void doExecuteWhenRunWithSubjectOrElevateThrowsSecurityServiceException() throws Exception {
    when(security.runWithSubjectOrElevate(any(Callable.class))).thenThrow(new SecurityServiceException(ERROR));
    subjectCommands.execute();
    assertThat(consoleOutput.getOutput(), containsString(ERROR));
}
Also used : SecurityServiceException(ddf.security.service.SecurityServiceException) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 10 with SecurityServiceException

use of ddf.security.service.SecurityServiceException in project ddf by codice.

the class Security method getSubject.

/**
     * Gets the {@link Subject} given a user name and password.
     *
     * @param username username
     * @param password password
     * @return {@link Subject} associated with the user name and password provided
     */
public Subject getSubject(String username, String password) {
    UPAuthenticationToken token = new UPAuthenticationToken(username, password);
    SecurityManager securityManager = getSecurityManager();
    if (securityManager != null) {
        try {
            return securityManager.getSubject(token);
        } catch (SecurityServiceException | RuntimeException e) {
            LOGGER.info("Unable to request subject for {} user.", username, e);
        }
    }
    return null;
}
Also used : SecurityServiceException(ddf.security.service.SecurityServiceException) SecurityManager(ddf.security.service.SecurityManager) UPAuthenticationToken(org.codice.ddf.security.handler.api.UPAuthenticationToken)

Aggregations

SecurityServiceException (ddf.security.service.SecurityServiceException)34 Subject (ddf.security.Subject)11 SecurityManager (ddf.security.service.SecurityManager)9 Test (org.junit.Test)9 IOException (java.io.IOException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 X509Certificate (java.security.cert.X509Certificate)6 Response (javax.ws.rs.core.Response)6 SecurityAssertion (ddf.security.assertion.SecurityAssertion)5 HashMap (java.util.HashMap)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Matchers.anyString (org.mockito.Matchers.anyString)5 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)4 Serializable (java.io.Serializable)4 ServletException (javax.servlet.ServletException)4 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)4 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)4 Metacard (ddf.catalog.data.Metacard)3 Result (ddf.catalog.data.Result)3