ncb.setName(authentication.getPrincipal().toString());
String username = "";  Object principal = authentication.getPrincipal(); if (principal instanceof UserDetails) { username = ((UserDetails) principal).getUsername(); } else { username = principal.toString(); }  ncb.setName(username);
    public void handle(Callback callback, Authentication authentication)        throws IOException, UnsupportedCallbackException {        if (callback instanceof NameCallback) {            NameCallback ncb = (NameCallback) callback;            ncb.setName(authentication.getPrincipal().toString());        }    }