From 91a07facc6e4417810cebbfe017a4ac167ac13b1 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Sat, 26 Nov 2016 04:34:57 +0700 Subject: some improvenments on user service --- juick-server/src/main/java/com/juick/util/UserUtils.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'juick-server/src/main/java/com/juick/util') diff --git a/juick-server/src/main/java/com/juick/util/UserUtils.java b/juick-server/src/main/java/com/juick/util/UserUtils.java index 611a3b15..372dd502 100644 --- a/juick-server/src/main/java/com/juick/util/UserUtils.java +++ b/juick-server/src/main/java/com/juick/util/UserUtils.java @@ -1,5 +1,6 @@ package com.juick.util; +import java.security.Principal; import java.util.Random; /** @@ -24,4 +25,8 @@ public class UserUtils { public static boolean checkUserNameValid(final String uname) { return uname != null && uname.length() >= 2 && uname.length() <= 16 && uname.matches("[a-zA-Z0-9\\-]+"); } + + public static String getUsername(final Principal principal, final String defaultUsername) { + return principal == null ? defaultUsername : principal.getName(); + } } -- cgit v1.2.3