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)));
}
}
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);
}
}
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);
}
}
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));
}
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;
}
Aggregations