Package org.platformlayer

Examples of org.platformlayer.Scope


  @Override
  public ProjectAuthorization get() {
    ProjectAuthorization authentication = null;

    Scope scope = scopeProvider.get();
    if (scope != null) {
      authentication = scope.get(ProjectAuthorization.class);
    }

    return authentication;
  }
View Full Code Here


public class ScopeProvider implements Provider<Scope> {

  @Override
  public Scope get() {
    Scope contextMap = Scope.get();
    return contextMap;
  }
View Full Code Here

  }

  @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();
    }
  }
View Full Code Here

  }

  @Override
  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {
    Scope authenticatedScope = Scope.empty();

    // Fail safe
    authenticatedScope.put(AuthenticationCredentials.class, null);

    if (servletRequest instanceof HttpServletRequest) {
      HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
      HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;

      try {
        AuthenticationCredentials credentials = findCredentials(httpServletRequest);

        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();
    }
  }
View Full Code Here

  // 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;
  }
View Full Code Here

    }
  }

  @Override
  public Object call() throws OpsException {
    Scope scope = Scope.empty();
    scope.put(ProjectAuthorization.class, activeJob.getProjectAuthorization());
    try {
      scope.push();
      return doOperation();
    } finally {
      scope.pop();
    }
  }
View Full Code Here

    this.platformLayerClient = platformLayerClient;
    this.projects = projects;
  }

  public static OpsContext get() {
    Scope scope = Scope.get();
    if (scope == null) {
      return null;
    }
    return scope.get(OpsContext.class);
  }
View Full Code Here

    return scope.getInstance(clazz);
  }

  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();
    }
  }
View Full Code Here

TOP

Related Classes of org.platformlayer.Scope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.