コード例 #1
0
  public List<?> call(String methodName, Object args[]) throws FabricCommunicationException {
    String authenticateHeader;

    try {
      authenticateHeader = DigestAuthentication.getChallengeHeader(this.url);
    } catch (IOException ex) {
      throw new FabricCommunicationException(
          "Unable to obtain challenge header for authentication", ex);
    }

    Map<String, String> digestChallenge =
        DigestAuthentication.parseDigestChallenge(authenticateHeader);

    String authorizationHeader =
        DigestAuthentication.generateAuthorizationHeader(
            digestChallenge, this.username, this.password);

    this.underlyingCaller.setHeader("Authorization", authorizationHeader);

    return this.underlyingCaller.call(methodName, args);
  }
コード例 #2
0
  private UserSession doAuthentication(HttpServletRequest request, HttpServletResponse response) {
    // Get the Authorization header, if one was supplied
    String authHeader = request.getHeader("Authorization");
    if (authHeader != null) {
      // fetch user session from a previous authentication

      UserSession usess = null;

      StringTokenizer st = new StringTokenizer(authHeader);
      if (st.hasMoreTokens()) {
        String basic = st.nextToken();

        // We only handle HTTP Basic authentication
        if (basic.equalsIgnoreCase("Basic")) {
          String credentials = st.nextToken();
          usess = handleBasicAuthentication(credentials, request);
        } else if (basic.equalsIgnoreCase("Digest")) {
          DigestAuthentication digestAuth = DigestAuthentication.parse(authHeader);
          usess = handleDigestAuthentication(digestAuth, request);
        }
      }

      if (usess != null) {
        return usess;
      }
    }

    // If the user was not validated or the browser does not know about the realm yet, fail with a
    // 401 status code (UNAUTHORIZED) and
    // pass back a WWW-Authenticate header for
    // this servlet.
    //
    // Note that this is the normal situation the
    // first time you access the page. The client
    // web browser will prompt for userID and password
    // and cache them so that it doesn't have to
    // prompt you again.

    if (request.isSecure() || Settings.isJUnitTest()) {
      response.addHeader("WWW-Authenticate", "Basic realm=\"" + BASIC_AUTH_REALM + "\"");
    }
    if (webdavModule.isDigestAuthenticationEnabled()) {
      String nonce = UUID.randomUUID().toString().replace("-", "");
      response.addHeader(
          "WWW-Authenticate",
          "Digest realm=\"" + BASIC_AUTH_REALM + "\", qop=\"auth\", nonce=\"" + nonce + "\"");
    }
    response.setStatus(401);
    return null;
  }