aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/util/UserUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/util/UserUtils.java')
-rw-r--r--juick-server/src/main/java/com/juick/util/UserUtils.java49
1 files changed, 0 insertions, 49 deletions
diff --git a/juick-server/src/main/java/com/juick/util/UserUtils.java b/juick-server/src/main/java/com/juick/util/UserUtils.java
deleted file mode 100644
index 3d78b5b5..00000000
--- a/juick-server/src/main/java/com/juick/util/UserUtils.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.juick.util;
-
-import com.juick.User;
-import com.juick.server.security.entities.AnonymousUser;
-import com.juick.server.security.entities.JuickUser;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-import java.util.Random;
-
-/**
- * Created by aalexeev on 11/14/16.
- */
-public class UserUtils {
- private UserUtils() {
- throw new IllegalStateException();
- }
-
- private static final String ABCDEF = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
- public static String generateHash(final int len) {
- Random rnd = new Random();
- StringBuilder sb = new StringBuilder(len);
- for (int i = 0; i < len; i++) {
- sb.append(ABCDEF.charAt(rnd.nextInt(ABCDEF.length())));
- }
- return sb.toString();
- }
-
- public static Authentication getAuthentication() {
- return SecurityContextHolder.getContext().getAuthentication();
- }
-
- public static Object getPrincipal(final Authentication authentication) {
- return authentication == null ? null : authentication.getPrincipal();
- }
-
- public static User getCurrentUser() {
- Object principal = getPrincipal(getAuthentication());
-
- if (principal instanceof JuickUser)
- return ((JuickUser) principal).getUser();
-
- if (principal instanceof User)
- return (User) principal;
-
- return AnonymousUser.INSTANCE;
- }
-}