Crowlix
Crowlix

Reputation: 1269

GWT: EntityManager NullPointerException

I am using GWT with the SmartGWT library to make an application and I deploy this on a JBoss server. To authenticate my users, I made a JPA Entity and a ManagerBean. However, when I try to use the EntityManager in this ManagerBean, I get a NullPointerException. The EntityManager works in every other class, but not in the AppUser class.

Code from AppUserManagerBean:

@PersistenceContext(unitName = "test")
private EntityManager em;

private Logger logger = Logger.getLogger("be.test.server.AppUserManagerBean");

public boolean checkUser(String username,String password){

    logger.info("ENTITY MANAGER: " + em.toString());
    AppUser user = null;
    Query query = em.createQuery("SELECT OBJECT(a) FROM AppUser a WHERE a.username = :username AND a.password = :password");
    query.setParameter("username", username);
    query.setParameter("password", password);

Error logs:

java.lang.NullPointerException
    be.test.server.auth.AppUserManagerBean.checkUser(AppUserManagerBean.java:23)
    be.test.server.auth.CustomAuthenticationProvider.authenticate(CustomAuthenticationProvider.java:29)
    org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:130)
    org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
    org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:148)
    org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
    org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:97)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)

I am aware this probably isn't enough info, so feel free to ask me for more in the comments.

Thanks in advance.

Upvotes: 0

Views: 288

Answers (1)

mojoo-de
mojoo-de

Reputation: 481

make sure AppUserManagerBean is also instantiated by the container and not by yourself.

Upvotes: 2

Related Questions