aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/security/entities
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/security/entities')
-rw-r--r--juick-server/src/main/java/com/juick/server/security/entities/AnonymousUser.java132
-rw-r--r--juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java74
2 files changed, 0 insertions, 206 deletions
diff --git a/juick-server/src/main/java/com/juick/server/security/entities/AnonymousUser.java b/juick-server/src/main/java/com/juick/server/security/entities/AnonymousUser.java
deleted file mode 100644
index 5ee9527f..00000000
--- a/juick-server/src/main/java/com/juick/server/security/entities/AnonymousUser.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package com.juick.server.security.entities;
-
-import com.juick.User;
-
-/**
- * Created by aalexeev on 12/11/16.
- */
-public final class AnonymousUser extends User {
- public static final AnonymousUser INSTANCE = new AnonymousUser();
-
- private AnonymousUser() {
- super.setUid(getUid());
- super.setName(getName());
- super.setAvatar(getAvatar());
- super.setFullName(getFullName());
- super.setJid(getJid());
- super.setMessagesCount(getMessagesCount());
- super.setAuthHash(getAuthHash());
- super.setBanned(isBanned());
- super.setCredentials(getCredentials());
- super.setLang(getLang());
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj == this || obj instanceof AnonymousUser;
- }
-
- @Override
- public int getUid() {
- return 0;
- }
-
- @Override
- public String getName() {
- return "Anonymous";
- }
-
- @Override
- public String getFullName() {
- return getName();
- }
-
- @Override
- public String getJid() {
- return "anonym@localhost";
- }
-
- @Override
- public String getAuthHash() {
- return null;
- }
-
- @Override
- public Integer getUnreadCount() {
- return 0;
- }
-
- @Override
- public boolean isBanned() {
- return false;
- }
-
- @Override
- public Object getAvatar() {
- return null;
- }
-
- @Override
- public String getCredentials() {
- return null;
- }
-
- @Override
- public String getLang() {
- return "__";
- }
-
- @Override
- public int getMessagesCount() {
- return 0;
- }
-
- @Override
- public boolean isAnonymous() {
- return true;
- }
-
- @Override
- public void setUid(int uid) {
- }
-
- @Override
- public void setName(String name) {
- }
-
- @Override
- public void setFullName(String fullName) {
- }
-
- @Override
- public void setJid(String jid) {
- }
-
- @Override
- public void setAuthHash(String authHash) {
- }
-
- @Override
- public void setUnreadCount(Integer count) {
- }
-
- @Override
- public void setBanned(boolean banned) {
- }
-
- @Override
- public void setAvatar(Object avatar) {
- }
-
- @Override
- public void setCredentials(String credentials) {
- }
-
- @Override
- public void setLang(String lang) {
- }
-
- @Override
- public void setMessagesCount(int messagesCount) {
- }
-}
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
deleted file mode 100644
index b86d94dd..00000000
--- a/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java
+++ /dev/null
@@ -1,74 +0,0 @@
-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;
-import java.util.List;
-
-/**
- * Created by aalexeev on 11/21/16.
- */
-public class JuickUser implements UserDetails {
- static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
- static final GrantedAuthority ROLE_ANONYMOUS = new SimpleGrantedAuthority("ROLE_ANONYMOUS");
-
- public static final List<GrantedAuthority> USER_AUTHORITY = Collections.singletonList(ROLE_USER);
- public static final List<GrantedAuthority> ANONYMOUS_AUTHORITY = Collections.singletonList(ROLE_ANONYMOUS);
-
- public static final JuickUser ANONYMOUS_USER = new JuickUser(AnonymousUser.INSTANCE, ANONYMOUS_AUTHORITY);
-
- private final com.juick.User user;
- private final Collection<? extends GrantedAuthority> authorities;
-
- public JuickUser(com.juick.User user) {
- this(user, USER_AUTHORITY);
- }
-
- public JuickUser(com.juick.User user, Collection<? extends GrantedAuthority> authorities) {
- this.user = user;
- this.authorities = authorities;
- }
-
- @Override
- public Collection<? extends GrantedAuthority> getAuthorities() {
- return authorities;
- }
-
- @Override
- public String getPassword() {
- return user.getCredentials();
- }
-
- @Override
- public String getUsername() {
- return user.getName();
- }
-
- @Override
- public boolean isAccountNonExpired() {
- return true;
- }
-
- @Override
- public boolean isAccountNonLocked() {
- return true;
- }
-
- @Override
- public boolean isCredentialsNonExpired() {
- return true;
- }
-
- @Override
- public boolean isEnabled() {
- return !user.isBanned();
- }
-
- public User getUser() {
- return user;
- }
-}