Idle Notification not showing - Vaadin 14 - spring-boot

I'm trying to use an add-on https://vaadin.com/directory/component/idle-notification for Session Management. I would like to show notification when user is inactive in the application for a given time.
I have Main Layout:
#PWA(name = "App", shortName = "App", enableInstallPrompt = false)
#Theme(themeFolder = "app")
#CssImport(value = "./styles/example.css", themeFor = "vaadin-grid")
#PreserveOnRefresh
#Push
public class MainView extends AppLayout implements AfterNavigationObserver {
public MainView() {
...
IdleNotification idleNotification = new IdleNotification();
idleNotification.setSecondsBeforeNotification(90);
idleNotification.setMessage("Your session will expire in " +
IdleNotification.MessageFormatting.SECS_TO_TIMEOUT
+ " seconds.");
idleNotification.addExtendSessionButton("Extend session");
idleNotification.addRedirectButton("Logout now", "logout");
idleNotification.addCloseButton();
idleNotification.setExtendSessionOnOutsideClick(false);
UI.getCurrent().add(idleNotification);
}
}
Unfortunatelly notification not showing.
I also tried set parameters in application.properties as:
vaadin.closeIdleSessions=false
vaadin.heartbeatInterval=true
vaadin.pushMode=true
but that does not solve the problem

The problem was setting vaadin.whitelisted-packages = com.my.app, I added com.vaadin.componentfactory to vaadin.whitelisted-packages and work.

Related

Masstransit Testharness with multiple ExecuteActivities doesn't create Endpoints as expected

I want to write a test that checks if my routingslip works as expected. I narrowed it down to this simplified Version.
namespace MasstransitTest
{
public class Tests
{
private readonly InMemoryTestHarness _harness;
public Tests()
{
var services = new ServiceCollection();
services.AddLogging(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Debug));
services.AddMassTransitInMemoryTestHarness(cfg =>
{
cfg.AddExecuteActivity<ActivityOne, MyMessage>()
.Endpoint(c => c.Name = "queue1");
cfg.AddExecuteActivity<ActivityTwo, MyMessage>()
.Endpoint(c => c.Name = "queue2");
});
var serviceProvider = services.BuildServiceProvider(true);
_harness = serviceProvider.GetRequiredService<InMemoryTestHarness>();
_harness.Start();
}
[Test]
public async Task Test1()
{
var routingSlipBuilder = new RoutingSlipBuilder(Guid.NewGuid());
routingSlipBuilder.AddActivity("Activity1", new Uri("loopback://localhost/queue1"), new { MyMessage = new MyMessage()});
routingSlipBuilder.AddActivity("Activity2", new Uri("loopback://localhost/queue2"), new { MyMessage = new MyMessage()});
routingSlipBuilder.AddSubscription(new Uri("loopback://localhost/protocol-event-monitor"),RoutingSlipEvents.All, RoutingSlipEventContents.All);
var routingSlip = routingSlipBuilder.Build();
await _harness.Bus.Execute(routingSlip);
Assert.That(await _harness.Sent.Any<RoutingSlipCompleted>());
}
}
}
This Test failes, but it works if I replace one of the activities by an activity with another argument type. For example
cfg.AddExecuteActivity<ActivityTwo, MyOtherMessage>().Endpoint(c => c.Name = "queue2");
The failing test prints this log:
info: MassTransit[0] Configured endpoint queue2, Execute Activity: MasstransitTest.ActivityOne
info: MassTransit[0] Configured endpoint queue2, Execute Activity: MasstransitTest.ActivityTwo
dbug: MassTransit[0] Starting bus: loopback://localhost/
I think the Problem is that only one endpoint gets configured, but I don't know why. Is this a bug in the Testingframework?
When using .Endpoint to override the execute or compensate endpoint for an activity, the arguments or log type must be unique.
To change the endpoint name for activities that have a common argument or log type, use an ActivityDefinition or an ExecuteActivityDefinition
public class ActivityOnExecuteActivityDefinition :
ExecuteActivityDefinition<ActivityOne, One>
{
public ActivityOnExecuteActivityDefinition()
{
EndpointName = "queue1";
}
}

Specifying LUIS dialog spellCheck, slot programmatically

so far I was able to avoid hardcoding my LUIS appId and key by doing the following:
var luisService = new LuisService(new LuisModelAttribute(ConfigurationManager.AppSettings["LuisAppId"], ConfigurationManager.AppSettings["LuisAppKey"]));
context.Call(new LuisDialog(luisService), ResumeAfterDialog);
And then having my LUIS dialog declared as:
[Serializable]
public class LuisDialog : LuisDialog<object>
{
public LuisDialog(ILuisService ls) : base(ls)
{
}
....
}
}
But I would also like to be able to set SpellCheck=true, Log, Verbose and other parameters available in the LuisModel attribute programmatically, is there a way of doing that?
Thanks
I figured it out, I just need to set the LuisModelAttribute properties in code before creating the LuisService:
var luisSettings = new LuisModelAttribute(ConfigurationManager.AppSettings["LuisAppId"], ConfigurationManager.AppSettings["LuisAppKey"]);
luisSettings.Log = true;
luisSettings.SpellCheck = true;
luisSettings.Log = true;
var luisService = new LuisService(luisSettings);
context.Call(new LuisDialog(luisService), ResumeAfterDialog);

What is the correct way to define models and their validation?

I want to create a supplier model i.e code, name, address, phone
I am also going to use the aurelia-validation classes.
Using them both together with the viewmodel - SupplierMaint.js & view - SupplierMaint.html is fine but I want to keep the Supplier model in another file so that I can use it in many places to ensure a consistent validation of values lengths etc.
How should I go about this?
I suspect the #NoView annotation might have something to do with it but I am not sure how to import the external file and wire it up to the submit & validation processing in the SupplierMaint.js
Bob
Models
This is how I do it -
export class Supplier {
name = '';
modelId = '';
constructor(data) {
Object.assign(this, data);
}
}
This let's anyone consume your model and create a new instance of it. The data that is passed in will override the default values you define, but if they do not you still have those default values.
Validation
Validation is currently in a state of flux. I'm hoping to be done with the initial refactoring work by the end of this weekend but here is a preview for what I propose as the best usage, feedback welcome.
import {ValidationReporter} from 'aurelia-validate';
export class PersonViewModel {
activePerson;
static inject = [ValidationReporter];
constructor(reporter) {
this.activePerson = new PersonModel({firstName: 'Lucky Luke'});
this.reporter = reporter.subscribe(validationErrors => {
// do something with validationErrors
});
}
}
class PersonModel {
#length({ minimum: 5, maximum: 25 }) firstName = 'Luke';
#required lastName = 'Skywalker';
#date lastUpdated = new Date();
#datetime lastTimeUpdated = new Date();
#email email = 'luke#skywalker.net';
#length({ minimum: 5, maximum: 25 }) password = 'equal';
#equality confirmPassword = 'equal';
#url website = 'http://www.google.com';
#numericality friendCount = 25;
#numericality({ noStrings: true }) age = 25;
constructor(data) {
Object.assign(this, data);
}
}

Zend Framework specific module session configuration

I'm trying to get a different session configuration for 2 modules.
In my application ini i have a modules set up like :
resources.modules[] =
resources.frontcontroller.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontcontroller.throwerrors = true
resources.layout.layout = "layout"
and for the sessions
resources.session.save_path = APPLICATION_PATH "/temp/session"
resources.session.use_cookies = true
resources.session.use_only_cookies = true
resources.session.gc_maxlifetime = 3600
resources.session.remember_me_seconds = 3600
resources.session.name = "sid"
resources.session.gc_probability = 1
backoffice.resources.session.save_path = APPLICATION_PATH "/temp/bo/session"
backoffice.resources.session.use_cookies = true
backoffice.resources.session.use_only_cookies = true
backoffice.resources.session.gc_maxlifetime = 3600
backoffice.resources.session.remember_me_seconds = 3600
backoffice.resources.session.name = "BOsid"
backoffice.resources.session.gc_probability = 1
but when i go the backoffice module i still have my default configuraton
Any idea what should be the best way to get different sessions for different modules ?
Thanks
I want to advise you another method of config customization for specific modules in ZF:
1. Create for each module config file: /modules/$moduleName/configs/module.ini
2. Add to the root Bootstrap the next code:
protected function _initBootstrap()
{
$_conf = new Zend_Config_Ini(APPLICATION_PATH . "/modules/" . $this->getModuleName() . "/configs/module.ini", APPLICATION_ENV);
$this->_options = array_merge($this->_options, $_conf->toArray());
}
I finally opted for a controller plug-in.
With some code like
class App_Controller_Plugin_Session extends Zend_Controller_Plugin_Abstract
{
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$config = Zend_Registry::get('config')->toArray();
if( $this->getRequest()->getModuleName() == 'backoffice' ) {
$conf = $config['sessionBackoffice'];
} else {
$conf = $config['sessionDefault'];
}
Zend_Session::setOptions($conf);
Zend_Session::start();
}
}
The plugin need to be added at first in the registerPlugin stack if you some other plugin that require sessions.
If you have a better solution i'm open.

How to change AzureADOptions at runtime

I am trying to change AzureADOptis at run time. I tried the following, but after this, clicking on the sign in link takes old values for redirecting it to microsoft login page. Expectation is to take updated options.
var options = new AzureADOptions
{
Instance = "https://login.microsoftonline.com/",
Domain = "....",
TenantId = "....",
ClientId = "....",
CallbackPath = "/signin-oidc"
};
_optionsCache.TryRemove(AzureADDefaults.AuthenticationScheme);
_optionsCache.TryAdd(AzureADDefaults.AuthenticationScheme, options);
You can use OpenIdConnectOptions since AzureADOptions will also map to OpenIdConnectOptions in library . And you need to inject OpenIdConnectPostConfigureOptions into DI system and call _postConfigureOptions.PostConfigure before _optionsCache.TryAdd :
ConfigureServices.cs:
services.AddSingleton<OpenIdConnectPostConfigureOptions>();
In your Controller:
private readonly IAuthenticationSchemeProvider _schemeProvider;
private readonly IOptionsMonitorCache<OpenIdConnectOptions> _optionsCache;
private readonly OpenIdConnectPostConfigureOptions _postConfigureOptions;
public HomeController(IAuthenticationSchemeProvider schemeProvider, IOptionsMonitorCache<OpenIdConnectOptions> optionsCache, OpenIdConnectPostConfigureOptions postConfigureOptions)
{
_schemeProvider = schemeProvider;
_optionsCache = optionsCache;
_postConfigureOptions = postConfigureOptions;
}
In your action :
var OIDCoptions = new OpenIdConnectOptions
{
Authority = "https://login.microsoftonline.com/YourTenantID/",
ClientId = "YourClientID",
CallbackPath = "/signin-oidc"
};
_postConfigureOptions.PostConfigure(AzureADDefaults.OpenIdScheme, OIDCoptions);
_optionsCache.TryRemove(AzureADDefaults.OpenIdScheme);
_optionsCache.TryAdd(AzureADDefaults.OpenIdScheme, OIDCoptions);

Resources