[
https://jira.jboss.org/jira/browse/EJBTHREE-615?page=com.atlassian.jira.p...
]
asdfasdf ddd commented on EJBTHREE-615:
---------------------------------------
dear my friends , I have been counter with the same problem for 2 days, after learning the
security constract of ejb3 on jboss4, I finally find a esay way to solve this problem .
add
props.setProperty(Context.SECURITY_PRINCIPAL, "myuserid");
to your client program ...
then in the bean class
ctx.getCallerPrincipal();
will return "myuserid" which the client program determined above.
my client program is like this ..
Properties props=new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.security.jndi.JndiLoginInitialContextFactory");
props.setProperty(Context.PROVIDER_URL, "localhost:1099");
props.setProperty(Context.SECURITY_PRINCIPAL, "myuserid");//here!!!!!!!!!!!
InitialContext ctx=new InitialContext(props);
saha ss=(saha)ctx.lookup("sahabean/remote");
ss.sayhi();
my bean class is like this ..
@Stateful
@Remote({saha.class})
public class sahabean implements saha {
@Resource SessionContext ctx;
public String sayhi() {
System.out.println(ctx.getCallerPrincipal());//no exceptions now..
return "success";
}
}
remote interface "saha" is like this ..
public interface saha {
public String sayhi();
}
after deployed sahabean on jboss-4.2.3.GA-jdk6 and run client program, you can see the
output "myuserid" on your jboss command console.
i am confident that this code can normally run on jboss5 too.
best regards ..
NPE in Embedded Jboss when getCallerPrincipal method on
SessionContext
----------------------------------------------------------------------
Key: EJBTHREE-615
URL:
https://jira.jboss.org/jira/browse/EJBTHREE-615
Project: EJB 3.0
Issue Type: Bug
Affects Versions: EJB 3.0 RC8 - FD
Reporter: Nicolai ?dum
Assignee: Carlo de Wolf
Attachments: BugReportInterceptor.java
The bug is pretty easy to create.
Modify the CalculaterBean in the security example that is distributed with JBoss embedded
like this
import javax.annotation.Resource;
import java.security.Principal;
import javax.ejb.SessionContext;
..
public class CalculatorBean implements Calculator
{
@Resource SessionContext ctx;
@RolesAllowed({"student"})
public int subtract(int x, int y)
{
Principal caller = ctx.getCallerPrincipal(); //Nullpointer
return x - y;
}
The exception
full stacktrace:
javax.ejb.EJBException: java.lang.NullPointerException
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at
org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at
org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:167)
at
org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:100)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at
org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at
org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
at $Proxy15.getSubscriberDetails(Unknown Source)
Another user has reported that is is possible to get the principal from
org.jboss.security.SecurityAssociation.getPrincipal(), but not from the Session Context.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira