package com.juick.util; import java.security.Principal; 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 String getUsername(final Principal principal, final String defaultUsername) { return principal == null ? defaultUsername : principal.getName(); } }