Hi

I try to implement an action, that verifiyes the http
authorization-header, and send a http errorcode back, if its
nonexistent. How can I make this? I know, that this is not necessarly a
cocoon task but I want to make it application/web server independent.

Actualy my action looks like:

public class AuthAction extends AbstractAction
{

  final static String PORTAL_AUTH_TYPE = "xxx.hu";

  public Map act (Redirector redirector, 
                  SourceResolver resolver, 
                  Map objectModel, 
                  String source, 
                  Parameters params) {
  Map sitemapParams = new HashMap();

    Request request = ObjectModelHelper.getRequest(objectModel);
    Response response = ObjectModelHelper.getResponse(objectModel);

    Logger logger = this.getLogger();

    String authtype = request.getAuthType();

    try {

    if (authtype.equals(PORTAL_AUTH_TYPE)) {
      request.setAttribute("authok", "true");
      request.setAttribute("reqtype", request.getClass().getName());
      request.setAttribute("errormsg","AUTH OK");

      logger.debug("-- Auth OK - reqtype: " + request.getClass().getName());

    } else {

      logger.debug("-- Auth FAILED - reqtype: " + request.getClass().getName() +
                    " -- authtype: " + authtype);

      if 
(request.getClass().getName().equals("org.apache.cocoon.environment.http.HttpResponse"))
 {
        try {
          HttpResponse a = (HttpResponse)response;
          a.sendError(java.net.HttpURLConnection.HTTP_UNAUTHORIZED);
          request.setAttribute("errormsg","authentication required!");
        }
        catch (java.io.IOException e) {
          System.out.println(e.getLocalizedMessage());
        }

      } else {
        request.setAttribute("authok", "true");
        request.setAttribute("reqtype", request.getClass().getName());
        request.setAttribute("errormsg","AUTH CMDLINE");
      }
    }

    } 
    catch (Exception e) {
      System.out.println(e.getLocalizedMessage());
    }

    return sitemapParams;
  }
}

thanks,
-- 
Kálmán Kiss
[EMAIL PROTECTED]


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to