bstlboard-back/src/main/java/de/bstly/board/controller/BaseController.java

53 lines
1.1 KiB
Java

/**
*
*/
package de.bstly.board.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import de.bstly.board.businesslogic.UserManager;
import de.bstly.board.model.LocalUser;
/**
* The Class BaseController.
*/
public class BaseController {
@Autowired
private UserManager localUserManager;
/**
* Authenticated.
*
* @return true, if successful
*/
protected boolean authenticated() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
return auth != null && auth.isAuthenticated();
}
/**
* Gets the current username.
*
* @return the current username
*/
protected String getCurrentUsername() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
return auth != null ? auth.getName() : null;
}
/**
* Gets the local user.
*
* @return the local user
*/
protected LocalUser getLocalUser() {
return localUserManager.getByAuth(SecurityContextHolder.getContext().getAuthentication());
}
}