001/*
002 *  Copyright 2016 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.runtime.workspaces.admin.authentication;
017
018import java.util.Collections;
019import java.util.List;
020import java.util.Set;
021
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024import org.apache.cocoon.environment.Request;
025
026import org.ametys.core.authentication.AuthenticateAction;
027import org.ametys.core.right.RightManager;
028import org.ametys.runtime.plugin.PluginsManager;
029
030/**
031 * Cocoon action for authenticating users in the administration workspace. 
032 */
033public class AdminAuthenticateAction extends AuthenticateAction
034{
035    /** The runtime rights manager */
036    protected RightManager _rightManager;
037    
038    @Override
039    public void service(ServiceManager smanager) throws ServiceException
040    {
041        super.service(smanager);
042        _rightManager = (RightManager) manager.lookup(RightManager.ROLE);
043    }
044    
045    @Override
046    protected Set<String> _getAvailableUserPopulationsIds(Request request, List<String> contexts)
047    {
048        if (PluginsManager.getInstance().isSafeMode() || _userPopulationDAO.getEnabledUserPopulations(false).isEmpty())
049        {
050            return Collections.singleton(_userPopulationDAO.getAdminPopulation().getId());
051        }
052        else
053        {
054            return super._getAvailableUserPopulationsIds(request, contexts);
055        }
056    }
057}