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/entities/AnonymUser.java132
-rw-r--r--juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java18
2 files changed, 147 insertions, 3 deletions
diff --git a/juick-server/src/main/java/com/juick/server/security/entities/AnonymUser.java b/juick-server/src/main/java/com/juick/server/security/entities/AnonymUser.java
new file mode 100644
index 00000000..2cc692a2
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/server/security/entities/AnonymUser.java
@@ -0,0 +1,132 @@
+package com.juick.server.security.entities;
+
+import com.juick.User;
+
+/**
+ * Created by aalexeev on 12/11/16.
+ */
+public final class AnonymUser extends User {
+ public static final AnonymUser INSTANCE = new AnonymUser();
+
+ private AnonymUser() {
+ 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 AnonymUser;
+ }
+
+ @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 isAnonym() {
+ 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
index f6d27ddf..596c95d1 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
@@ -7,23 +7,35 @@ 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 {
- public static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
- public static final Collection<? extends GrantedAuthority> USER_AUTHORITY = Collections.singletonList(ROLE_USER);
+ static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
+ static final GrantedAuthority ROLE_ANONYM = new SimpleGrantedAuthority("ROLE_ANONYM");
+
+ public static final List<GrantedAuthority> USER_AUTHORITY = Collections.singletonList(ROLE_USER);
+ public static final List<GrantedAuthority> ANONYM_AUTHORITY = Collections.singletonList(ROLE_ANONYM);
+
+ public static final JuickUser ANONYM_USER = new JuickUser(AnonymUser.INSTANCE, ANONYM_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 USER_AUTHORITY;
+ return authorities;
}
@Override