Timed Access Control for non back office users

Hi

How can I implement timed access to the application for non back office users? The idea is that the back office sets the date and time where regular users have access to the application. When a non back office user logs in, a message should be shown such as "The system is open from … to … ".

Best,
Wern

Hi Werner,

what you can do is to set session attributes for user groups like startTime and endTime.

Then you can create a Login listener, that looks up the values and before login you raise an exception in case the time range is not exceeded.

In the docs there is an example:

https://doc.cuba-platform.com/manual-latest/login.html#login_events

@Component
public class MaintenanceModeValve {
    private volatile boolean maintenance = true;

    public boolean isMaintenance() {
        return maintenance;
    }

    public void setMaintenance(boolean maintenance) {
        this.maintenance = maintenance;
    }

    @EventListener
    protected void onBeforeLogin(BeforeLoginEvent event) throws LoginException {
        if (maintenance && event.getCredentials() instanceof AbstractClientCredentials) {
            throw new LoginException("Sorry, system is unavailable");
        }
    }
}

which you can take as a basis for your implementation.

Cheers
Mario

1 Like

Thanks Mario!
That’s exactly what I am looking for.
Best,
Wern