<commit_before>/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2011 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */

package org.geomajas.internal.security;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.geomajas.annotation.Api;
import org.geomajas.configuration.LayerInfo;
import org.geomajas.layer.Layer;
import org.geomajas.layer.VectorLayer;
import org.geomajas.layer.feature.InternalFeature;
import org.geomajas.security.AreaAuthorization;
import org.geomajas.security.AttributeAuthorization;
import org.geomajas.security.Authentication;
import org.geomajas.security.AuthorizationNeedsWiring;
import org.geomajas.security.BaseAuthorization;
import org.geomajas.security.FeatureAuthorization;
import org.geomajas.security.SavedAuthentication;
import org.geomajas.security.SavedAuthorization;
import org.geomajas.security.SecurityContext;
import org.geomajas.security.VectorLayerSelectFilterAuthorization;
import org.geomajas.service.ConfigurationService;
import org.geomajas.service.DtoConverterService;
import org.geomajas.service.FilterService;
import org.geomajas.service.GeoService;
import org.opengis.filter.Filter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;

import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.PrecisionModel;

/**
 * {@link org.geomajas.security.SecurityContext} implementation.
 * <p/>
 * The security context is a thread scoped service which allows you to query the authorization details for the logged in
 * user.
 * 
 * @author <NAME>
 * @since 1.10.0
 */
@Api
@Component
@Scope(value = "thread", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class DefaultSecurityContext implements SecurityContext {

	private final Logger log = LoggerFactory.getLogger(DefaultSecurityContext.class);

	private List<Authentication> authentications = new ArrayList<Authentication>();

	private String token;

	private String id; // SecurityContext id

	// user info
	private String userId;

	private String userName;

	private Locale userLocale;

	private String userOrganization;

	private String userDivision;

	@Autowired
	private FilterService filterService;

	@Autowired
	private ConfigurationService configurationService;

	@Autowired
	private DtoConverterService converterService;

	@Autowired
	private GeoService geoService;

	@Autowired
	private ApplicationContext applicationContext;

	/**
	 * Set the token and authentications for this security context.
	 * <p/>
	 * This method can be overwritten to handle custom policies.
	 *
	 * @param token current token
	 * @param authentications authentications for token
	 */
	@Api
	public void setAuthentications(String token, List<Authentication> authentications) {
		this.token = token;
		this.authentications.clear();
		if (null != authentications) {
			for (Authentication auth : authentications) {
				for (BaseAuthorization ba : auth.getAuthorizations()) {
					if (ba instanceof AuthorizationNeedsWiring) {
						((AuthorizationNeedsWiring) ba).wire(applicationContext);
					}
				}
				this.authentications.add(auth);
			}
		}
		userInfoInit();
	}

	/**
	 * @inheritDoc
	 */
	public List<Authentication> getSecurityServiceResults() {
		return authentications;
	}<commit_msg>GBE-229 constructor needs to be api too (so make it explicit)<commit_after>/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2011 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */

package org.geomajas.internal.security;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.geomajas.annotation.Api;
import org.geomajas.configuration.LayerInfo;
import org.geomajas.layer.Layer;
import org.geomajas.layer.VectorLayer;
import org.geomajas.layer.feature.InternalFeature;
import org.geomajas.security.AreaAuthorization;
import org.geomajas.security.AttributeAuthorization;
import org.geomajas.security.Authentication;
import org.geomajas.security.AuthorizationNeedsWiring;
import org.geomajas.security.BaseAuthorization;
import org.geomajas.security.FeatureAuthorization;
import org.geomajas.security.SavedAuthentication;
import org.geomajas.security.SavedAuthorization;
import org.geomajas.security.SecurityContext;
import org.geomajas.security.VectorLayerSelectFilterAuthorization;
import org.geomajas.service.ConfigurationService;
import org.geomajas.service.DtoConverterService;
import org.geomajas.service.FilterService;
import org.geomajas.service.GeoService;
import org.opengis.filter.Filter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;

import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.PrecisionModel;

/**
 * {@link org.geomajas.security.SecurityContext} implementation.
 * <p/>
 * The security context is a thread scoped service which allows you to query the authorization details for the logged in
 * user.
 * 
 * @author <NAME>
 * @since 1.10.0
 */
@Api
@Component
@Scope(value = "thread", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class DefaultSecurityContext implements SecurityContext {

	private final Logger log = LoggerFactory.getLogger(DefaultSecurityContext.class);

	private List<Authentication> authentications = new ArrayList<Authentication>();

	private String token;

	private String id; // SecurityContext id

	// user info
	private String userId;

	private String userName;

	private Locale userLocale;

	private String userOrganization;

	private String userDivision;

	@Autowired
	private FilterService filterService;

	@Autowired
	private ConfigurationService configurationService;

	@Autowired
	private DtoConverterService converterService;

	@Autowired
	private GeoService geoService;

	@Autowired
	private ApplicationContext applicationContext;

	/**
	 * Default constructor.
	 *
	 * @since 1.10.0
	 */
	@Api
	public DefaultSecurityContext() {
		// method provided to be able to put @Api annotation on it
	}

	/**
	 * Set the token and authentications for this security context.
	 * <p/>
	 * This method can be overwritten to handle custom policies.
	 *
	 * @param token current token
	 * @param authentications authentications for token
	 */
	@Api
	public void setAuthentications(String token, List<Authentication> authentications) {
		this.token = token;
		this.authentications.clear();
		if (null != authentications) {
			for (Authentication auth : authentications) {
				for (BaseAuthorization ba : auth.getAuthorizations()) {
					if (ba instanceof AuthorizationNeedsWiring) {
						((AuthorizationNeedsWiring) ba).wire(applicationContext);
					}
				}
				this.authentications.add(auth);
			}
		}
		userInfoInit();
	}

	/**
	 * @inheritDoc
	 */
	public List<Authentication> getSecurityServiceResults() {
		return authentications;
	}
{'fraction_non_alphanumeric': 0.08894551632083485, 'fraction_numerical': 0.004247057395947094, 'mean_word_length': 5.206325301204819, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '143857', 'n_tokens_mistral': 2486, 'n_tokens_neox': 2314, 'n_words': 604}