import java.security.Principal; ... // Get the current user Principal currentUser = request.getUserPrincipal(); // Get the user's name String userName = currentUser.getName(); // Print the user's name System.out.println("User name: " + userName);In this example, we're using the Principal interface to get the current user associated with an HTTP request. Then, we call the getName() method on that object to retrieve the user's name. This example code is using the Java standard library package `java.security` which provides security utilities such as these authentication-related classes.