001 /**
002 * $RCSfile: MCRUserFacade.java,v $
003 * $Revision: 1.0 $ $Date: 01.09.2008 10:16:52 $
004 *
005 * This file is part of ** M y C o R e **
006 * Visit our homepage at http://www.mycore.de/ for details.
007 *
008 * This program is free software; you can use it, redistribute it
009 * and / or modify it under the terms of the GNU General Public License
010 * (GPL) as published by the Free Software Foundation; either version 2
011 * of the License or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program, normally in the file license.txt.
020 * If not, write to the Free Software Foundation Inc.,
021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
022 *
023 **/
024 package org.mycore.user;
025
026 import java.security.Principal;
027
028 import org.mycore.common.MCRConfiguration;
029 import org.mycore.common.MCRSessionMgr;
030
031 public class MCRUserFacade {
032
033 public static String getCurrentUser() {
034 if (MCRConfiguration.instance().getBoolean("MCR.User.UseWebServer", false)) {
035 Principal p = MCRSessionMgr.getCurrentSession().getUserPrincipal();
036 if (p != null)
037 return p.getName();
038 }
039 return MCRSessionMgr.getCurrentSession().getCurrentUserID();
040 }
041
042 public static boolean isUserInGroup(String role) {
043 if (MCRConfiguration.instance().getBoolean("MCR.User.UseWebServer", false)) {
044 Principal p = MCRSessionMgr.getCurrentSession().getUserPrincipal();
045 if (p != null)
046 return MCRSessionMgr.getCurrentSession().isPrincipalInRole(role);
047 }
048 return MCRUserMgr.instance().getCurrentUser().isMemberOf(new MCRGroup(role));
049 }
050
051 }