All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fitnesse.authentication.Authenticator Maven / Gradle / Ivy

The newest version!
// Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.authentication;

import fitnesse.FitNesseContext;
import fitnesse.Responder;
import fitnesse.http.Request;

public abstract class Authenticator {
  public Authenticator() {
  }

  public Responder authenticate(FitNesseContext context, Request request, Responder privilegedResponder) throws Exception {
    request.getCredentials();
    String username = request.getAuthorizationUsername();
    String password = request.getAuthorizationPassword();

    if (isAuthenticated(username, password))
      return privilegedResponder;
    else if (!isSecureResponder(privilegedResponder))
      return privilegedResponder;
    else
      return verifyOperationIsSecure(privilegedResponder, context, request);
  }

  private Responder verifyOperationIsSecure(Responder privilegedResponder, FitNesseContext context, Request request) {
    SecureOperation so = ((SecureResponder) privilegedResponder).getSecureOperation();
    if (so.shouldAuthenticate(context, request))
      return unauthorizedResponder(context, request);
    else
      return privilegedResponder;
  }

  protected Responder unauthorizedResponder(FitNesseContext context, Request request) {
    return new UnauthorizedResponder();
  }

  private boolean isSecureResponder(Responder privilegedResponder) {
    return (privilegedResponder instanceof SecureResponder);
  }

  public abstract boolean isAuthenticated(String username, String password);

  @Override
  public String toString() {
    return getClass().getName();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy