First the question, then the explanation: I want to get rid of the Beans XML configuration and add some info to my EJB contexts.
I've here in my project (web part of the project) a class named StatelessEjbSupportLocal
which extends LocalStatelessSessionProxyFactoryBean
and this is the implementation:
public class StatelessEjbSupportLocal
extends LocalStatelessSessionProxyFactoryBean {
private UserInfo userInfo;
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
FacesContext context = FacesContext.getCurrentInstance();
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.security.jndi.JndiLoginInitialContextFactory");
properties.put(Context.PROVIDER_URL, "jnp://localhost:1099/");
properties.put(Context.SECURITY_PRINCIPAL,
userInfo.getLogin() + ";" + userInfo.getHost());
properties.put(Context.SECURITY_CREDENTIALS, userInfo.getIdUser());
super.setJndiEnvironment(properties);
refreshHome();
}
public UserInfo getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
}
And I have on my apps.xml
with the beans configuration:
(...)
<context:annotation-config/>
<context:component-scan base-package="my.package.controller" />
<bean id="someBusiness" class="my.package.StatelessEjbSupportLocal">
<property name="jndiName" value="SomeBusinessImpl/local" />
<property name="businessInterface" value="my.package.business.SomeBusiness" />
<property name="userInfo" ref="userInfo" />
</bean>
(...)
My web.xml has the configuration to load the above xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:apps.xml</param-value>
</context-param>
My UserInfo
class is annotated with @Component
and is filled on my SecurityFilter
(configured on my web.xml as a filter) after the users login. I set the host, login and the id there and put it on the session.
It is all working fine. I have this because I set the user on the EJB SessionContext to get this info on an Interceptor on my Business (services) classes. That way I don't need to handed pass the user info to all my business implementations (I need this because on my connection I set the user info to the database with a procedure like some kind of pre-connection configuration to audit purposes).
What I would like to do is to get rid of the beans
XML configuration on my apps.xml
. In other words some kind of interceptor to this LocalStatelessSessionProxyFactoryBean that would set the UserInfo without the need of <property name="userInfo" ref="userInfo" />
on every bean configuration.
Since I can have my apps.xml
with just this:
<context:annotation-config/>
<context:component-scan base-package="my.package.controller" />
And my SomeBusiness
attribute on my managed bean annotated with @Autowired
will work just fine.
Let me know if you need more information and I will edit this question with it.
Thanks in advance.