<commit_before>/*
 * Copyright 2017 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.b2international.snowowl.authorization.server;

import com.b2international.commons.platform.PlatformUtil;
import com.b2international.snowowl.authentication.AuthenticationConfiguration;
import com.b2international.snowowl.authorization.server.providers.IAuthorizationStrategy;
import com.b2international.snowowl.authorization.server.providers.file.FileBasedAuthorizationStrategy;
import com.b2international.snowowl.authorization.server.providers.ldap.LdapAuthorizationStrategy;
import com.b2international.snowowl.authorization.server.service.AdminPartyAuthorizationService;
import com.b2international.snowowl.authorization.server.service.AuthorizationService;
import com.b2international.snowowl.core.ApplicationContext;
import com.b2international.snowowl.core.api.SnowowlRuntimeException;
import com.b2international.snowowl.core.api.SnowowlServiceException;
import com.b2international.snowowl.core.config.SnowOwlConfiguration;
import com.b2international.snowowl.core.setup.DefaultBootstrapFragment;
import com.b2international.snowowl.core.setup.Environment;
import com.b2international.snowowl.core.setup.PreRunCapableBootstrapFragment;
import com.b2international.snowowl.core.users.IAuthorizationService;
import com.b2international.snowowl.rpc.RpcProtocol;
import com.b2international.snowowl.rpc.RpcUtil;

/**
 * @since 5.10.13
 */
public class AuthorizationBootstrap extends DefaultBootstrapFragment implements PreRunCapableBootstrapFragment {

	@Override
	public void preRun(SnowOwlConfiguration configuration, Environment env) {
		final IAuthorizationService service;
		if (!env.isEmbedded()) {
			// register proxy authorization service in embedded mode
			final RpcProtocol protocol = RpcUtil.getRpcClientProtocol(env.container());
			protocol.registerClassLoader(IAuthorizationService.class, IAuthorizationService.class.getClassLoader());
			service = protocol.getServiceProxy(IAuthorizationService.class);
		} else {
			final AuthenticationConfiguration authenticationConfiguration = configuration.getModuleConfig(AuthenticationConfiguration.class);
			service = createAuthorizationService(authenticationConfiguration);
		}
		ApplicationContext.getInstance().registerService(IAuthorizationService.class, service);
	}<commit_msg>[boot] register server side authorization service classloader properly<commit_after>/*
 * Copyright 2017 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.b2international.snowowl.authorization.server;

import org.eclipse.net4j.util.container.IPluginContainer;

import com.b2international.commons.platform.PlatformUtil;
import com.b2international.snowowl.authentication.AuthenticationConfiguration;
import com.b2international.snowowl.authorization.server.providers.IAuthorizationStrategy;
import com.b2international.snowowl.authorization.server.providers.file.FileBasedAuthorizationStrategy;
import com.b2international.snowowl.authorization.server.providers.ldap.LdapAuthorizationStrategy;
import com.b2international.snowowl.authorization.server.service.AdminPartyAuthorizationService;
import com.b2international.snowowl.authorization.server.service.AuthorizationService;
import com.b2international.snowowl.core.ApplicationContext;
import com.b2international.snowowl.core.api.SnowowlRuntimeException;
import com.b2international.snowowl.core.api.SnowowlServiceException;
import com.b2international.snowowl.core.config.SnowOwlConfiguration;
import com.b2international.snowowl.core.setup.DefaultBootstrapFragment;
import com.b2international.snowowl.core.setup.Environment;
import com.b2international.snowowl.core.setup.PreRunCapableBootstrapFragment;
import com.b2international.snowowl.core.users.IAuthorizationService;
import com.b2international.snowowl.rpc.RpcProtocol;
import com.b2international.snowowl.rpc.RpcSession;
import com.b2international.snowowl.rpc.RpcUtil;

/**
 * @since 5.10.13
 */
public class AuthorizationBootstrap extends DefaultBootstrapFragment implements PreRunCapableBootstrapFragment {

	@Override
	public void preRun(SnowOwlConfiguration configuration, Environment env) {
		final IAuthorizationService service;
		if (!env.isEmbedded()) {
			// register proxy authorization service in embedded mode
			final RpcProtocol protocol = RpcUtil.getRpcClientProtocol(env.container());
			protocol.registerClassLoader(IAuthorizationService.class, IAuthorizationService.class.getClassLoader());
			service = protocol.getServiceProxy(IAuthorizationService.class);
		} else {
			final AuthenticationConfiguration authenticationConfiguration = configuration.getModuleConfig(AuthenticationConfiguration.class);
			service = createAuthorizationService(authenticationConfiguration);
			final RpcSession session = RpcUtil.getInitialServerSession(IPluginContainer.INSTANCE);
			session.registerClassLoader(IAuthorizationService.class, service.getClass().getClassLoader());
		}
		ApplicationContext.getInstance().registerService(IAuthorizationService.class, service);
	}
{'fraction_non_alphanumeric': 0.08024186958653375, 'fraction_numerical': 0.011112926948847851, 'mean_word_length': 6.659574468085107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7494017', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1620, 'n_words': 351}