You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Fe...@thomson.com on 2006/03/22 10:49:46 UTC
authenticator component?
Is there a sample of a Java authenticator component (I think a
generator) somewhere?
Something that can be put inside the matcher for the authentication uri
of the authentication manager.
Thanks
Re: authenticator component?
Posted by Fernando Mato Mira <ma...@acm.org>.
I made a sample based on the RequestGenerator. There are some unused
imports.
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.generation;
import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Map;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.generation.ServiceableGenerator;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.xml.IncludeXMLConsumer;
import org.apache.excalibur.xml.sax.SAXParser;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class SampleAuthenticationGenerator extends ServiceableGenerator {
/** The namespace URI of this generator. */
private final static String URI = null;
private String userid;
public void setup(SourceResolver resolver, Map objectModel, String
src, Parameters parameters)
throws ProcessingException, SAXException, IOException {
super.setup(resolver, objectModel, src, parameters);
userid = parameters.getParameter("username", null);
}
/**
* Generate XML data.
*/
public void generate()
throws SAXException {
final Request request = ObjectModelHelper.getRequest(objectModel);
final AttributesImpl attr = new AttributesImpl();
this.contentHandler.startDocument();
if (userid != null) {
if (userid.equals("allow")) {
attribute(attr, "target", request.getRequestURI());
attribute(attr, "sitemap", request.getSitemapURI());
attribute(attr, "source", (this.source != null ? this.source
: ""));
start("authentication", attr);
start("ID", attr);
data(userid);
end("ID");
start("role", attr);
data("PRIV_EDITOR");
end("role");
start("data", attr);
end("data");
end("authentication");
}
}
this.contentHandler.endDocument();
}
private void attribute(AttributesImpl attr, String name, String value) {
attr.addAttribute("", name, name, "CDATA", value);
}
private void start(String name, AttributesImpl attr)
throws SAXException {
super.contentHandler.startElement(URI, name, /*PREFIX + ":" +*/
name, attr);
attr.clear();
}
private void end(String name)
throws SAXException {
super.contentHandler.endElement(URI, name, /*PREFIX + ":" +*/ name);
}
private void data(String data)
throws SAXException {
super.contentHandler.characters(data.toCharArray(), 0,
data.length());
}
}
Mato Mira, Fernando (DIA CHE) wrote:
> Is there a sample of a Java authenticator component (I think a
> generator) somewhere?
>
> Something that can be put inside the matcher for the authentication
> uri of the authentication manager.
>
>
>
> Thanks
>
--
--
Fernando D. Mato Mira matomira@acm.org
Thomson Corporation Switzerland AG
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org