use of org.apache.shiro.subject.Subject in project ddf by codice.
the class SubjectCommands method runWithUserName.
private Object runWithUserName() throws InvocationTargetException {
try {
String password = getLine("Password for " + user + ": ", false);
Subject subject = security.getSubject(user, password);
if (subject == null) {
printErrorMessage("Invalid username/password");
return null;
}
return subject.execute(this::executeWithSubject);
} catch (ExecutionException e) {
LOGGER.info("Failed to run command: {}", e.getCause().getMessage(), e.getCause());
throw new InvocationTargetException(e.getCause());
} catch (IOException e) {
LOGGER.info("Failed to run command", e);
printErrorMessage("Failed to read password");
}
return null;
}
use of org.apache.shiro.subject.Subject in project ddf by codice.
the class SecurityPlugin method setSubjectOnRequestProperties.
private ddf.security.Subject setSubjectOnRequestProperties(Operation operation) {
try {
Object requestSubject = operation.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
if (!(requestSubject instanceof ddf.security.Subject)) {
Subject subject = SecurityUtils.getSubject();
if (subject instanceof ddf.security.Subject) {
operation.getProperties().put(SecurityConstants.SECURITY_SUBJECT, (ddf.security.Subject) subject);
LOGGER.debug("Copied security subject from SecurityUtils to operation property for legacy and multi-thread support.");
return (ddf.security.Subject) subject;
} else {
LOGGER.debug("Security subject was not of type ddf.security.Subject, cannot add to current operation. It may still be accessible from SecurityUtils for supporting services.");
}
}
} catch (Exception e) {
LOGGER.debug("No security subject found, cannot add to current operation.");
}
return null;
}
use of org.apache.shiro.subject.Subject in project ddf by codice.
the class SecurityLoggerInInterceptor method handleMessage.
@Override
public void handleMessage(Message message) throws Fault {
if (!MessageUtils.isRequestor(message)) {
Subject subject = ThreadContext.getSubject();
if (subject != null) {
String username = SubjectUtils.getName(subject);
SecurityLogger.audit("{} is making an inbound request to {}.", username, message.get(Message.REQUEST_URL));
} else {
SecurityLogger.audit("No subject associated with inbound request to {}.", message.get(Message.REQUEST_URL));
}
}
}
use of org.apache.shiro.subject.Subject in project ddf by codice.
the class FilterPlugin method getSubject.
private Subject getSubject(Request input) throws StopProcessingException {
Object securityAssertion = input.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
Subject subject;
if (securityAssertion instanceof Subject) {
subject = (Subject) securityAssertion;
LOGGER.debug("Filter plugin found Subject for query response.");
} else {
throw new StopProcessingException("Unable to filter contents of current message, no user Subject available.");
}
return subject;
}
use of org.apache.shiro.subject.Subject in project ddf by codice.
the class FilterPlugin method processPostResource.
@Override
public ResourceResponse processPostResource(ResourceResponse input, Metacard metacard) throws StopProcessingException {
if (input.getRequest() == null || input.getRequest().getProperties() == null) {
throw new StopProcessingException("Unable to filter contents of current message, no user Subject available.");
}
KeyValueCollectionPermission securityPermission = new KeyValueCollectionPermission(CollectionPermission.READ_ACTION);
Subject subject = getSubject(input);
Attribute attr = metacard.getAttribute(Metacard.SECURITY);
if (!checkPermissions(attr, securityPermission, subject, CollectionPermission.READ_ACTION)) {
for (FilterStrategy filterStrategy : filterStrategies.values()) {
FilterResult filterResult = filterStrategy.process(input, metacard);
if (filterResult.processed()) {
if (filterResult.response() == null) {
throw new StopProcessingException("Subject not permitted to receive resource");
} else {
input = (ResourceResponse) filterResult.response();
}
break;
//returned metacards are ignored for resource requests
}
}
if (filterStrategies.size() == 0) {
throw new StopProcessingException("Subject not permitted to receive resource");
}
}
return input;
}
Aggregations