Spring Security example does not engage security - java

I am trying to follow one of the basic Spring Security tutorials in order to have a foundation to test something more advanced afterwards. But the tutorial is not working. Here is the link:
http://docs.spring.io/spring-security/site/docs/3.2.x/guides/hellomvc.html
Here is what I have done so far:
1.) I followed the instructions explicitly up to the start of the section titled “Verify SecurityConfig is loaded”.
2.) I was then not sure what to do with the “Verify SecurityConfig is loaded” section because it does not give instructions, only explanations. So at first I just skipped it and moved to the section titled “Exploring the secured application, but Run As..Run on Server launched the unsecured app with no login required.”
3.) Next, I tried importing the MessageWebApplicationInitializer.java and RootConfiguration.java classes from the messages-jc sample mentioned in the “Verify SecurityConfig is loaded” section, but this caused a failure of the app to get launched when tomcat was restarted, with errors about beans of specific names not being resolved.
4.) So I started importing the classes for each of the named beans from the messages-jc project and resolving one error after another, but the number of these tells me that the author could not possibly have meant for readers to manually import so many classes that are not described in the tutorial.
How can I get this tutorial to work?
I really just want to add a custom login form, but I have to start with something simpler and build up with a tutorial.
A major problem with the Spring example projects is that they are rarely self-contained, so that a project never contains all the required code. One thus has to do a lot of detective work to figure out where else the example project is pulling code from. It would be nice to just have a simple example project that contains within the project all the code required to execute the project. Such nesting may explain the problems described above.
Note
I am using Eclipse Mars and Tomcat 8, not the STS and tc server. But this should not matter.
Edit
Diff command results in the following. How should I interpret it?
I did not scroll down to the target section since that is all generated, but I could if someone needs me to.

Related

WildFly Jboss EAS 7.2 loadtimeweaving issue with Spring 4.2.4

We are blocked with this issue, I will try to put it in words below.
Please have a look at the image first or keep it opened in parallel.
Project is an old Ant based project. Using Spring 4.2.4 currently. Configuration is XML-based.
Class XYZProjectSample is present inside XYZ.jar and a non-Spring class file present inside ABC.war, say ABCWarSample.java like below:
//non -spring outer class
class ABCWarSample {
//spring-based inner class
#Configurable
class InnerBean {
#Autowired
XYZProjectSample xyzProjectSampleInstance;
}
private XYZProjectSample getService() {
return new InnerBean().xyzProjectSampleInstance;
}
}
For combining these two classes from different modules, load time weaving is used.
Inside ABC.war project's spring-context.xml file they have used load time weaving via
<context:load-time-weaver aspectj-weaving="on"/>
Now this above line is giving error with Jboss EAP 7.2 as mentioned here.
They mentioned upgrade to Spring 5, we did it but encountered page loading issue. like half content coming without and JS and header.
They have used requestDispatcher.include() method to combine two responses. However we see only one and one is lost and there is no visible able error in the logs.
Now point two if we keep the Spring version 4, server doesn't start and gives the same issue, see here.
We tried some fixes given on internet but nothing has worked so far.
All I am looking for as of now is an alternative of this load time weaving for resolving this dependency. I thought about using compile time weaving, but that requires aspectj-maven plugin and we are using ant scripts.
I am really stuck here. Any advice or alternative solution can be really really helpful.
Please feel free to revert in case of any confusions or if you need more information.

Using JBoss BRMS to Create My Own Decision Table Application

I am using the open-source JBoss BRMS application from jboss.org. Hopefully, if you clicked on this post you are familiar with this web application that can be used to develop applications that use Drools rules.
I am following along with the tutorial on building an application that uses a Decision Table to create the rules. That tutorial can be found here: http://www.jboss.org//quickstarts/brms/decision-table/index.html. I was able to successfully execute this tutorial after modifying the pom.xml some.
My question is how can I create my own similar application? This example application works by importing some Java classes into the BRMS repository and also putting a pre-configured Settings.xml file in the ./m2 Maven repository. There are also some folders at another location on my computer that contain 1) a pom.xml file and 2) a src and test directory which contain other things like java source files, compiled byte-code, and some XML files. How can I do this on my own and build my own JBoss BRMS Decision Table application? I was able to create some classes and a spreadsheet and validated this with JBoss BRMS but I am still confused on how to a) create the pom.xml file, b) create the Settings.xml file, and c) create the folders with the required program files like java source code to use Maven to build and run.
I have been reading the Drools documentation and the "proprietary documentation" from Red Hat on the business rules management system (BRMS) that is not too helpful as of yet. It is somewhat helpful but not really. I call it "proprietary documentation" because it is on access.redhat.com which requires a subscription to even download trial software. Jboss.org has completely free versions of similar software. I hope this made sense. Please reply in the comments if it did not make any sense to you.
Respectfully,
user3870315

xml-less spring configuration

I'm struggling with XML-less setup of a Spring project. Could you suggest some approaches to making this an iterative process? i.e. descirbe the steps of where to obtain configuration, how to find docs, which configs to define first, etc..
My goal is to implement a web app that supports websocket and I already found a very recent stock portfolio example https://github.com/rstoyanchev/spring-websocket-portfolio which works great, but when I try to create a simplest webapp that will have a very basic chat, I don't know where to start. I suppose this is all very new and not many are playing with this yet, but if you are, please share, I would be very grateful.
Update: My exact issue is how to dissect WebConfig java of the spring-websocket-portfolio project and rebuild it step by step to achieve a simple chat functionality. I have a spring project going, and it compiles and runs on tomcat 8 successfully(env is fine). the config file in question is this version: WebConfig.java.
What I am after is what is the best way to create something simple, a starting point, and build on top of it. By the way, the latest WebConfig.java has been much simplified by Rossen, but interestingly it has some compile issues and doesn't work.

Java library search order

Background / example (but question is probably broader than this):
I'm trying to write a Java application that accesses a Google AppEngine server. To set up the project for this, I followed the steps outlined in the accepted answer here:
Developing a Java Application that uses an AppEngine database
I am now running into a problem where I'm trying to execute an HttpURLConnection-request in the Java client application (i.e. not in the AppEngine server code), but Google's AppEngine library seems to have replaced the Java version of this connection with its own urlFetch()-implementation. This leads to me getting the following error: "The API package 'urlfetch' or call 'Fetch()' was not found.".
Actual question:
What determines the order in which Java looks through libraries to find needed class-implementations? Is there a way to modify this order (specifically in Eclipse), so that the actual JRE-functions take precedence over a third-party-library that is also needed. Or is there maybe something special going on with the implementation of Url in the example given above, that cannot be resolved by specifying a library order?
Update:
Turns out the problem I was seeing had nothing to do with the order in which classes were loaded. The AppEngine server code explicitly calls setContentHandlerFactory(...) to register its own handler during execution rather than at library load time (see here for a fix to this specific issue). So, while my "actual question" might still stand, I haven't actually yet come across a scenario where it matters...
You might have to define a custom ClassLoader.
Also, take a look at this answer.
Inside Eclipse, you can adjust the classpath order. Right click your project, choose Properties, Java Build Path, then click the "Order and Export" tab. However, of course, this won't affect your program when running outside Eclipse.

Weblogic application complains about some classes missing, how to debug?

I have a rather complex J2EE app I don't have any documentation for and I am trying to get it to run.
I have gotten the ant build script to compile a EAR file that contains a WAR file, but this application even though I get "successfully deployed" on weblogic console is still not working.
There are many required jars missing from the EAR file, hence I get errors about missing classes on the console log when I deploy the app. Sometimes even after I check a particular class is there I still get the error.
What is a best way to debug and get this application running?
Is there any shortcuts in J2EE/Java to "find all dependencies", apps anybody knows to analyze code and find dependencies or anything like that?
Is there any shortcuts in J2EE/Java to "find all dependencies", apps anybody knows to analyze code and find dependencies or anything like that?
Do you mean a compiler? I'm actually semi serious here (even if the compiler won't give you the name of a missing JAR). Indeed, if you are compiling that application successfully with Ant, then you likely have all dependencies required at compile time (you may need more of them at runtime but, well, you'll need to execute the code to identify them). Maybe you just need to add more of them in the EAR during the packaging. Or maybe you need to add more dependencies at the app server classpath level.
In both case, search engines like jarFinder.com or Docjar.com or Jarhoo.com might help you to identify missing JARs and to solve your ClassNotFoundException or NoClassDefFoundError.
You should actually give readers more details about the missing classes, I'm sure people will be able to give you some hints and point you in the right direction.
I know of no easy way to deal with this. If the application provides an ant task build the EAR then the result should be a self-contained deployable application EAR. It is possible that the EAR requires extra libraries to be added to some class path, without documentation it's really hard to know what.
This phrase is, I guess, at the heart of the problem: "Sometimes even after I check a particular class is there I still get the error." Exactly what do you mean?
You are getting a class not found error but you can see the class in the EAR file? If that's the case then things are really difficult, and may well be some kind of classloader issue. I don't know WebLogic at all, but in WebSphere when deploying an application you have a choice of whether to give precedence to JARs in the EAR or to the same JAR in WebSphere itself. Some Applications demand one or the other setting. If there's anything like that in WebLogic then this may be your problem.
Another possible problem is that the app may depend on infrastructure libraries (Eg. XML parsers) that are supplied by WebLogic, but expects a different version that is supplied with the WebLogic version you are using.
Without documentation that the app is supported on the version of WebLogic you are using, I fear you're fighting a long, hard (or even a losing) battle.
I'd assume you managed to get this application put together and compiled in an IDE, maybe Eclipse. Why not simply put all the Jars that you had available at build time, into the EAR?
If you're having to debug this by trial and error, you can look at the list of missing classes and figure out which jars they belong to by Googling for the class names, or maybe you can find them in your IDE too.
If you have a lot of trouble identifying some classes, post the class names (or the error messages) here and someone should be able to tell you where to find the Jar it belongs in.
If you are able to successfully build and deploy the app, but still getting the errors about missing classes, probably some of the jar classes are called through reflection. You may want to search for reflection API calls in the Project through your IDE.
These calls may be something like,
"Class cls = Class.forName(..); cls.newInstance()."
Sometimes even after I check a
particular class is there I still get
the error.
This may be a deployment issue. check the classpath. Some of the jars may be missing from the Classpath.
Is there any shortcuts in J2EE/Java to
"find all dependencies", apps anybody
knows to analyze code and find
dependencies or anything like that?
I'd start by having another go at getting documentation ... or help ... from the original developers, if you can find them. [IMO, people who develop / provide software without any documentation deserve to be bugged incessantly by people asking silly questions.] But I guess you've already tried that.
Then there are the jarfinder.com and other services as mentioned in another answer. (New to me!)
If that fails, I'd try doing a Google search on the FQNs. The chances are that if the missing classes are part of a commonly used library you will hit the Javadocs ... or a posting from someone else with a similar problem to yours.
If the "Google it" approach fails, use the clues in the package naming for the missing classes to try and find where they come from. If they follow the Sun recommendations, the names should map to a company or (real or pseudo-) organization that you can locate by a web search.

Categories

Resources