Hello,
I’m a new vaadin user and I try to make vaadin-cdi + jaas working.
I’ve done a very simple project to test my implementation but it doesn’t work.
my pom.xml :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>vaadin.jaas.cdi</groupId>
<artifactId>testjaascdi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<vaadin.version>7.3.8</vaadin.version>
<vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
<repository>
<id>sonatype vaadin</id>
<url>https://oss.sonatype.org/content/repositories/vaadin/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
<version>${vaadin.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
<version>${vaadin.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
<version>${vaadin.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-cdi</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
my web.xml :
[code]
<?xml version="1.0" encoding="UTF-8"?>
MainUIConstraint
MainUI
The authenticated part of the app
/main/*
Only valid users are allowed
admin
FORM
ApplicationRealm
/login
/login
admin
[/code]LoginUI :
[code]
package testjaascdi;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Inject;
import com.vaadin.cdi.CDIUI;
import com.vaadin.cdi.access.JaasAccessControl;
import com.vaadin.server.Page;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Notification;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings(“serial”)
@CDIUI
public class LoginUI extends UI {
private static final Logger LOG = Logger.getLogger(LoginUI.class.getName());
private TextField mUsernameField = new TextField("username");
private PasswordField mPasswordField = new PasswordField("password");
private Button mLoginButton = new Button("login");
@Inject
private JaasAccessControl service;
@Override
public void init(VaadinRequest pRequest) {
mLoginButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(Button.ClickEvent pEvent) {
try {
JaasAccessControl.login(mUsernameField.getValue(), mPasswordField.getValue());
Page lPage = Page.getCurrent();
lPage.setLocation("main");
} catch (Exception lE) {
Notification.show("FAILED");
LOG.log(Level.SEVERE, null, lE);
}
}
});
if (service.isUserSignedIn()) {
Page lPage = Page.getCurrent();
lPage.setLocation("main");
} else {
setContent(new VerticalLayout(mUsernameField, mPasswordField, mLoginButton));
mUsernameField.selectAll();
}
}
}
[/code]MainUI :
[code]
package testjaascdi;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.servlet.ServletException;
import com.vaadin.cdi.CDIUI;
import com.vaadin.cdi.access.JaasAccessControl;
import com.vaadin.server.Page;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings(“serial”)
@CDIUI
public class MainUI extends UI {
private Button logoutButton;
private static final Logger LOG = Logger.getLogger(MainUI.class.getName());
@Inject
private JaasAccessControl service;
@Override
protected void init(final VaadinRequest request) {
logoutButton = new Button("logout");
logoutButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
JaasAccessControl.logout();
getUI().getSession().close();
VaadinService.getCurrentRequest().getWrappedSession().invalidate();
Page lPage = Page.getCurrent();
lPage.setLocation(VaadinService.getCurrentRequest().getContextPath());
} catch (ServletException e) {
e.printStackTrace();
}
}
});
VerticalLayout layout = new VerticalLayout();
layout.addComponent(new Label(String.format("Bienvenue %s", service.getPrincipalName())));
if (service.isUserSignedIn()) {
layout.addComponent(logoutButton);
}
setContent(layout);
LOG.info("init mainUI");
}
}
[/code]The idea : a login UI, unsecure for the jEE server which redirect to mainUI (secure). Normally when a user try to access to the main UI directly without beeing authentified, the server intercept the request and must redirect to loginUI… in a perfect world. But in my case, the browser blocks in a page with a loading gif without redirecting to the login page.
Where I’m wrong with this very simple config ?
In the web.xml, can I redirect to the context root path “/” instead of “/login” ?
Thank you for your help.
Benoit.