Session scoped bean behaves as Request scope bean

514 views Asked by At

I have Session scope bean which behaves as request scope bean.

I'm using it in Singleton bean, and maybe that's why with second request is has null values? Code which I used to setup the bean: In singleton:

@Autowired
private MyBean myBean;

MyBean class:

@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public class MyBeanImpl implements MyBean, Serializable {

Configuration:

@Configuration
@ComponentScan(scopedProxy = ScopedProxyMode.INTERFACES, value = {  "my.package.with.bean" })
public class ComponentsConfig {
}

MyBean is simple pojo. with getters and setters. With first request I set values on that bean, with second request in the same class (singleton) I want to read those values, but all values are null. There is no way that something has overrdiden those values.

EDIT How I make requests - It's just simple browser request, and code which read/writes to my session bean lays in filters.

This is singleton:

@Service
public class SingletonBean {

    @Autowired
    private MyBean myBean;
// here I save the data to session scoped bean
    private void saveUser(LdapContext ctx, String principal) throws NamingException {
        Attributes attributes = getAttributes();
        myBean.setId("id");
        myBean.setName("name");
        myBean.setEmail("email");
        myBean.setTelNum("123");
        myBean.setGroups(Lists.newArrayList("one", "two"));
        myBean.setAddress("address");
    }
// here I try to read data from session scoped bean:
    @Override
    protected AuthorizationInfo queryForAuthorizationInfo(PrincipalCollection principals,
            LdapContextFactory ldapContextFactory) throws NamingException {
       // here userInfo will be null
        List<String> userInfo =  myBean.getGroups();
        SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
        for (String role : userInfo ) {
            authorizationInfo.addRole(role);
        }
        return authorizationInfo;
}

}

When user logs in, and he is authenticated, I save his details in session bean. When he tries to open any page method queryForAuthorizationInfo is executed (after chain of filters) and values are null in that object.

0

There are 0 answers