/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocelotds.core.services;

import java.security.Principal;
import java.util.Locale;
import java.util.Map;
import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.enterprise.inject.Any;
import javax.inject.Inject;
import javax.websocket.Session;
import org.ocelotds.Constants;
import org.ocelotds.context.ThreadLocalContextHolder;
import org.ocelotds.annotations.OcelotLogger;
import org.ocelotds.messaging.MessageFromClient;
import org.ocelotds.spi.security.SecurityContext;
import org.ocelotds.security.SecurityServices;
import org.slf4j.Logger;

/**
 *
 * @author hhfrancois
 */
@Decorator
public abstract class CallServiceDecorator implements CallService {

	@Inject
	@Delegate
	@Any
	CallService callSercice;

	@Inject
	@OcelotLogger
	private Logger logger;

	@Inject
	SecurityServices subjectServices;
	
	@Override
	public void sendMessageToClient(MessageFromClient message, Session session) {
		Map<String, Object> sessionProperties = session.getUserProperties();
		// Get subject from config and set in session
		final Principal principal = session.getUserPrincipal();
		ThreadLocalContextHolder.put(Constants.PRINCIPAL, principal);

		final Locale locale = (Locale) sessionProperties.get(Constants.LOCALE);
		ThreadLocalContextHolder.put(Constants.LOCALE, locale);

		// HERE WE SET THE SECURITY CONTEXT WITH SPECIFIC VENDOR IMPLEMENTATION
		final SecurityContext context = (SecurityContext) sessionProperties.get(Constants.SECURITY_CONTEXT);
		subjectServices.setSecurityContext(context);
		logger.debug("Decorate CallService for add context to session Principal : {}, Locale : {}", principal, locale);
		callSercice.sendMessageToClient(message, session);
	}
}

@@ -1173,16 +1173,83 @@
 ion) %7B%0D%0A
+%09%09System.out.println(%22CallServiceDecorator.sendMessageToClient%22);%0D%0A
 %09%09Map%3CSt
@@ -1312,16 +1312,16 @@
 ies();%0D%0A
-
 %09%09// Get
@@ -1491,83 +1491,8 @@
 %0D%0A%0D%0A
-%09%09final Locale locale = (Locale) sessionProperties.get(Constants.LOCALE);%0D%0A
 %09%09Th
@@ -1532,22 +1532,24 @@
 nts.
-LOCALE, locale
+SESSION, session
 );%0D%0A
@@ -1729,16 +1729,16 @@
 TEXT);%0D%0A
-
 %09%09subjec
@@ -1777,16 +1777,91 @@
 text);%0D%0A
+%09%09final Locale locale = (Locale) sessionProperties.get(Constants.LOCALE);%0D%0A
 %09%09logger

add session in TheadContext