Coder Social home page Coder Social logo

cubait / cuba-component-forgot-password Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 10.0 319 KB

A CUBA framework component that adds forgot password functionality to CUBA. It also offer a REST API to be consumed by third party applications or by JS clients.

License: Apache License 2.0

Java 90.34% Groovy 5.41% Shell 3.67% TSQL 0.58%
cuba-component cuba cuba-platform addon reset-passwords

cuba-component-forgot-password's Introduction

license Generic badge Run in Postman

CUBA Forgot Password Component

This application component gives the following features once added to a CUBA project:

  • Enables displaying an optional Forgot password link in the main login window, allowing users to send themselves an email with a reset password link
  • Enables logging in by both login name and email (this works also when using REST API). PLEASE NOTE that requires a UNIQUE constraint on the email attribute of the User entity (simply put, users' emails must be unique in the system)
  • Exposes a new REST service (extsec_UserManagementService) that enables REST clients to use the forgot password functionality via API calls

Installation

NOTE: This add-on's repository is officially linked to the main CUBA repository.

You can jump straight to step 2. for instructions on how to add it to your project, or optionally you can choose to add my repository to your project's repositories.

  1. [OPTIONAL] Add the following maven repository https://dl.bintray.com/pfurini/cuba-components to the build.gradle of your CUBA application:
buildscript {
    
    //...
    
    repositories {
    
        // ...
    
        maven {
            url  "https://dl.bintray.com/pfurini/cuba-components"
        }
    }
    
    // ...
}
  1. Select a version of the add-on which is compatible with the platform version used in your project:
Platform Version Add-on Version Coordinates
6.6.* 0.1.1 it.nexbit.cuba.security.forgotpassword:nxsecfp-global:0.1.1
6.7.* N/A not compatible
6.8.* 0.2.0 it.nexbit.cuba.security.forgotpassword:nxsecfp-global:0.2.0
6.9.* 1.0.0 it.nexbit.cuba.security.forgotpassword:nxsecfp-global:1.0.0
6.10.* 2.2.0 it.nexbit.cuba.security.forgotpassword:nxsecfp-global:2.2.0
7.0.* 3.0.0 it.nexbit.cuba.security.forgotpassword:nxsecfp-global:3.0.0
7.1.* 4.0.0 it.nexbit.cuba.security.forgotpassword:nxsecfp-global:4.0.0

The latest stable version is: 4.0.0

  1. Install the correct add-on version in your project using CUBA Studio, or manually by editing your build.gradle file.

PLEASE NOTE that new features are developed only in the latest releases, while only critical bug fixes are back-ported to older ones. Please update your CUBA version as soon as possible, if you are in need of some features available only in a recent release (see the CHANGELOG for reference).

BREAKING CHANGE NOTICES

1.0.0

  • The loginWindow screen has been refactored a bit. You need to change your code if you have extended this screen, otherwise no action is required.
  • CUBA 6.9 makes the Anonymous role a Denying role by default. So if you install the component in a brand new project, it will not work until you adjust the permissions for the Anonymous role. No action is required if upgrading an existing project, or your Anonymous role is already configured with the needed roles. Please see the paragraph Setup the Anonymous role in the Usage section, for instructions on how to setup a new CUBA 6.9 project.

2.0.0

  • The loginWindow screen has been refactored to follow the changes made in CUBA 6.10 for the new Hover theme. You need to change your code if you have extended this screen, otherwise no action is required.
  • The extended allowAnonymous attribute in rest-services.xml file has been removed. Please use the anonymousAllowed standard attribute introduced in CUBA 6.10 instead. Remember to change the attribute xmlns="http://schemas.haulmont.com/cuba/rest-services-v2-ext.xsd" in your rest-services.xml to the standard xmlns="http://schemas.haulmont.com/cuba/rest-services-v2.xsd" one.

3.0.0

  • Some code changes required for CUBA 7 compatibility, that are backwards incompatible.

Supported DBMS engines

Since version 0.2.0 this plugin supports the following RDBMS engines:

  • HSQLDB
  • PostgreSQL
  • MySQL/MariaDB 10.x (thanks to Mario David)
  • Microsoft SQL Server (tested against 2017-GA Express on Ubuntu 16.04)
  • Oracle 11g+ (tested against Oracle Express Edition 11g)

Created tables

Table Name Scope
NXSECFP_RESET_PASSWORD_TOKEN Holds generated reset tokens, alongside the linked User entity and timestamp of expiration

Usage

Setup the Anonymous role (1.0.0+ only)

If you install the 1.0.0 or later add-on version on a brand new CUBA project, please follow these instructions to setup your Anonymous role.

  1. Login as Administrator
  2. Open the Roles screen in the Administration menu
  3. Find the Anonymous role and edit it
  4. In the Screens tab expand the Other screens target, then find the screens listed in the following image, and set them to allow

  1. Finally Save and Close the edit screen, and restart the application

Using the Forgot Password functionality

To enable the Forgot password link, and related functionality in the main login window, follow these steps:

  1. Add the following properties to your web-app.properties file:
# this property enables the reset password link in login window
ext.security.showResetPasswordLinkAtLogin = true

# you must include the "reset" link handler action to be able to open the change pass dialog via custom link
cuba.web.linkHandlerActions = open|o|reset
  1. Optionally, create custom reset link emails and set the corresponding paths in your app.properties file, located in the core module:
# create customized email templates, and set the full path in these properties
ext.security.resetPasswordLinkTemplateBody = /it/nexbit/cuba/security/forgotpassword/app/email/reset-password-link-body.gsp
ext.security.resetPasswordLinkTemplateSubject = /it/nexbit/cuba/security/forgotpassword/app/email/reset-password-link-subject.gsp

You can find built-in templates here: Default email templates. Remember that they use the same mechanism described here in the official docs: https://doc.cuba-platform.com/manual-7.0/users.html, so they can be localized adding a locale suffix, and they can also be located or overridden in the tomcat configuration directory, with the properties added to the local.app.properties file.

Properties

The component also exposes the following DATABASE properties, that you can configure in your running app:

Property Default Value Description
ext.security.resetPasswordLinkWebPath /reset The path appended to your web application URL when the token is generated from the standard login window (WARNING: do not modify this value unless you are extending or changing the component behavior)
ext.security.resetPasswordLinkPortalUrl http://localhost:8080/portal/reset You should change this property if you plan to use the forgot password functionality from REST clients. This endpoint must be configured using your JS framework of choice, and it is beyond the scope of this documentation
ext.security.resetPasswordTokenLifetimeMinutes 1440 The lifetime of a newly generated reset token (default 24 hours)

extsec_UserManagementService Methods

UPDATE FOR CUBA >= 7.1: Since the REST API functionality has been moved to a separate add-on, you must add it to your project to be able to call the following methods via REST.

The following are the methods exposed by the extsec_UserManagementService

<?xml version="1.0" encoding="UTF-8"?>
<services xmlns="http://schemas.haulmont.com/cuba/rest-services-v2-ext.xsd">
    <service name="extsec_UserManagementService">
        <method name="checkUserExist" anonymousAllowed="true">
            <param name="loginOrEmail"/>
        </method>
        <method name="sendResetPasswordLink" anonymousAllowed="true">
            <param name="loginOrEmail"/>
        </method>
        <method name="checkResetPasswordToken" anonymousAllowed="true">
            <param name="token"/>
        </method>
        <method name="changePasswordWithToken" anonymousAllowed="true">
            <param name="token"/>
            <param name="password"/>
        </method>
        <method name="deleteResetPasswordToken" anonymousAllowed="true">
            <param name="token"/>
        </method>
    </service>
</services>

Consult the online documentation at this link, or the JavaDoc documentation on the interface methods for explanation of their usage and parameters.

You can use the following button to open a collection of requests in the Postman application:

Run in Postman

Usage Notes

The methods exposed to REST clients are not all the methods available on the NexbitUserManagementService interface, but only the safest ones.

Feel free to use the other ones in your own client and middleware code, for example if you want to implement a new management functionality to bulk send reset passwords to a group of users.

This is specially useful, because the methods on that interface allow to explicitly set the baseUrl to use when generating reset links, and so you could let your power user (admin) to choose where end users will be redirected when clicking the link (if you have multiple apps for multiple groups of users).

In this regard, the component use a couple of defaults when choosing which baseUrl to use when generating reset links:

  • if the user click the Forgot password link on the main (vaadin) login window, it will use the URL obtained by concatenating the values from GlobalConfig#getWebAppUrl() and the ext.security.resetPasswordLinkWebPath property
  • if the request comes from the sendResetPasswordLink REST service method, it will use the URL in the ext.security.resetPasswordLinkPortalUrl property

In both cases, it will append a token=<TOKEN_VALUE> query string to the final URL.

New Login screen in v.4.0

Starting from version 4.0 of the addon, there are two login screens:

  • NexbitLoginScreen - new login screen written with the new screen API
  • NexbitAppLoginWindow - legacy login screen written with the old API. NOTE: you should not extend your custom login screen from this if you are starting a new project!

The legacy login screen is used automatically when your web-app.properties contains cuba.web.loginScreenId=loginWindow.

Known Issues

See the corresponding issue to find if a workaround is currently available.

Credits

Thanks to

  • Mario David (@mariodavid) for the initial MySQL/MariaDB scripts
  • Sorin Federiga (@sorinfederiga) for the Romanian translation
  • Sergey Butenin (@basicus) for the Russian translation and for porting the code to CUBA 7

cuba-component-forgot-password's People

Contributors

basicus avatar pfurini avatar sorinfederiga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cuba-component-forgot-password's Issues

pls support to 7.1*.

I'm submitting a feature request

  • Component Version:
    3.0.0

Please tell us about your environment:

  • Operating System:
    Windows 10

  • CUBA Version:
    7.1.0

  • Java Version:
    Oracle JDK 1.8.0_144

Current behavior:
don't support to 7.1*.

Expected/desired behavior:

  • support to 7.1*.

I'm submitting a feature request for cuba 7.2.x support

I'm submitting a feature request

Please tell us about your environment:

  • Operating System:
    OSX 11.0.1

  • CUBA Version:
    7.2.10

  • Java Version:
    Corretto-11.0.9.11.1

Current behavior:
Not supported

Expected/desired behavior:
Support for cuba projects using 7.2.10

Add db scripts for most RDBMS engines (now missing)

I'm submitting a feature request

  • Component Version:
    0.1.x

Please tell us about your environment:

  • Operating System:
    N/A

  • CUBA Version:
    6.6.4

  • Java Version:
    N/A

Current behavior:
Currently only scripts for HSQLDB and Postgres are provided in the component.

Expected/desired behavior:

There should be init scripts for all the RDBMS supported by CUBA.

What is the motivation / use case for changing the behavior?
Let users that need support for other RDBMS to install this component in their app.

Unable to Add custom application component

@pfurini find the Log and screen
[11:32:07.907] Cannot add application component it.nexbit.cuba.security.forgotpassword:nxsecfp-global:0.1.0
[11:32:39.285] Exception has been thrown by com.haulmont.studio.backend.p.d@427a5b:
[11:32:39.285] java.io.FileNotFoundException: Artifact it.nexbit.cuba.security.forgotpassword:nxsecfp-global:0.1.0 not found in the repositories:[https://repo.cuba-platform.com/content/groups/work, https://repo.cuba-platform.com/content/groups/premium, https://mvnrepository.com/artifact/net.java.dev.jets3t/jets3t]

at com.haulmont.studio.backend.p.d.a(SourceFile:428)

at com.haulmont.studio.backend.p.d.c(SourceFile:361)

at com.haulmont.studio.backend.p.d.a(SourceFile:266)

at com.haulmont.studio.ui.n.m.a(SourceFile:95)

at com.haulmont.studio.ui.n.m.b(SourceFile:74)

at com.haulmont.studio.ui.n.z.commit(SourceFile:209)

at com.haulmont.studio.ui.common.b.buttonClick(SourceFile:75)

at sun.reflect.GeneratedMethodAccessor185.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)

at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:200)

at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:163)

at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1037)

at com.vaadin.ui.Button.fireClick(Button.java:377)

at com.vaadin.ui.Button$1.click(Button.java:54)

at sun.reflect.GeneratedMethodAccessor147.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

...
[11:32:39.288] Cannot add application component it.nexbit.cuba.security.forgotpassword:nxsecfp-global:0.1.0
Messages
Clear
capture

allowAnonymous does not work for POST requests

I'm submitting a bug report

  • Component Version:
    0.1.0

Please tell us about your environment:

  • Operating System:
    OSX 10.12

  • CUBA Version:
    6.6.4

  • Java Version:
    Oracle JDK 1.8.0_144

Current behavior:

If you put allowAnonymous="true" on a method that is then called using a POST request, the method will continue to ask for an Authorization header.

If you call the same method with a GET request (putting the parameters in the query string), the method is executed even without an Authorization header, as expected by the allowAnonymous attribute.

Example rest-services.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<services xmlns="http://schemas.haulmont.com/cuba/rest-services-v2-ext.xsd">
    <service name="testsec_NewService">
        <method name="someMethod" allowAnonymous="true">
            <param name="someArg"/>
        </method>
    </service>
</services>

try sending a POST request to <BASE_URL>/services/testsec_NewService/someMethod, with the following JSON body

{ "someArg": "test" }

the response will be 401 Unauthorized, with the response body:

{
    "error": "unauthorized",
    "error_description": "An Authentication object was not found in the SecurityContext"
}

then try instead sending a GET request to the same method: <BASE_URL>/services/testsec_NewService/someMethod?someArg=test
and the request will complete successfully even without an Authorization header.

Expected/desired behavior:

I expect to be able to call service methods anonymously using POST requests, and passing parameters in the JSON body.

RootView exception... platform 7.0.6

I'm submitting a bug report
I'm submitting a feature request

  • Component Version:
    major.minor.patch-pre

Please tell us about your environment:

  • Operating System:
    OSX 10.x|Linux (distro)|Windows [7|8|8.1|10]

  • CUBA Version:
    6.6.4

  • Java Version:
    Oracle JDK 1.8.0_144

Current behavior:

Expected/desired behavior:

  • What is the motivation / use case for changing the behavior?

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.