Vaadin-CDI & JAAS

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.

Here is the server log :

17:24:48,018 DEBUG [org.apache.tomcat.util.http.Cookies]
 (http-localhost-127.0.0.1-8080-1) Cookies: Parsing b[]: JSESSIONID=91X09bxln4-Jof+LNrkULTOZ.undefined
17:24:48,018 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-1) Security checking request GET /dashboard/ui
17:24:48,018 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-1)   Checking constraint 'SecurityConstraint[Main page]
' against GET /ui --> true
17:24:48,028 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-1)   Checking constraint 'SecurityConstraint[Main page]
' against GET /ui --> true
17:24:48,028 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-1)  Calling hasUserDataPermission()
17:24:48,028 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-1)   User data constraint has no restrictions
17:24:48,028 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-1)  Calling authenticate()
17:24:48,028 DEBUG [org.apache.catalina.authenticator.FormAuthenticator]
 (http-localhost-127.0.0.1-8080-1) Save request in session '91X09bxln4-Jof+LNrkULTOZ.undefined'
17:24:48,039 DEBUG [org.apache.tomcat.util.http.Parameters]
 (http-localhost-127.0.0.1-8080-1) Set encoding to ISO-8859-1
17:24:48,049 DEBUG [org.apache.catalina.core.ContainerBase.[jboss.web]
.[default-host]
.
[/dashboard].[VaadinServlet]
] (http-localhost-127.0.0.1-8080-1)  Disabling the response for futher output
17:24:48,049 DEBUG [org.apache.catalina.core.ContainerBase.[jboss.web]
.[default-host]
.
[/dashboard].[VaadinServlet]
] (http-localhost-127.0.0.1-8080-1)  The Response is vehiculed using a wrapper: org.apache.catalina.connector.Response
17:24:48,049 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-1)  Failed authenticate() test
17:24:48,109 DEBUG [org.apache.tomcat.util.http.Cookies]
 (http-localhost-127.0.0.1-8080-1) Cookies: Parsing b[]: JSESSIONID=91X09bxln4-Jof+LNrkULTOZ.undefined
17:24:48,109 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-1) Security checking request GET /dashboard/VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/com.vaadin.DefaultWidgetSet.nocache.js
17:24:48,109 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-1)   Checking constraint 'SecurityConstraint[Main page]
' against GET /VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/com.vaadin.DefaultWidgetSet.nocache.js --> false
17:24:48,109 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-1)   Checking constraint 'SecurityConstraint[Main page]
' against GET /VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/com.vaadin.DefaultWidgetSet.nocache.js --> false
17:24:48,109 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-1)   Checking constraint 'SecurityConstraint[Main page]
' against GET /VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/com.vaadin.DefaultWidgetSet.nocache.js --> false
17:24:48,109 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-1)   Checking constraint 'SecurityConstraint[Main page]
' against GET /VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/com.vaadin.DefaultWidgetSet.nocache.js --> false
17:24:48,109 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-1)   No applicable constraint located
17:24:48,109 DEBUG [org.apache.tomcat.util.http.Cookies]
 (http-localhost-127.0.0.1-8080-2) Cookies: Parsing b[]: JSESSIONID=91X09bxln4-Jof+LNrkULTOZ.undefined
17:24:48,109 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-1)  Not subject to any constraint
17:24:48,119 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-2) Security checking request POST /dashboard/ui
17:24:48,119 FIN   [com.vaadin.server.VaadinServlet]
 (http-localhost-127.0.0.1-8080-1) Accepted access to a file using a class loader: vfs:/C:/Users/Benoit/Documents/logiciels/jboss-as-7.1.1.Final/standalone/deployments/dashboard.war/WEB-INF/lib/vaadin-client-compiled-7.3.8.jar/VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/com.vaadin.DefaultWidgetSet.nocache.js
17:24:48,119 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-2)   Checking constraint 'SecurityConstraint[Main page]
' against POST /ui --> true
17:24:48,119 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-2)   Checking constraint 'SecurityConstraint[Main page]
' against POST /ui --> true
17:24:48,119 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-2)  Calling hasUserDataPermission()
17:24:48,119 DEBUG [org.apache.catalina.realm.RealmBase]
 (http-localhost-127.0.0.1-8080-2)   User data constraint has no restrictions
17:24:48,119 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-2)  Calling authenticate()
17:24:48,129 DEBUG [org.apache.catalina.authenticator.FormAuthenticator]
 (http-localhost-127.0.0.1-8080-2) Save request in session '91X09bxln4-Jof+LNrkULTOZ.undefined'
17:24:48,129 DEBUG [org.apache.tomcat.util.http.Parameters]
 (http-localhost-127.0.0.1-8080-2) Set encoding to UTF-8
17:24:48,129 DEBUG [org.apache.tomcat.util.http.Parameters]
 (http-localhost-127.0.0.1-8080-2) Decoding query null null
17:24:48,129 DEBUG [org.apache.tomcat.util.http.Parameters]
 (http-localhost-127.0.0.1-8080-2) Start processing with input [v-1421339088089]

17:24:48,129 DEBUG [org.apache.tomcat.util.http.Parameters]
 (http-localhost-127.0.0.1-8080-2) Parameter starting at position [0]
 and ending at position [15]
 with a value of [0]
 was not followed by an = character
17:24:48,129 DEBUG [org.apache.catalina.core.ContainerBase.[jboss.web]
.[default-host]
.
[/dashboard].[VaadinServlet]
] (http-localhost-127.0.0.1-8080-2)  Disabling the response for futher output
17:24:48,129 DEBUG [org.apache.catalina.core.ContainerBase.[jboss.web]
.[default-host]
.
[/dashboard].[VaadinServlet]
] (http-localhost-127.0.0.1-8080-2)  The Response is vehiculed using a wrapper: org.apache.catalina.connector.Response
17:24:48,139 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase]
 (http-localhost-127.0.0.1-8080-2)  Failed authenticate() test

Any suggestion ?

Does anyone succed to make jaas working with vaadin ?? I tried many and many solutions, no one work (redirect correctly to login UI).
I tried
this project
without modification and it’s the same : don’t work => “Failed to load the bootstrap javascript: ./VAADIN/vaadinBootstrap.js”

Please help !

Latest versions of vaadin-cdi needs an empty string in @CDIUI, like
@CDIUI(“”)

Can’t see any sign of weld in your tomcat-log. Which cdi-implementation do you use?

Even though it’s a bit old-fashioned I find it easier to just use an appserver like wildfly instead of manually crafting the applications stack.

There is a vaadin-app called rating-star on github, it’s a good startingpoint.