protected String getCurrentUsername() {
        Subject subject = SecurityUtils.getSubject();
        if (subject == null || subject.getPrincipal() == null || !subject.isAuthenticated()) {
            throw new IllegalStateException("Unable to retrieve the current authenticated subject");
        }
        return SecurityUtils.getSubject().getPrincipal().toString();
    }
Internal utility method to retrieve the username of the current authenticated user.

@return The name.
samples/aspectj/src/main/java/org/apache/shiro/samples/aspectj/bank/SecureBankService.java