cz.muni.fi.pb138.cvmanager.controller.BaseController.java Source code

Java tutorial

Introduction

Here is the source code for cz.muni.fi.pb138.cvmanager.controller.BaseController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.cvmanager.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;

/**
 *
 * @author david
 */
@Controller
public class BaseController {

    /**
     * Finds out and returns name of currently logged in user
     *
     * @return name of currently logged in user
     */
    protected String getPrincipalUsername() {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        UserDetails userDetails = (UserDetails) auth.getPrincipal();
        return userDetails.getUsername();
    }

}