<commit_before>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-2010 The eXist Project
 *  http://exist-db.org
 *  
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * 
 *  $Id$
 */
package org.exist.security;

import org.exist.EXistException;
import org.exist.security.xacml.ExistPDP;
import org.exist.storage.BrokerPool;
import org.exist.storage.DBBroker;
import org.exist.xmldb.XmldbURI;

/**
 * SecurityManager is responsible for managing users and groups.
 * 
 * There's only one SecurityManager for each database instance, which
 * may be obtained by {@link BrokerPool#getSecurityManager()}.
 * 
 * Users and groups are stored in the system collection, in document
 * users.xml. While it is possible to edit this file by hand, it
 * may lead to unexpected results, since SecurityManager reads 
 * users.xml only during database startup and shutdown.
 */
public interface SecurityManager {

   public final static String ACL_FILE = "users.xml";
   public final static XmldbURI ACL_FILE_URI = XmldbURI.create(ACL_FILE);
   
   public final static String DBA_GROUP = "dba";
   public final static String DBA_USER = "admin";
   public final static String GUEST_GROUP = "guest";
   public final static String GUEST_USER = "guest";

   void attach(BrokerPool pool, DBBroker sysBroker) throws EXistException;
   
   public BrokerPool getDatabase();

   boolean isXACMLEnabled();
   
   ExistPDP getPDP();

   User getUser(int uid);

   boolean hasUser(String name);

   // TODO: this should be addUser
   void setUser(User user) throws PermissionDeniedException, EXistException;

   void deleteUser(String name) throws PermissionDeniedException, EXistException;
   void deleteUser(User user) throws PermissionDeniedException, EXistException;

   boolean updateAccount(User account) throws PermissionDeniedException, EXistException;

   User getUser(String name);

   void addGroup(Group group) throws PermissionDeniedException, EXistException;
   @Deprecated
   void addGroup(String group) throws PermissionDeniedException, EXistException;

   boolean hasGroup(String name);
   boolean hasGroup(Group group);

   Group getGroup(String name);
   Group getGroup(int gid);

   void deleteRole(String name) throws PermissionDeniedException, EXistException;

   boolean hasAdminPrivileges(User user);

   int getResourceDefaultPerms();
   int getCollectionDefaultPerms();
	<commit_msg>[API] SecurityManager's methods getResourceDefaultPerms & getCollectionDefaultPerms deprecated, switch to CollectionConfiguration one<commit_after>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-2010 The eXist Project
 *  http://exist-db.org
 *  
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * 
 *  $Id$
 */
package org.exist.security;

import org.exist.EXistException;
import org.exist.config.Configurable;
import org.exist.security.xacml.ExistPDP;
import org.exist.storage.BrokerPool;
import org.exist.storage.DBBroker;
import org.exist.xmldb.XmldbURI;

/**
 * SecurityManager is responsible for managing users and groups.
 * 
 * There's only one SecurityManager for each database instance, which
 * may be obtained by {@link BrokerPool#getSecurityManager()}.
 * 
 * Users and groups are stored in the system collection, in document
 * users.xml. While it is possible to edit this file by hand, it
 * may lead to unexpected results, since SecurityManager reads 
 * users.xml only during database startup and shutdown.
 */
public interface SecurityManager extends Configurable {

   public final static String ACL_FILE = "users.xml";
   public final static XmldbURI ACL_FILE_URI = XmldbURI.create(ACL_FILE);
   
   public final static XmldbURI SECURITY_COLLETION_URI = XmldbURI.SYSTEM_COLLECTION_URI.append("security");
   public final static XmldbURI CONFIG_FILE_URI = XmldbURI.create("config.xml");

   public final static String DBA_GROUP = "dba";
   public final static String DBA_USER = "admin";
   public final static String GUEST_GROUP = "guest";
   public final static String GUEST_USER = "guest";

   void attach(BrokerPool pool, DBBroker sysBroker) throws EXistException;
   
   public BrokerPool getDatabase();

   boolean isXACMLEnabled();
   
   ExistPDP getPDP();

   User getUser(int uid);

   boolean hasUser(String name);

   // TODO: this should be addUser
   void setUser(User user) throws PermissionDeniedException, EXistException;

   void deleteUser(String name) throws PermissionDeniedException, EXistException;
   void deleteUser(User user) throws PermissionDeniedException, EXistException;

   boolean updateAccount(User account) throws PermissionDeniedException, EXistException;

   User getUser(String name);

   void addGroup(Group group) throws PermissionDeniedException, EXistException;
   @Deprecated
   void addGroup(String group) throws PermissionDeniedException, EXistException;

   boolean hasGroup(String name);
   boolean hasGroup(Group group);

   Group getGroup(String name);
   Group getGroup(int gid);

   void deleteRole(String name) throws PermissionDeniedException, EXistException;

   boolean hasAdminPrivileges(User user);

   @Deprecated //use CollectionConfiguration one
   int getResourceDefaultPerms();
   @Deprecated //use CollectionConfiguration one
   int getCollectionDefaultPerms();
	
{'fraction_non_alphanumeric': 0.06861710149298748, 'fraction_numerical': 0.005127431759915548, 'mean_word_length': 4.38748984565394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '242454', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1786, 'n_words': 695}