You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by P82 <st...@mail.ru> on 2014/05/27 14:51:08 UTC

JavaEE 7 + EJB and standalone client - where is mistake in this code

Hello experts and shiro community. Since I got no answer how to use shiro for
standalone client I have to try to do it myself. Please consider the
following code. Where is my mistake?

I have an EJB with two methods - login() and check(). From a standalone
client I firstly call login() and after that I call check().

public void login(){
        Factory<SecurityManager> factory = new
IniSecurityManagerFactory("classpath:shiro.ini");
        SecurityManager securityManager = factory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
        Subject currentUser = SecurityUtils.getSubject();
        if ( !currentUser.isAuthenticated() ) {
            UsernamePasswordToken token = new
UsernamePasswordToken("lonestarr", "vespa");
            currentUser.login(token);
        }
       //if I call it here it ourputs "lonestarr"
      
System.out.println(SecurityUtils.getSubject().getPrincipal().toString()); 
}

public void check(){
    //if I call it here it throws  java.lang.NullPointerException  
   
System.out.println(SecurityUtils.getSubject().getPrincipal().toString()); 
}




--
View this message in context: http://shiro-user.582556.n2.nabble.com/JavaEE-7-EJB-and-standalone-client-where-is-mistake-in-this-code-tp7579983.html
Sent from the Shiro User mailing list archive at Nabble.com.