[jboss-jira] [JBoss JIRA] (WFLY-3314) LoginContext does not propagate Login

Darran Lofthouse (JIRA) issues at jboss.org
Mon Sep 22 13:09:03 EDT 2014


     [ https://issues.jboss.org/browse/WFLY-3314?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Darran Lofthouse resolved WFLY-3314.
------------------------------------
    Fix Version/s: 9.0.0.Beta1
       Resolution: Rejected


This is an issue that needs discussing in the forums.

> LoginContext does not propagate Login
> -------------------------------------
>
>                 Key: WFLY-3314
>                 URL: https://issues.jboss.org/browse/WFLY-3314
>             Project: WildFly
>          Issue Type: Bug
>            Reporter: Markus D
>            Assignee: Darran Lofthouse
>             Fix For: 9.0.0.Beta1
>
>
> I am trying to do a manual login in an EJB like the Servlet Request offers.
> So far so good. I implemented the CallbackHandler:
> public class PasswordCallbackHandler implements CallbackHandler {
>     private String username;
>     private char[] password;
>     public PasswordCallbackHandler(String username, char[] password) {
>         super();
>         this.username = username;
>         this.password = password;
>     }
>     public void handle(Callback[] callbacks) throws IOException,
>             UnsupportedCallbackException {
>         if(callbacks == null) {
>             return;
>         }
>         for (int i = 0; i < callbacks.length; i++) {
>             if (callbacks[i] instanceof NameCallback) {
>                 NameCallback nc = (NameCallback) callbacks[i];
>                 nc.setName(username);
>             } else if (callbacks[i] instanceof PasswordCallback) {
>                 PasswordCallback pc = (PasswordCallback) callbacks[i];
>                 pc.setPassword(password);
>             } else {
>                 throw new UnsupportedCallbackException(callbacks[i],
>                         "Unrecognized Callback");
>             }
>         }
>     }
> }
> My Code:
>     PasswordCallbackHandler handler = new PasswordCallbackHandler("user", "password".toCharArray());
>     LoginContext context = new LoginContext("realm", handler);
>     context.login();
> The subject shows:
> Subject:
>     Principal: user
>     Principal: Roles(members:ADMIN,USER)
>     Principal: CallerPrincipal(members:user)
> So the login itself worked. My Question now is what am I doing with it? When I fetch the current principal from the container I still receive anonymous. Tested on JBoss 7.1 and Wildfly.
>     @Resource
>     private SessionContext ctx;
> Principal callerPrincipal = ctx.getCallerPrincipal();
> if(callerPrincipal == null) {
>     return null;
> }
> String name = callerPrincipal.getName(); // Also after login() it returns anonymous.
> So did I misunderstood this functionality or should the container set the principal to the user I logged in?



--
This message was sent by Atlassian JIRA
(v6.3.1#6329)


More information about the jboss-jira mailing list