001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.auth.portal;
018:
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import org.apache.avalon.framework.CascadingRuntimeException;
023: import org.apache.avalon.framework.configuration.Configuration;
024: import org.apache.avalon.framework.configuration.ConfigurationException;
025: import org.apache.avalon.framework.service.ServiceException;
026: import org.apache.cocoon.portal.PortalService;
027: import org.apache.cocoon.auth.StandardApplication;
028: import org.apache.cocoon.auth.User;
029:
030: /**
031: * This is a default implementation for a portal application.
032: * Note: This class belongs to cauth but has to be defined in the portal block for now.
033: * This will be cleaned up with Cocoon 2.2.
034: * @version $Id: StandardPortalApplication.java 486543 2006-12-13 08:14:36Z cziegeler $
035: */
036: public class StandardPortalApplication extends StandardApplication
037: implements PortalApplication {
038:
039: /** The configuration. */
040: protected Map portalConfig;
041:
042: /**
043: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
044: */
045: public void configure(final Configuration conf)
046: throws ConfigurationException {
047: super .configure(conf);
048: final Configuration config = conf.getChild("profiles");
049: final Configuration[] children = config.getChildren();
050: this .portalConfig = new HashMap();
051: if (children != null) {
052: for (int i = 0; i < children.length; i++) {
053: this .portalConfig.put(children[i].getName(),
054: children[i].getAttribute("uri"));
055: }
056: }
057: }
058:
059: /**
060: * @see org.apache.cocoon.auth.portal.PortalApplication#getPortalConfiguration()
061: */
062: public Map getPortalConfiguration() {
063: return this .portalConfig;
064: }
065:
066: /**
067: * @see org.apache.cocoon.auth.Application#userDidLogin(org.apache.cocoon.auth.User, java.util.Map)
068: */
069: public void userDidLogin(final User user, final Map context) {
070: super .userDidLogin(user, context);
071: PortalService service = null;
072: try {
073: service = (PortalService) this .manager
074: .lookup(PortalService.ROLE);
075: service.getComponentManager().getProfileManager().login();
076: } catch (ServiceException ce) {
077: throw new CascadingRuntimeException(
078: "Unable to lookup portal service.", ce);
079: } finally {
080: this .manager.release(service);
081: }
082: }
083:
084: /**
085: * @see org.apache.cocoon.auth.Application#userWillLogout(org.apache.cocoon.auth.User, java.util.Map)
086: */
087: public void userWillLogout(final User user, final Map context) {
088: PortalService service = null;
089: try {
090: service = (PortalService) this .manager
091: .lookup(PortalService.ROLE);
092: service.getComponentManager().getProfileManager().logout();
093: } catch (ServiceException ce) {
094: throw new CascadingRuntimeException(
095: "Unable to lookup portal service.", ce);
096: } finally {
097: this.manager.release(service);
098: }
099: super.userWillLogout(user, context);
100: }
101: }
|