Package org.jboss.web.tomcat.security

Examples of org.jboss.web.tomcat.security.ExtendedRealm


          if ((username != null) && (password != null)) {
              if (log.isDebugEnabled())
                  log.debug("Reauthenticating username '" + username + "'");
             // principal =
                 // context.getRealm().authenticate(username, password);
              ExtendedRealm realm = (ExtendedRealm)context.getRealm();
              try
              {
                 principal = realm.authenticate(request, response, config);
              }
              catch(Exception e)
              {
                 log.error("Exception in realm authenticate:",e);
              }
              if (principal != null) {
                  session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
                  if (!matchRequest(request)) {
                      register(request, response, principal,
                               HttpServletRequest.FORM_AUTH,
                               username, password);
                      return (true);
                  }
              }
              if (log.isDebugEnabled())
                  log.debug("Reauthentication failed, proceed normally");
          }
      }

      // Is this the re-submit of the original request URI after successful
      // authentication?  If so, forward the *original* request instead.
      if (matchRequest(request)) {
          session = request.getSessionInternal(true);
          if (log.isDebugEnabled())
              log.debug("Restore request from session '"
                        + session.getIdInternal()
                        + "'");
          principal = (Principal)
              session.getNote(Constants.FORM_PRINCIPAL_NOTE);
          register(request, response, principal, HttpServletRequest.FORM_AUTH,
                   (String) session.getNote(Constants.SESS_USERNAME_NOTE),
                   (String) session.getNote(Constants.SESS_PASSWORD_NOTE));
          // If we're caching principals we no longer need the username
          // and password in the session, so remove them
          if (cache) {
              session.removeNote(Constants.SESS_USERNAME_NOTE);
              session.removeNote(Constants.SESS_PASSWORD_NOTE);
          }
          if (restoreRequest(request, session)) {
              if (log.isDebugEnabled())
                  log.debug("Proceed to restored request");
              return (true);
          } else {
              if (log.isDebugEnabled())
                  log.debug("Restore of original request failed");
              response.sendError(HttpServletResponse.SC_BAD_REQUEST);
              return (false);
          }
      }

      // Acquire references to objects we will need to evaluate
      MessageBytes uriMB = MessageBytes.newInstance();
      CharChunk uriCC = uriMB.getCharChunk();
      uriCC.setLimit(-1);
      String contextPath = request.getContextPath();
      String requestURI = request.getDecodedRequestURI();

      // Is this the action request from the login page?
      boolean loginAction =
          requestURI.startsWith(contextPath) &&
          requestURI.endsWith(Constants.FORM_ACTION);

      // No -- Save this request and redirect to the form login page
      if (!loginAction) {
          session = request.getSessionInternal(true);
          if (log.isDebugEnabled())
              log.debug("Save request in session '" + session.getIdInternal() + "'");
          try {
              saveRequest(request, session);
          } catch (IOException ioe) {
              log.debug("Request body too big to save during authentication");
              response.sendError(HttpServletResponse.SC_FORBIDDEN,
                      sm.getString("authenticator.requestBodyTooBig"));
              return (false);
          }
          forwardToLoginPage(request, response, config);
          return (false);
      }

      // Yes -- Validate the specified credentials and redirect
      // to the error page if they are not correct
      ExtendedRealm realm = (ExtendedRealm)context.getRealm();
      if (characterEncoding != null) {
          request.setCharacterEncoding(characterEncoding);
      }
      String username = request.getParameter(Constants.FORM_USERNAME);
      String password = request.getParameter(Constants.FORM_PASSWORD);
      if (log.isDebugEnabled())
          log.debug("Authenticating username '" + username + "'");
      //principal = realm.authenticate(username, password);
      try
      {
         principal = realm.authenticate(request, response, config);
      }
      catch(Exception e)
      {
         log.error("Exception in realm authenticate:",e);
      }
View Full Code Here


          if ((username != null) && (password != null)) {
              if (log.isDebugEnabled())
                  log.debug("Reauthenticating username '" + username + "'");
             // principal =
                 // context.getRealm().authenticate(username, password);
              ExtendedRealm realm = (ExtendedRealm)context.getRealm();
              try
              {
                 principal = realm.authenticate(request, response, config);
              }
              catch(Exception e)
              {
                 log.error("Exception in realm authenticate:",e);
              }
              if (principal != null) {
                  session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
                  if (!matchRequest(request)) {
                      register(request, response, principal,
                               Constants.FORM_METHOD,
                               username, password);
                      return (true);
                  }
              }
              if (log.isDebugEnabled())
                  log.debug("Reauthentication failed, proceed normally");
          }
      }

      // Is this the re-submit of the original request URI after successful
      // authentication?  If so, forward the *original* request instead.
      if (matchRequest(request)) {
          session = request.getSessionInternal(true);
          if (log.isDebugEnabled())
              log.debug("Restore request from session '"
                        + session.getIdInternal()
                        + "'");
          principal = (Principal)
              session.getNote(Constants.FORM_PRINCIPAL_NOTE);
          register(request, response, principal, Constants.FORM_METHOD,
                   (String) session.getNote(Constants.SESS_USERNAME_NOTE),
                   (String) session.getNote(Constants.SESS_PASSWORD_NOTE));
          // If we're caching principals we no longer need the username
          // and password in the session, so remove them
          if (cache) {
              session.removeNote(Constants.SESS_USERNAME_NOTE);
              session.removeNote(Constants.SESS_PASSWORD_NOTE);
          }
          if (restoreRequest(request, session)) {
              if (log.isDebugEnabled())
                  log.debug("Proceed to restored request");
              return (true);
          } else {
              if (log.isDebugEnabled())
                  log.debug("Restore of original request failed");
              response.sendError(HttpServletResponse.SC_BAD_REQUEST);
              return (false);
          }
      }

      // Acquire references to objects we will need to evaluate
      MessageBytes uriMB = MessageBytes.newInstance();
      CharChunk uriCC = uriMB.getCharChunk();
      uriCC.setLimit(-1);
      String contextPath = request.getContextPath();
      String requestURI = request.getDecodedRequestURI();
      response.setContext(request.getContext());

      // Is this the action request from the login page?
      boolean loginAction =
          requestURI.startsWith(contextPath) &&
          requestURI.endsWith(Constants.FORM_ACTION);

      // No -- Save this request and redirect to the form login page
      if (!loginAction) {
          session = request.getSessionInternal(true);
          if (log.isDebugEnabled())
              log.debug("Save request in session '" + session.getIdInternal() + "'");
          try {
              saveRequest(request, session);
          } catch (IOException ioe) {
              log.debug("Request body too big to save during authentication");
              response.sendError(HttpServletResponse.SC_FORBIDDEN,
                      sm.getString("authenticator.requestBodyTooBig"));
              return (false);
          }
          forwardToLoginPage(request, response, config);
          return (false);
      }

      // Yes -- Validate the specified credentials and redirect
      // to the error page if they are not correct
      ExtendedRealm realm = (ExtendedRealm)context.getRealm();
      if (characterEncoding != null) {
          request.setCharacterEncoding(characterEncoding);
      }
      String username = request.getParameter(Constants.FORM_USERNAME);
      String password = request.getParameter(Constants.FORM_PASSWORD);
      if (log.isDebugEnabled())
          log.debug("Authenticating username '" + username + "'");
      //principal = realm.authenticate(username, password);
      try
      {
         principal = realm.authenticate(request, response, config);
      }
      catch(Exception e)
      {
         log.error("Exception in realm authenticate:",e);
      }
View Full Code Here

TOP

Related Classes of org.jboss.web.tomcat.security.ExtendedRealm

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.