001/*
002 *  Copyright 2017 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.workspaces.cmis;
017
018import java.util.ArrayList;
019import java.util.Collection;
020import java.util.List;
021
022import org.apache.avalon.framework.parameters.Parameters;
023import org.apache.avalon.framework.service.ServiceException;
024import org.apache.avalon.framework.service.ServiceManager;
025import org.apache.cocoon.environment.Request;
026
027import org.ametys.web.repository.site.SiteManager;
028
029/**
030 * Special authentication process for CMIS server, without project.
031 */
032public class AuthenticateAction extends org.ametys.core.authentication.AuthenticateAction
033{
034    private SiteManager _siteManager;
035
036    @Override
037    public void service(ServiceManager smanager) throws ServiceException
038    {
039        _siteManager = (SiteManager) smanager.lookup(SiteManager.ROLE);
040        super.service(smanager);
041    }
042    @Override
043    protected List<String> _getContexts(Request request, Parameters parameters)
044    {
045     // We return all the populations linked to at least one site
046        List<String> contexts = new ArrayList<>();
047
048        // Retrieve the sites to build the contexts to search on
049        Collection<String> siteNames = _siteManager.getSiteNames();
050
051        for (String siteName : siteNames)
052        {
053            String siteContext = "/sites/" + siteName;
054            contexts.add(siteContext);
055            siteContext = "/sites-fo/" + siteName;
056            contexts.add(siteContext);
057        }
058        
059        return contexts;
060    }
061}