diff --git a/chatto/src/main/java/org/ros/chatto/security/CustomBasicAuthenticationFilter.java b/chatto/src/main/java/org/ros/chatto/security/CustomBasicAuthenticationFilter.java index b016726..83e245c 100644 --- a/chatto/src/main/java/org/ros/chatto/security/CustomBasicAuthenticationFilter.java +++ b/chatto/src/main/java/org/ros/chatto/security/CustomBasicAuthenticationFilter.java @@ -1,8 +1,6 @@ package org.ros.chatto.security; import org.ros.chatto.model.UserToken; -import org.ros.chatto.repository.UserRepository; -import org.ros.chatto.service.UserService; import org.ros.chatto.service.UserTokenService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; @@ -15,14 +13,10 @@ import org.springframework.stereotype.Component; @Component public class CustomBasicAuthenticationFilter extends BasicAuthenticationFilter { - @Autowired - private UserService userService; @Autowired private TokenService tokenService; @Autowired private UserTokenService userTokenService; - @Autowired - private UserRepository userRepository; @Autowired public CustomBasicAuthenticationFilter(final AuthenticationManager authenticationManager) { @@ -35,7 +29,7 @@ public class CustomBasicAuthenticationFilter extends BasicAuthenticationFilter { // Generate Token // Save the token for the logged in user // send token in the response - UserToken userToken = userTokenService.getToken(authResult.getName()); + UserToken userToken = userTokenService.getTokenByUserName(authResult.getName()); Token token; if (userToken == null) { token = tokenService.allocateToken(""); diff --git a/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java b/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java index 13b2477..1276b00 100644 --- a/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java +++ b/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java @@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest; import org.ros.chatto.model.UserToken; import org.ros.chatto.repository.TokenRepository; import org.ros.chatto.repository.UserRoleRepository; +import org.ros.chatto.service.UserTokenService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -28,10 +29,10 @@ import org.springframework.web.filter.GenericFilterBean; public class TokenAuthenticationFilter extends GenericFilterBean { @Autowired - UserRoleRepository userRoleRepository; - + private TokenRepository tokenRepository; + @Autowired - TokenRepository tokenRepository; + private UserTokenService userTokenService; @Autowired TokenService tokenService; @@ -51,7 +52,7 @@ public class TokenAuthenticationFilter extends GenericFilterBean { if (token == null) { throw new UsernameNotFoundException("Token not issued by us"); } - UserToken userToken = tokenRepository.findByToken(accessToken); + UserToken userToken = userTokenService.getTokenByTokenString(accessToken); if (userToken == null) { throw new UsernameNotFoundException("Token not associated with any user"); diff --git a/chatto/src/main/java/org/ros/chatto/service/UserTokenService.java b/chatto/src/main/java/org/ros/chatto/service/UserTokenService.java index de584c5..95e2c52 100644 --- a/chatto/src/main/java/org/ros/chatto/service/UserTokenService.java +++ b/chatto/src/main/java/org/ros/chatto/service/UserTokenService.java @@ -15,11 +15,16 @@ public class UserTokenService { // @Cacheable - public UserToken getToken(String userName) + public UserToken getTokenByUserName(String userName) { return tokenRepository.findByUserName(userName); } + public UserToken getTokenByTokenString(String tokenString) + { + return tokenRepository.findByToken(tokenString); + } + @Transactional public void saveToken(UserToken userToken) {