0

A named bean, listProjects, requires authentication which is provided by the container. I want to get the username from the named loginMBean and use it in the listProjects bean.

I have injected the authentication bean into listProjects, but when I access the username, it it null even though the user has authenticated.

@Named("loginMBean")
@SessionScoped
@PermitAll
public class LoginMBean implements Serializable {
private String username;

public String getUsername() {
    return username;
} 



@Named
@SessionScoped
@RolesAllowed({"Users"})
public class ListProjectsMBean implements Serializable {
@Inject
private LoginMBean wLoginMBean;

public void getList(ActionEvent actionEvent) {
        String testUserName = wLoginMBean.getUsername();
  l     
}

wildfly 8.2 weld 2.2 java 1.7

  • Are you sure that `username` field is not null after authentication? You should see "updated value" if you set the field with username after authentication. – Geinmachi Feb 21 '16 at 20:01
  • I think you are right. Apparently I wasn't actually using the authentication bean for authentication. While making changes eclipse caused me problems, so I can't really test it. Still working on it. – user3555047 Feb 21 '16 at 23:29

1 Answers1

0

The injection is ok, the username is probably not set that is why it is null.

Try to inject the principal in the ListProjectsMBean to see if the authentication was successful.

@Inject Principal principal;
simdevmon
  • 673
  • 7
  • 14
  • Both @Geinmachi and your comments were helpful. Geinmachi was first so I wanted to mark his comment as correct, but it appears that I can only check answers. – user3555047 Feb 21 '16 at 23:32