aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-rw-r--r--juick-server/src/main/java/com/juick/server/security/JuickAuthenticationProvider.java22
-rw-r--r--juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java6
2 files changed, 17 insertions, 11 deletions
diff --git a/juick-server/src/main/java/com/juick/server/security/JuickAuthenticationProvider.java b/juick-server/src/main/java/com/juick/server/security/JuickAuthenticationProvider.java
index bf0ed4d7..8d0bfddb 100644
--- a/juick-server/src/main/java/com/juick/server/security/JuickAuthenticationProvider.java
+++ b/juick-server/src/main/java/com/juick/server/security/JuickAuthenticationProvider.java
@@ -1,11 +1,13 @@
package com.juick.server.security;
+import com.juick.server.security.entities.JuickUser;
import com.juick.service.UserService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
import javax.inject.Inject;
import java.util.Collections;
@@ -14,18 +16,22 @@ import java.util.Collections;
* Created by vitalyster on 25.11.2016.
*/
public class JuickAuthenticationProvider implements AuthenticationProvider {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
@Inject
- UserService userService;
+ private UserService userService;
+
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
- if (userService.checkPassword(name, password) > 0) {
- return new UsernamePasswordAuthenticationToken(name, password, Collections.singletonList(
- new SimpleGrantedAuthority("ROLE_USER")
- ));
- }
- return null;
+
+ boolean isAuthenticated = userService.checkPassword(name, password) > 0;
+
+ logger.info("user {} authenticated: {}", name, isAuthenticated);
+
+ return isAuthenticated ?
+ new UsernamePasswordAuthenticationToken(name, password, JuickUser.USER_AUTHORITY) : null;
}
@Override
diff --git a/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java b/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java
index 6cc002ae..fd06b65b 100644
--- a/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java
+++ b/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java
@@ -12,18 +12,18 @@ import java.util.Collections;
* Created by aalexeev on 11/21/16.
*/
public class JuickUser implements UserDetails {
- private static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
+ public static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
+ public static final Collection<? extends GrantedAuthority> USER_AUTHORITY = Collections.singletonList(ROLE_USER);
private final com.juick.User user;
-
public JuickUser(com.juick.User user) {
this.user = user;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
- return Collections.singletonList(ROLE_USER);
+ return USER_AUTHORITY;
}
@Override