Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
How can I access shiro authentication information
Platform:
Java 1.8
karaf 4.0.7
pax web 4.3.0
shiro 1.3.1
vaadin 7.7.4
I have a web application where I'm trying out various Java web technologies and now the turn has come to vaadin.
The "using-vaadin" branch of my web application currently contains a vaadin hello world application that has been transformed from a shiro-basic-authenticated primefaces web application:
https://github.com/steinarb/ukelonn/tree/using-vaadin
My next step is to retrieve the shiro authentication information, but I have been unable to google up how to do this with vaadin 7. All examples and prior forum questions relate to vaadin 6.
How do I find the authenticated username? Is it somewhere in the session object? Do I need to create some kind of handler to listen to the http request? Where do I put it in the handler so that it is available in the UI.init() method?
Do my questions make sense when applied to vaadin...? :-)
Thanks!
- Steinar
I figured out how to access the current user from the init() method, use the static getSubject() method of the Shiro SecurityUtils class:
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
public class UkelonnUI extends UI {
private static final long serialVersionUID = 1388525490129647161L;
@Override
protected void init(VaadinRequest request) {
Subject currentUser = SecurityUtils.getSubject();
// Create the content root layout for the UI
VerticalLayout content = new VerticalLayout();
setContent(content);
// Display the greeting
content.addComponent(new Label("Hello " + currentUser.getPrincipal()))
It turned out to be a lot simpler than the above example: The VaadinRequest argument to the init() method contains the necessary information:
public class UkelonnUI extends UI {
@Override
protected void init(VaadinRequest request) {
Principal currentUser = request.getUserPrincipal();
// Create the content root layout for the UI
VerticalLayout content = new VerticalLayout();
setContent(content);
// Display the greeting
Component greeting = new Label("Hello " + currentUser.getName());
greeting.setStyleName("h1");
content.addComponent(greeting);