Example for CDI-SessionScoped LogIn with TomEE - session

i'm currently fighting with TomEE, JSF and CDI (i think).
Is there any example out there which has "#javax.enterprise.context.SessionScoped" annotation using TomEE 1.5.1 (or current snapshot)?
I DONT want to use #ManagedBean or something else from javax.faces, just plain CDI.
My problem is: when i change some #SessionScoped user session instance i end up in having a new sessionID (session fixation problem?!?).
My Use-Case:
I want to have a login on one page and have the possability to login from anywhere, the user comes from a JPA-layer which scope i don't know exactly if have to choose.
Is there another way to archieve this?!
I already got this pages, but didn't helped me out:
http://openejb.979440.n4.nabble.com/Guest-user-td4655258i20.html
https://issues.apache.org/jira/browse/TOMEE-734
https://issues.apache.org/jira/browse/TOMEE-745
Thanks for any help!

After a lot of time i created my own "proof-of-concept"-example working with cdi-beans:
https://github.com/FibreFoX/cdi-sessionscoped-login
I hope it will help others, like it helped me while developing that piece of awesome :)

I Use TomEE but I don't understand your problem. Do you use the web-profile?
Did you setup beans.xml correctly?
The bugs you linked are unrelated probably your setup. Impossible to say since I don't have anything to go on. Link a sample project I can try or at least paste your bean and tell were you put beans.xml

Related

Simple working Spring MVC / Maven configuration

I’ve been trying to set up a Spring MVC application from scratch, using Maven, in IntelliJ Idea. I know there are probably some nice Archetypes that can do this for you, but I really want to understand what’s going on. Here’s what I want to do:
Create a simple web application that shows displays “Hello World” under https://localhost:8080/, using an embedded Tomcat (with the Maven plugin). So, one controller, one request mapping, and one template. I’ve been able to get the spring application to boot (the Spring logo appears in the console) and Tomcat seems to run as well (the site responds). The problem is, I haven’t been able to get the request to map to my RequestMap method in my Controller. I’m quite sure that the controller isn’t the problem, but that it’s some configuration/setup issue.
Here’s the thing: I’ve been looking at tutorials, StackOverflow, Spring documentation, etc. for hours now, but I haven’t found a source that really explains how to configure a Spring MVC Maven project. Everyone seems to have a different opinion on what XML files you need, what they should be named, and where they should be located. The consensus seems to be that you need a web.xml file in a folder named WEB-INF, but even there, everyone has a different opinion on where that folder should go. I appreciate that there are multiple different ways to do this, and that there’s no “right” way, but in my experience, there are definitely many “wrong” ways =).
My question right now isn’t necessarily how to get my current project running (I don’t mind starting over), but what kinds of config files are out there (web, spring, app-config, servlet, …), what they do, which ones you need, where they need to go, what they should be named, how they connect, etc. Some people also use the Maven Compiler plugin, and others don’t, and nobody says why :D. Essentially: How do I let Spring know where to find controllers, templates, etc., and how to run and deploy all of this on the embedded Tomcat. I would like to find a source that explains the entire core-ecosystem of Spring MVC in a unified way. I have found many sources that provide “how-to” tutorials, but with little to no explanation (like “add the following servlet.xml file to your WEB-INF folder”). So, if your setup slightly differs from the tutorial (e.g. because you are using IntelliJ instead of Eclipse, Tomcat instead of Jetty, embedded Tomcat, a slightly different folder structure) nothing works, and, most importantly, you have no clue why.
Has anyone learned these setup-basics with anything better than copy/pasting or trial & error? :D
Easiest way to start is by using Spring Boot. Go to following link:
Spring initializr
Choose "Web" for "Selected Dependencise" and click "Generate Project". Download of maven project should start after that. Then import that project in IntelliJ IDEA as a Maven project. And that is a good starting point. You'll get main class that you can run and embeded Tomcat will start at 8080 port. Than you can add some controller, template etc...
Also good guides

Spring framework replacement for FlowAction

I recently inherited a very old code base (written in 2006) that uses the spring framework. Right now, the goal is to get it semi-functional, which I've almost done. However, there is some code I can't seem to fix that uses the class "FlowAction" from 'org.springframework.webflow.executor.struts.FlowAction'. This used to exist in the spring-webflow-1.0.6.jar, but no longer exists in 2.4.2.
Can anyone give me any hints for how to fix the following code using more recent spring framework code?
<action path="/secure/FRONT/enrollAction"
name="webflowActionForm" scope="request"
type="org.springframework.webflow.executor.struts.FlowAction" />
Please keep in mind that this is an attempt to get this very old code working so telling me it's impossible is fine, but please provide a good reason why (I'm no spring expert). I've googled and searched the spring code to no avail, but I'm hoping it's as simple as using a different library. Thanks for any input!
EDIT
Based on the first comment below, struts is no longer supported. I am offering a bounty for someone who knows how to update this code. I assume an alternative exists, or was offered by the spring framework, for code that was using the old libraries. If anyone knows what that is, I would greatly appreciate it. I just need help on how I would update the specific block of code above and am happy to provide any further information needed.
FlowHandlerMapping
FlowHandler
FlowHandlerAdapter
FlowExecutor
FlowDefinition
FlowRegistry
we can use the following classes for getting struts functionality to your code

Passing JSF URL parameters to CDI Bean

I am in the process of redesigning a project and I've come across what I think is a bug but Im confused as to where the bug is originating from.
Basically all I am trying to do is pass a URL parameter to the backing bean. Nothing magic and there are loads of different ways of achieving this. The following are the ones I use regularly;
I can change the bean from #Named to #ManagedBean and then use the #ManagedProperty
I can access the param using FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() and then get the desired param from the Map
Or I can use: <f:metadata><f:viewParam name="id" value="#{backingBean.id}"/></f:metadata>
When I'm using JSF 2.1 with Glassfish 3+ all three of these work perfectly. The problem is that my current project is using JSF 2.2 and Glassfish 4 and none of these work! No matter what I do the parameter is never set and always just ends up as null.
I'm not sure how to track this down further. The obvious changes from the last project are that I am using Glassfish 4 instead of 3, JavaEE 7 instead of 6, and JSF 2.2 instead of 2.1.
I don't get any errors or exceptions that I can post.
Is there anything else I can test or any alternative solutions I can try. Failing that is anybody aware of any reported bugs or changes that might cause this. Lastly can anybody reproduce this error?
The problem relates to the namespace!
If you declare the old namespace everything will work fine;
xmlns:f="http://java.sun.com/jsf/core"
If you declare the new namespace it won't work;
xmlns://xmlns.jcp.org/jsf/core
Be careful as netbeans will automatically populate your namespaces. I really hope this saves somebody some time!

Spring MVC and Backbone.js Integration Issue

I am trying to understand the integration of Spring MVC with backbone.js as its view technology. I find a couple of examples online such as here and here too However, in both of these samples, I am facing the same issues that the Spring MVC controller (the TodoController in the first link and TaskController in the second) does not seem to get called.
First, there are no log messages printed (even if I do a desperate System.out.println() in the controller class). Second, when I try to set break points in the controller classes and go into debug mode, it was not stopped at all, but the example is accessible through localhost:8080/todo (Assume that is the url of the deployed war file). In both examples, a code based configuration approach is used (there is no web.xml). So I am wondering, does the controller class ever got called?
I have been stumbling on this for the weekend. So I would really appreciate it if someone can point me the right direction. Thanks!!!
Thanks for your answer soulcheck :)
I went back to the old fashioned web.xml as opposed to the code-based configuration approach, and I am able to see that the controller class gets properly scanned and called, as printed by the log!! I do not know why though, but i just have new respect for web.xml :)

Audit log with JBoss Seam (EJB3+JSF)

I would need to implement an audit log for a web application written with JBoss Seam. EntityListeners seem like good candidates, but I don't know how to connect the EntityListeners to the application session context to include the logged in used principal in the audit record.
I wonder if there is a way to do this "connection", or if there is a more confortable/elegant/effective way to implement an audit log for this programming environment.
Thanks in advance.
Rafa.
Edit:
Many thanks to Damo for his answer! I tried the injection of my identity component, but it did not work. However, the suggested call to Component.getInstance() did provide the desired reference to the user's identity in the EntityListener.
Have you tried injecting your Application/Session scoped Beans into the EntityListener? Or using Component.getInstance("myBean") if injection is unavailable.

Resources