From 55b09a6a3bc4a21201189d855e140308f05016fb Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 25 Nov 2016 13:20:15 +0300 Subject: juick-api: security WIP --- .../juick/server/security/entities/JuickUser.java | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java (limited to 'juick-server/src/main/java/com/juick/server/security/entities') 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 new file mode 100644 index 00000000..6cc002ae --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java @@ -0,0 +1,62 @@ +package com.juick.server.security.entities; + +import com.juick.User; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; +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"); + + private final com.juick.User user; + + + public JuickUser(com.juick.User user) { + this.user = user; + } + + @Override + public Collection getAuthorities() { + return Collections.singletonList(ROLE_USER); + } + + @Override + public String getPassword() { + return null; + } + + @Override + public String getUsername() { + return user.getName(); + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return false; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return !user.isBanned(); + } + + public User getUser() { + return user; + } +} -- cgit v1.2.3