use of org.platformlayer.Scope in project platformlayer by platformlayer.
the class OperationWorker method call.
@Override
public Object call() throws OpsException {
Scope scope = Scope.empty();
scope.put(ProjectAuthorization.class, activeJob.getProjectAuthorization());
try {
scope.push();
return doOperation();
} finally {
scope.pop();
}
}
use of org.platformlayer.Scope in project platformlayer by platformlayer.
the class OpsAuthenticationFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
Scope authenticatedScope = Scope.inherit();
// Fail safe
authenticatedScope.put(AuthenticationCredentials.class, null);
if (servletRequest instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
try {
AuthenticationCredentials credentials = findCredentials(httpServletRequest);
// if (authenticated == null) {
// httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// return;
// } else {
// populateScope(authenticatedScope, authenticated);
// }
authenticatedScope.put(AuthenticationCredentials.class, credentials);
} catch (SecurityException e) {
httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
} catch (Exception e) {
// If we're down, don't tell the user that their password is wrong
log.warn("Unexpected error in authentication filter", e);
httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
authenticatedScope.push();
try {
filterChain.doFilter(servletRequest, servletResponse);
} finally {
authenticatedScope.pop();
}
}
use of org.platformlayer.Scope in project platformlayer by platformlayer.
the class ResourceBase method getScopeParameter.
// protected <T> void setScopeParameter(T t) {
// getScope().put(t);
// }
protected <T> T getScopeParameter(Class<T> clazz, boolean required) {
Scope contextMap = Scope.get();
T t = contextMap.get(clazz);
if (required && t == null) {
throw new IllegalArgumentException(clazz.getSimpleName() + " is required");
}
return t;
}
use of org.platformlayer.Scope in project platformlayer by platformlayer.
the class ScopeProjectAuthorizationProvider method get.
@Override
public ProjectAuthorization get() {
ProjectAuthorization authentication = null;
Scope scope = scopeProvider.get();
if (scope != null) {
authentication = scope.get(ProjectAuthorization.class);
}
return authentication;
}
use of org.platformlayer.Scope in project platformlayer by platformlayer.
the class OpsContext method runInContext.
public static <T, E extends Exception> T runInContext(OpsContext opsContext, CheckedCallable<T, E> callable) throws OpsException {
Scope scope = Scope.inherit();
scope.put(opsContext);
try {
scope.push();
return callable.call();
} catch (Exception e) {
log.warn("Error running operation", e);
if (e instanceof OpsException) {
throw ((OpsException) e);
}
throw new OpsException("Error during operation", e);
} finally {
try {
Utils.safeClose(opsContext);
} catch (Exception e) {
log.error("Error while closing OpsContext");
}
scope.pop();
}
}
Aggregations