orbeon-bluedb-integration/documents-explorer/src/main/java/eu/mooseinc/documents/explorer/bean/UserBean.java

42 lines
1.3 KiB
Java

/*********************************************************************************************************************************
* Autorskie Prawa Majątkowe - Moose Spółka z ograniczoną odpowiedzialnością
* Copyright 2019 Moose Spółka z ograniczoną odpowiedzialnością
********************************************************************************************************************************/
package eu.mooseinc.documents.explorer.bean;
import java.io.IOException;
import java.security.Principal;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
/**
* Bean for operations related to users.
*/
@SessionScoped
@ManagedBean(name = "UserBean")
public class UserBean {
/**
* Gets the username from the faces context.
*
* @return Name of the currently authenticated user.
*/
public String getUserName() {
final Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
return principal != null ? principal.getName() : "";
}
/**
* Logs out the user.
*
* @throws IOException Exception thrown during redirection.
*/
public void logout() throws IOException {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
FacesContext.getCurrentInstance().getExternalContext().redirect("index.jsp");
}
}