Example usage for org.springframework.security.ldap.userdetails LdapUserDetails getUsername

List of usage examples for org.springframework.security.ldap.userdetails LdapUserDetails getUsername

Introduction

In this page you can find the example usage for org.springframework.security.ldap.userdetails LdapUserDetails getUsername.

Prototype

String getUsername();

Source Link

Document

Returns the username used to authenticate the user.

Usage

From source file:org.musicrecital.service.UserSecurityAdvice.java

private User getCurrentUser(Authentication auth, UserManager userManager) {
    User currentUser;// w  ww.j av a 2s.c  om
    if (auth.getPrincipal() instanceof LdapUserDetails) {
        LdapUserDetails ldapDetails = (LdapUserDetails) auth.getPrincipal();
        String username = ldapDetails.getUsername();
        currentUser = userManager.getUserByUsername(username);
    } else if (auth.getPrincipal() instanceof UserDetails) {
        currentUser = (User) auth.getPrincipal();
    } else if (auth.getDetails() instanceof UserDetails) {
        currentUser = (User) auth.getDetails();
    } else {
        throw new AccessDeniedException("User not properly authenticated.");
    }
    return currentUser;
}