コード例 #1
0
  @Override
  protected int beforeHandle(Request request, Response response) {
    Cookie cookie = request.getCookies().getFirst("Credentials");

    if (cookie != null) {
      // Extract the challenge response from the cookie
      String[] credentials = cookie.getValue().split("=");

      if (credentials.length == 2) {
        String identifier = credentials[0];
        String secret = credentials[1];
        request.setChallengeResponse(
            new ChallengeResponse(ChallengeScheme.HTTP_COOKIE, identifier, secret));
      }
    } else if (Method.POST.equals(request.getMethod())
        && request.getResourceRef().getQueryAsForm().getFirst("login") != null) {
      // Intercepting a login form
      Form credentials = new Form(request.getEntity());
      String identifier = credentials.getFirstValue("identifier");
      String secret = credentials.getFirstValue("secret");
      request.setChallengeResponse(
          new ChallengeResponse(ChallengeScheme.HTTP_COOKIE, identifier, secret));

      // Continue call processing to return the target representation if
      // authentication is successful or a new login page
      request.setMethod(Method.GET);
    }

    return super.beforeHandle(request, response);
  }
コード例 #2
0
 @Override
 protected ReadRegistration createUpdateQuery(
     Method method, Context context, Request request, Response response) throws ResourceException {
   Object key = request.getAttributes().get(UserDBResource.resourceKey);
   if (Method.POST.equals(method)) {
     if (key == null) return null; // post allowed only on /user level, not on /user/id
   } else if (Method.PUT.equals(method)) {
     return createQuery(context, request, response);
   }
   throw new ResourceException(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
 }
コード例 #3
0
ファイル: Config.java プロジェクト: jdgarrett/geogig
 @Override
 public boolean supports(final Method method) {
   return Method.POST.equals(method) || Method.GET.equals(method) || super.supports(method);
 }