Giter VIP home page Giter VIP logo

vaadin-loginform's Introduction

Vaadin LoginForm

Usage

Vaadin LoginForm is an add-on for Vaadin. It requires at least Vaadin 7.3 Specifically it will not work with Vaadin 6. To use it, you have to compile your own widgetset, using the precompiled widget set will not work with this addon.

To create a login form that supports auto-completion and auto-fill for modern versions of Firefox, Chrome, IE and Safari, you can use the classes com.ejt.vaadin.loginform.DefaultVerticalLoginForm or com.ejt.vaadin.loginform.DefaultHorizontalLoginForm and add a listener to handle login events:

// Add the loginForm instance below to your UI
DefaultVerticalLoginForm loginForm = new DefaultVerticalLoginForm();
loginForm.addLoginListener(new LoginListener() {
    @Override
    public void onLogin(LoginEvent event) {
        System.err.println(
                "Logged in with user name " + event.getUserName() +
                        " and password of length " + event.getPassword().length());

    }
});

For arbitrary layouts, extend com.ejt.vaadin.loginform.LoginForm and implement createContent as well:

public abstract class MyLoginForm extends LoginForm {
    @Override
    protected Component createContent(TextField userNameField, PasswordField passwordField, Button loginButton) {
        HorizontalLayout layout = new HorizontalLayout();
        layout.setSpacing(true);
        layout.setMargin(true);

        layout.addComponent(userNameField);
        layout.addComponent(passwordField);
        layout.addComponent(loginButton);
        layout.setComponentAlignment(loginButton, Alignment.BOTTOM_LEFT);
        return layout;
    }

    // You can also override this method to handle the login directly, instead of using the event mechanism
    @Override
    protected void login(String userName, String password) {
        System.err.println(
            "Logged in with user name " + userName +
            " and password of length " + password.length()
        );
    }
}

The userNameField, passwordField and loginButton components are specially prepared to work with password managers. You can override createUserNameField, createPasswordField and createLoginButton to replace the components with your own implementations or to add styles. To change captions, you can override getUserNameFieldCaption, getPasswordFieldCaption and getLoginButtonCaption.

In technical terms, the add-on wraps the login UI in an HTML form element that submits a POST request to a dummy resource. The text field for user name and the password field receive special attributes so that they are recognized by the password manager.

See the TestUi class for a runnable example.

Build instructions

The addon is built with gradle. The default task builds the distribution JAR file in build\libs. To compile the widgetset for running the Tomcat run configuration in the IntelliJ IDEA project, run the "compileWidgetSet" gradle task first. No gradle installation is required, executing

gradlew

in the root directory will download gradle and build the jar file.

License

Vaadin LoginForm is released under the Apache License, Version 2.0.

vaadin-loginform's People

Contributors

ingokegel avatar

Stargazers

Natsumi Angel avatar  avatar Bartosz Mierzejewski avatar Johannes Wachter avatar  avatar  avatar jamroks avatar SwhGo_oN avatar

Watchers

jamroks avatar  avatar SwhGo_oN avatar  avatar  avatar

vaadin-loginform's Issues

Submit to j_security_check

Hi,

Would it be possible to submit the form to the j_security_check endpoint? Just to be able to use container-authentication?

Thanks in advance

Add additional Tenant-Field

Hi.
Nice plugin. I have one enhancement ;)

My login form will have three textfields to login:
UserName
Password
Tenant-ID

Could you please add such an additional field which can optionally added to the login form?

Thanks in advance :)

NullpointerException in Vaadin portlet

Not working for Vaadin portlet because VaadinServlet.getCurrent() returns null on line #192 in LoginForm.java. For Vaadin portlet implementation correct line to get context path would be:
VaadinPortletService.getCurrentPortletRequest().getContextPath();

Chrome value for password field is not correctly filled

Hi,
In case you are at login page, the login button works perfectly, but if I add an enter listener the value from the password field is null the first time. After that, if i click on enter again the password has the value. Is there any way to force Chrome that get the value from the password TextField if I use an enter key action?
Otherwise, as i say at the beggining of the paragraph if i try to login using login button, everything works.
I know, this maybe a browser issue.
Thanks

Memory leak on RequestHandler

Hi,
First, thank you for this great add-on.
I've been monitoring memory on my app which is using your addon.
I noticed that every time I do a refresh on my login page the new LoginForm created is preserved in the session.
This is because you add a RequestHandler which you don't remove when detaching the UI.
Setting the requestHandler as a private attribute and removing it by overriding detach() would solve this issue.

Thank you,

Best regards.

Fred

Ivy 0.3.2 fails to resolve

When adding version 0.3.2 to Ivy I get the warning that it failed to resolve.

Using 0.3.1 resolves properly and I've gone with that instead for the time being.

Unwanted click event on custom button click in same layout

First of all, thanks for this wonderful addon, it works nicely.

However, when I add a custom javascript button to the form and click it, your loginButton acts like it was clicked and calls login(username, password) method as if there was a click on login button, even if there wasn't.

I have created a simple demo project for you to understand the issue. Please download and simply run mvn vaadin:compile jetty:run on https://github.com/bekce/loginform-test

Thanks.

Support for java form security

If you add a method to set if it's backed by java securtiy system, Spring-security etc, and send an actual response to j_security_check, it can be much more useful. Below is a standard java login form, names and action are constant.

<form method="POST" action="j_security_check">
<input type="text" name="j_username">
<input type="password" name="j_password">
</form>

NPE when refreshing the UI

Hi,

I got a NPE when I refresh the page;The UI is set up to preserve state on refresh. If I use restartApplication everything come back to normal.

Caused by: java.lang.NullPointerException
at com.ejt.vaadin.loginform.LoginForm.init(LoginForm.java:153)
at com.ejt.vaadin.loginform.LoginForm.attach(LoginForm.java:134)

Nice addon btw.

Context path not working correctly in nested environments

Hi,
excellent Vaddin add on... Vaadin should take it to the core :-)

I figured out an improvement for nested servlet pathes. If you are running Vaadin in this way:

http://localhost/vaadin everythink is fine!

If you run it on a nested path like:

http://localhost/myapp/vaadin I ran into a 404 for /loginForm request.

Can you please change: (LoginForm.java)

    String contextPath = VaadinService.getCurrentRequest().getContextPath();
    if (contextPath.endsWith("/")) {
        contextPath = contextPath.substring(0, contextPath.length() - 1);
    }

To:

    String contextPath = Page.getCurrent().getLocation().getPath();
    if (contextPath.endsWith("/")) {
        contextPath = contextPath.substring(0, contextPath.length() - 1);
    }

With this little change it should also work for nested pathes...

Best regards
Steffen

getContextPath() does not handle getContextPathFromService() returning null

Hi Ingo,

I'm trying to use LoginForm in my app (for which thanks!, by the way, it looks great). However, the way I setup my login flow (deferred) means that VaadinServletService.getCurrentServletRequest() returns null at the moment at which I instantiate my LoginForm subclass (I'm outside the request/response loop) This causes a NPE in the getContextPath() method. Since the concerned methods are private, I can't override them to fix the issue in my subclass, any chance you can fix it in the original?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.