<commit_before>package cz.metacentrum.perun.core.blImpl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cz.metacentrum.perun.core.api.AttributesManager;
import cz.metacentrum.perun.core.api.AuditMessagesManager;
import cz.metacentrum.perun.core.api.BeansUtils;
import cz.metacentrum.perun.core.api.DatabaseManager;
import cz.metacentrum.perun.core.api.ExtSource;
import cz.metacentrum.perun.core.api.ExtSourcesManager;
import cz.metacentrum.perun.core.api.FacilitiesManager;
import cz.metacentrum.perun.core.api.GroupsManager;
import cz.metacentrum.perun.core.api.MembersManager;
import cz.metacentrum.perun.core.api.OwnersManager;
import cz.metacentrum.perun.core.api.Perun;
import cz.metacentrum.perun.core.api.PerunPrincipal;
import cz.metacentrum.perun.core.api.PerunSession;
import cz.metacentrum.perun.core.api.RTMessagesManager;
import cz.metacentrum.perun.core.api.ResourcesManager;
import cz.metacentrum.perun.core.api.Searcher;
import cz.metacentrum.perun.core.api.SecurityTeamsManager;
import cz.metacentrum.perun.core.api.ServicesManager;
import cz.metacentrum.perun.core.api.UserExtSource;
import cz.metacentrum.perun.core.api.UsersManager;
import cz.metacentrum.perun.core.api.VosManager;
import cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.InternalErrorException;
import cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.UserNotExistsException;
import cz.metacentrum.perun.core.bl.AttributesManagerBl;
import cz.metacentrum.perun.core.bl.AuditMessagesManagerBl;
import cz.metacentrum.perun.core.bl.AuthzResolverBl;
import cz.metacentrum.perun.core.bl.DatabaseManagerBl;
import cz.metacentrum.perun.core.bl.ExtSourcesManagerBl;
import cz.metacentrum.perun.core.bl.FacilitiesManagerBl;
import cz.metacentrum.perun.core.bl.GroupsManagerBl;
import cz.metacentrum.perun.core.bl.MembersManagerBl;
import cz.metacentrum.perun.core.bl.ModulesUtilsBl;
import cz.metacentrum.perun.core.bl.OwnersManagerBl;
import cz.metacentrum.perun.core.bl.PerunBl;
import cz.metacentrum.perun.core.bl.RTMessagesManagerBl;
import cz.metacentrum.perun.core.bl.ResourcesManagerBl;
import cz.metacentrum.perun.core.bl.SearcherBl;
import cz.metacentrum.perun.core.bl.SecurityTeamsManagerBl;
import cz.metacentrum.perun.core.bl.ServicesManagerBl;
import cz.metacentrum.perun.core.bl.UsersManagerBl;
import cz.metacentrum.perun.core.bl.VosManagerBl;
import cz.metacentrum.perun.core.impl.Auditer;
import cz.metacentrum.perun.core.impl.PerunSessionImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * Implementation of Perun.
 *
 * @author <NAME> <EMAIL>
 */
public class PerunBlImpl implements PerunBl {
	private VosManager vosManager = null;
	private UsersManager usersManager = null;
	private MembersManager membersManager = null;
	private GroupsManager groupsManager = null;
	private FacilitiesManager facilitiesManager = null;
	private DatabaseManager databaseManager = null;
	private ResourcesManager resourcesManager = null;
	private ExtSourcesManager extSourcesManager = null;
	private AttributesManager attributesManager = null;
	private ServicesManager servicesManager = null;
	private OwnersManager ownersManager = null;
	private AuditMessagesManager auditMessagesManager = null;
	private RTMessagesManager rtMessagesManager = null;
	private SecurityTeamsManager securityTeamsManager = null;
	private Searcher searcher = null;

	private ModulesUtilsBl modulesUtilsBl = null;
	private VosManagerBl vosManagerBl = null;
	private UsersManagerBl usersManagerBl = null;
	private MembersManagerBl membersManagerBl = null;
	private GroupsManagerBl groupsManagerBl = null;
	private FacilitiesManagerBl facilitiesManagerBl = null;
	private DatabaseManagerBl databaseManagerBl = null;
	private ResourcesManagerBl resourcesManagerBl = null;
	private ExtSourcesManagerBl extSourcesManagerBl = null;
	private AttributesManagerBl attributesManagerBl = null;
	private ServicesManagerBl servicesManagerBl = null;
	private OwnersManagerBl ownersManagerBl = null;
	private AuditMessagesManagerBl auditMessagesManagerBl = null;
	private RTMessagesManagerBl rtMessagesManagerBl = null;
	private SecurityTeamsManagerBl securityTeamsManagerBl = null;
	private AuthzResolverBl authzResolverBl = null;
	private SearcherBl searcherBl = null;

	private Auditer auditer = null;

	final static Logger log = LoggerFactory.getLogger(PerunBlImpl.class);

	final static List<String> dontLookupUsersForLogins = new ArrayList<String>();

	// fill list of logins we don't want to lookup users for
	static {

		String propValue = null;
		try {
			propValue = BeansUtils.getPropertyFromConfiguration("perun.dont.lookup.users");
		} catch (InternalErrorException e) {
			log.error("Unable to load logins for which we don't lookup users");
		}

		if (propValue != null) {
			String[] dontLogins = propValue.split(",");
			for (String str : dontLogins) {
				dontLookupUsersForLogins.add(str.trim());
			}
		}

	}

	public PerunBlImpl() {

	}

	public PerunSession getPerunSession(PerunPrincipal principal) throws InternalErrorException {
		if (principal.getUser() == null &&
				this.getUsersManagerBl() != null &&
				!dontLookupUsersForLogins.contains(principal.getActor())) {
			// Get the user if we are completely initialized<commit_msg>CORE: Use HashSet instead of List for better performance<commit_after>package cz.metacentrum.perun.core.blImpl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cz.metacentrum.perun.core.api.AttributesManager;
import cz.metacentrum.perun.core.api.AuditMessagesManager;
import cz.metacentrum.perun.core.api.BeansUtils;
import cz.metacentrum.perun.core.api.DatabaseManager;
import cz.metacentrum.perun.core.api.ExtSource;
import cz.metacentrum.perun.core.api.ExtSourcesManager;
import cz.metacentrum.perun.core.api.FacilitiesManager;
import cz.metacentrum.perun.core.api.GroupsManager;
import cz.metacentrum.perun.core.api.MembersManager;
import cz.metacentrum.perun.core.api.OwnersManager;
import cz.metacentrum.perun.core.api.Perun;
import cz.metacentrum.perun.core.api.PerunPrincipal;
import cz.metacentrum.perun.core.api.PerunSession;
import cz.metacentrum.perun.core.api.RTMessagesManager;
import cz.metacentrum.perun.core.api.ResourcesManager;
import cz.metacentrum.perun.core.api.Searcher;
import cz.metacentrum.perun.core.api.SecurityTeamsManager;
import cz.metacentrum.perun.core.api.ServicesManager;
import cz.metacentrum.perun.core.api.UserExtSource;
import cz.metacentrum.perun.core.api.UsersManager;
import cz.metacentrum.perun.core.api.VosManager;
import cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.InternalErrorException;
import cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.UserNotExistsException;
import cz.metacentrum.perun.core.bl.AttributesManagerBl;
import cz.metacentrum.perun.core.bl.AuditMessagesManagerBl;
import cz.metacentrum.perun.core.bl.AuthzResolverBl;
import cz.metacentrum.perun.core.bl.DatabaseManagerBl;
import cz.metacentrum.perun.core.bl.ExtSourcesManagerBl;
import cz.metacentrum.perun.core.bl.FacilitiesManagerBl;
import cz.metacentrum.perun.core.bl.GroupsManagerBl;
import cz.metacentrum.perun.core.bl.MembersManagerBl;
import cz.metacentrum.perun.core.bl.ModulesUtilsBl;
import cz.metacentrum.perun.core.bl.OwnersManagerBl;
import cz.metacentrum.perun.core.bl.PerunBl;
import cz.metacentrum.perun.core.bl.RTMessagesManagerBl;
import cz.metacentrum.perun.core.bl.ResourcesManagerBl;
import cz.metacentrum.perun.core.bl.SearcherBl;
import cz.metacentrum.perun.core.bl.SecurityTeamsManagerBl;
import cz.metacentrum.perun.core.bl.ServicesManagerBl;
import cz.metacentrum.perun.core.bl.UsersManagerBl;
import cz.metacentrum.perun.core.bl.VosManagerBl;
import cz.metacentrum.perun.core.impl.Auditer;
import cz.metacentrum.perun.core.impl.PerunSessionImpl;

import java.util.HashSet;
import java.util.Set;

/**
 * Implementation of Perun.
 *
 * @author <NAME> <EMAIL>
 */
public class PerunBlImpl implements PerunBl {
	private VosManager vosManager = null;
	private UsersManager usersManager = null;
	private MembersManager membersManager = null;
	private GroupsManager groupsManager = null;
	private FacilitiesManager facilitiesManager = null;
	private DatabaseManager databaseManager = null;
	private ResourcesManager resourcesManager = null;
	private ExtSourcesManager extSourcesManager = null;
	private AttributesManager attributesManager = null;
	private ServicesManager servicesManager = null;
	private OwnersManager ownersManager = null;
	private AuditMessagesManager auditMessagesManager = null;
	private RTMessagesManager rtMessagesManager = null;
	private SecurityTeamsManager securityTeamsManager = null;
	private Searcher searcher = null;

	private ModulesUtilsBl modulesUtilsBl = null;
	private VosManagerBl vosManagerBl = null;
	private UsersManagerBl usersManagerBl = null;
	private MembersManagerBl membersManagerBl = null;
	private GroupsManagerBl groupsManagerBl = null;
	private FacilitiesManagerBl facilitiesManagerBl = null;
	private DatabaseManagerBl databaseManagerBl = null;
	private ResourcesManagerBl resourcesManagerBl = null;
	private ExtSourcesManagerBl extSourcesManagerBl = null;
	private AttributesManagerBl attributesManagerBl = null;
	private ServicesManagerBl servicesManagerBl = null;
	private OwnersManagerBl ownersManagerBl = null;
	private AuditMessagesManagerBl auditMessagesManagerBl = null;
	private RTMessagesManagerBl rtMessagesManagerBl = null;
	private SecurityTeamsManagerBl securityTeamsManagerBl = null;
	private AuthzResolverBl authzResolverBl = null;
	private SearcherBl searcherBl = null;

	private Auditer auditer = null;

	final static Logger log = LoggerFactory.getLogger(PerunBlImpl.class);

	final static Set<String> dontLookupUsersForLogins = new HashSet<>();

	// fill list of logins we don't want to lookup users for
	static {

		String propValue = null;
		try {
			propValue = BeansUtils.getPropertyFromConfiguration("perun.dont.lookup.users");
		} catch (InternalErrorException e) {
			log.error("Unable to load logins for which we don't lookup users");
		}

		if (propValue != null) {
			String[] dontLogins = propValue.split(",");
			for (String str : dontLogins) {
				dontLookupUsersForLogins.add(str.trim());
			}
		}

	}

	public PerunBlImpl() {

	}

	public PerunSession getPerunSession(PerunPrincipal principal) throws InternalErrorException {
		if (principal.getUser() == null &&
				this.getUsersManagerBl() != null &&
				!dontLookupUsersForLogins.contains(principal.getActor())) {
			// Get the user if we are completely initialized
{'fraction_non_alphanumeric': 0.08868556934504937, 'fraction_numerical': 0.00036235166228825073, 'mean_word_length': 6.220405493786789, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5109180', 'n_tokens_mistral': 3465, 'n_tokens_neox': 3386, 'n_words': 651}