01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.auth;
18:
19: import org.apache.avalon.framework.configuration.Configurable;
20: import org.apache.avalon.framework.configuration.Configuration;
21: import org.apache.avalon.framework.configuration.ConfigurationException;
22: import org.apache.avalon.framework.context.Context;
23: import org.apache.avalon.framework.context.ContextException;
24: import org.apache.avalon.framework.context.Contextualizable;
25: import org.apache.avalon.framework.logger.AbstractLogEnabled;
26: import org.apache.avalon.framework.thread.ThreadSafe;
27:
28: /**
29: * This is a base class that can be used for own {@link SecurityHandler}s. It
30: * provides a save implementation for the {@link #getId()} method. The only
31: * drawback is that a subclass has to use {@link Configurable} and can't
32: * use {@link org.apache.avalon.framework.parameters.Parameterizable}.
33: *
34: * @version $Id: AbstractSecurityHandler.java 433543 2006-08-22 06:22:54Z crossley $
35: */
36: public abstract class AbstractSecurityHandler extends
37: AbstractLogEnabled implements SecurityHandler, Configurable,
38: Contextualizable, ThreadSafe {
39:
40: /** The unique identifier. */
41: protected String id;
42:
43: /**
44: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
45: */
46: public void contextualize(final Context context)
47: throws ContextException {
48: String sitemapPrefix = null;
49: try {
50: // this is available starting with Cocoon 2.2
51: sitemapPrefix = (String) context.get("env-prefix");
52: } catch (ContextException ce) {
53: // no prefix available, so we are running pre 2.2 which means
54: // we only have one cocoon.xconf anyway
55: sitemapPrefix = "cocoon-2.1.x";
56: }
57: this .id = sitemapPrefix + '/';
58: }
59:
60: /**
61: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
62: */
63: public void configure(final Configuration conf)
64: throws ConfigurationException {
65: this .id = this .id + '/' + this .getClass().getName() + '/'
66: + conf.getAttribute("role", this .getClass().getName());
67: }
68:
69: /**
70: * @see org.apache.cocoon.auth.SecurityHandler#getId()
71: */
72: public String getId() {
73: return this.id;
74: }
75: }
|