Spring MVC objects storage in application - spring

I have a Spring MVC application.
For example I have a simple JSP page that displays list of Contact objects.
User can add, remove objects. The question is about the way of Contact objects storage. I cannot (by some reasons) use database. How can I anyway store list of objects globally for application?

According to this
it must be stored across whole application lifec-cycle. After I
restart server it the list should not be lost
you can use H2 or HSQLDB database and keep it content into single file, located in configurable path. Anyway, to keep some persisted data, you should use local file or remote storage, so, i think, it would simplify solution if you use such kind of database.

Related

Auto logout after Docker deployment in ASP.NET Core MVC Identity

I'm using ASP.NET Identity for Authentication and Authorization. Since I use docker on the recommended way (separate container for building and running), I got always logged out after each deployment. Seems like ASP.NET Core doesn't store the sessions in the database. Also cause I can't see any table where they are.
How can I fix this so that my users don't get logged out after each deployment?
I think I need to store the sessions in the database. But I couldn't find information how to do this. I found information about using Redis as session store. This comes near - I'm not sure, if this also affect the ASP.NET Identity session, or only the session stores like TempData. And the other problem is, that I would like to store the session in my MySQL database using Pomelo.EntityFrameworkCore.MySql provider.
Found out that using memory storage causes issues with the encryption keys, too. In Short, ASP.NET Core use those keys to protect sensitive data like sessions. So they're not stored in plain text. Seems like that ASP.NET generate those keys automatically on the first application run.
Cause it runs in a Docker container, this will result in two big problems:
The encription key get lost by rebuilding the container image. ASP.NET Core generated a new one automatically, but can't decrypt the existing sessions cause they were encrypted using an different key
A container is isolated, so the default memory storage provider for sessions would lost its data after every new deployment
This could be solved by using a storage which is running on a different server than the webserver, as I suggested. I couldn't find any MySQL implementation for this. Only SQL server, which seems to be MSSQL. I fixed it by installing a Redis server. Its used for session storage and the encryption keys.
To let ASP.NET Core storage encryption keys in Redis, install the Microsoft.AspNetCore.DataProtection.Redis provider and append the following lines to ConfigureServices before AddOptions
var redis = ConnectionMultiplexer.Connect($"{redisIpAddress}:{redisPort}");
services.AddDataProtection().PersistKeysToRedis(redis, "DataProtection-Keys");
Note, that this is only part of ASP.NET Core since the 1.1.0 release. Cause it has dependencies on other packages of the 1.1.0 branch, I'd assume that its not working on the LTS 1.0 release. In this case, you may need to write a custom implementation which is 1.0 compatible. But I haven't tested this, since I'm using 1.1.0 in my project. More infos in this article: http://www.tugberkugurlu.com/archive/asp-net-core-authentication-in-a-load-balanced-environment-with-haproxy-and-redis
In summary, I don't think its a bad idea to use Redis for this instead of a SQL database, cause Redis is optimized for serving key-value pairs very fast. And the base is there to use Redis for caching other parts of the application like (complex) database queries. This can speed up your application and reduce load of the database server.

Multitenency in Apache Nifi

I am working on a cloud based application using Apache Nifi, for this we required to support Multitenency. But the current Nifi implementation only supports role based access for users, for a single flow.
I could understand that the flow state is saved as a single compressed XML file for a Nifi instance. So that who ever logins into that instance can view the same flow. Our requirement is to create unique flows for each user login. I tried to replicate state saving gz XML file for each users, but couldn't succeeded as the FlowService/FlowController which loads the XML file, is instantiated at the application startup and they are singleton. Please correct me, if Iam wrong with this approach. Or is there any other solution for adding Multitenant support with Nifi. I also wonder the reason behind the Nifi as a single user application.
Multi-tenant support will be introduced in Apache NiFi 1.0.0. There is a BETA release available [1]. This will support assigning permissions on a per component basis. However, the different tenants still share a canvas. There has been discussions of introducing a workspace concept that could provide visually separate dataflows.
[1] https://nifi.apache.org/download.html

MVC4 Membership Tables not created on production environment

I'm attempting to use the ASP.NET universal providers in my MVC4 application. Among other places, this article describes how, the first time you attempt to register a user, the tables should auto-create in my DB.
I had this working on my internal app/db, but I used the asp.net web configuration tool to create my first user. When I deployed this to production, I attempted to register a user and was hit with an error indicating dbo.Applications didn't exist, which is one of the tables that should have been created.
Any thoughts on why these tables weren't created? I've made sure the System.Web.Providers dll was copied to the bin folder. I'm also sure my app can manage CRUD tasks on my database.
argh duh. Turns out I didn't have create perms set up for the app pool identity that was making the call. Hangs head in shame

Is it possbile to change the webpages_Membership, roles etc table names from a simple template created with web matrix?

I've created a Web Matrix web site from the starter template which creates a database with the a few tables for the login details. Most of these are names webpages_Membership, webpages_Roles etc. The hosting company I use only gives me one database and I want to have more than one site on the server. I want to prefix the table name with something to make it unique, but it looks like the web matrix framework will only work with the set table name. Does anyone know if this is possible?
If you use SQL Server Compact Edition, you can have as many databases as you like in your App_Data folder. Certainly something to consider if your sites aren't likely to be hugely busy. Otherwise you can develop your own Provider inheriting from ExtendedMembershipProvider and make it "site-aware". Dig around in the WebMatrix.Data source code for more details (available as part of the MVC source download).

Storing data locally

In my application I am retrieving data from database and showing in it. In db some of the tables contain 1000+ records. Now my requirement is to show this data even if there is no net connection, so I am planning to store the tables in SQLite db at user's machine, but there is a worry:
Since SQLite db will be included
within resources folder, in project,
so it will be by default contained
within application binary. So I want
to know that when the application will
be launched will all this data reside
on RAM ? If yes, then I think this can
cause some problems, so in that case- is
there any alternative solution to
store data locally?
Thanks,
Miraaj
No, it won't all reside in RAM. The contents of the application bundle (NIB files, images, etc.) are not all automatically loaded into memory when the app is launched. Resources are typically loaded on demand. For example, a view controller might call initWithNibName: to load the resources for that view.
Also, unless the database is a read-only part of the application (never changes unless you upgrade), you probably don't want to store it in the app bundle -- use the application documents directory instead (although you might include an initial "default" copy of the database within the app bundle). See "A Few Important Application Directories" in the iOS Application Programming Guide

Resources