You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Kiss K�lm�n <ss...@zalaszam.hu> on 2002/08/27 10:17:32 UTC

http errorcodes form an action

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
ssikiss@zalaszam.hu


---------------------------------------------------------------------
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:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: http errorcodes form an action

Posted by Vadim Gritsenko <va...@verizon.net>.
Kiss Kálmán wrote:

>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?
>

Make your action to return not-null map only on error. Then, in sitemap:

<map:action type="your type">
  <map:generate src="error"/>
  <map:serialize status-code="{status-from-action}" />
</map:action>

Vadim



> 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,
>  
>




---------------------------------------------------------------------
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:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>