freemarker.runtime - Template processing error: "No mapping defined for http://www.springframework.org/security/tags" - tags

Spring-security:3.0.2
Freemarker:2.3.19
I want to use springSecurity tags in freemarker, but it throws this errors:
[16 14:10:46,349 ERROR] [btpool0-0] freemarker.runtime - Template processing error: "No mapping defined for http://www.springframework.org/security/tags"
No mapping defined for http://www.springframework.org/security/tags
The problematic instruction:
==> assignment: security=JspTaglibs["http://www.springframework.org/security/tags"] [on line 1, column 1 in macro/header.ftl]
in user-directive page.bodytemplate [on line 6, column 1 in items.ftl]
ftl:
<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
pom.xml
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>

if the problems happen with tomcat7-maven-plugin and not with jetty-maven-plugin you most likely suffer from the not fully initialized servlet context of tomcat7.
Instead of "tomcat:run", do "tomcat:run-war"
the latter makes sure that your web app is (almost) fully being build and bootstrapped, like having jars in /WEB-INF/libs. freemarker's scanning logic for tlds will work like a charm.

It seems like a tag library which you want to download contains the tag org.springframework.security.taglibs.authz.AclTag.
The last version of Spring Security taglibs (which had this class) was the 2.0.7 release, hence the problem.
You can change you spring to 2.0 version. Or you can download security.tld from https://src.springframework.org/svn/spring-security/branches/spring-2.5-integration-branch/taglibs/src/main/resources/META-INF/security.tld and use it on freemarker template like this: <#assign security=JspTaglibs["/WEB-INF/tlds/security.tld"] />
By the way I really don't understand why http://www.springframework.org/security/tags doesn't work... I have tried to use it like you, and I have faced the same issue.

I encountered this error when switched to run-jetty-run maven module.
Module jetty:run didn't had this error.
This helped me:
Download spring-security.tld file and put it in webapp/WEB-INF/tld folder
Add this code to web.xml:
<jsp-config>
<taglib>
<taglib-uri>http://www.springframework.org/security/tags</taglib-uri>
<taglib-location>/WEB-INF/tld/spring-security.tld</taglib-location>
</taglib>
</jsp-config>

The reason why this doesn't work has to do with the Servlet container (and maybe the spec). If you're associating taglibs by the namespace it will only do that automatically if the JAR is in the WEB-INF/lib folder.
If you move the spring-security-taglibs.jar into the WEB-INF/lib folder, it will work.

Related

jsp errors IsUserInRole() and others

I am trying to redeploy a project that fell into my hands. It's a maven project with javax.servlet-api among the dependencies it's using:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>2.5</version>
</dependency>
To this, I'm getting error in jsp-s, including the following.
The method getIsUserInRole() is undefined for the type HttpServletRequest.
and
Multiple annotations found at this line:
- Undefined attribute name
(id).
- Unknown tag (canvas).
- Undefined attribute name
(style).
For this, I changed the servlet version to 3.0.1:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
However, i still have the same errors. The jstl version (ir relevant) on build path is 1.2.
How to fix this?
Why am i to explicitly define servlet-api of any kind, doesn't the servlet container have it?
If so, how to tell JBoss to use servlet version 3.0.1?
I'm running JBoss 7.1 on Eclipse Neon. I tried and got the same thing on Eclipse Mars.
TIA.
//-------------------------------
EDIT:
getIsUserInRole() is the name coming up in Eclipse problem report. here's a snapshot:
enter image description here
The method name is spelled correctly in the code:
<c:if test="${not empty pageContext.request.userPrincipal}">
<c:if test="${pageContext.request.isUserInRole('ROLE_ADMIN')}">
<button class="custombutton" id="admin" style="font-size: 150%; height:80px; width: 100%">Administration [Admin. Profile]</button>
</c:if>
</c:if>
Also, Eclipse is reporting warnings for all canvas items-- tags, attributes names, etc. isn't recognizing them:
enter image description here
//-----------------
EDIT2:
There is Spring 3.2.8 in this project. could it intercept the servlet definition in some way? However, the pom.xml dependency hierarchy shows no indication of it.
Also, I haven't changed any Spring dependencies in the project, they are the same as the one that's been deployed and running now.
This looks like a build problem, however I can't see it. The previous version was deployed on IntelliJ.
No wonder it produces compile errors: The method is wrongly-spelled: It is isUserInRole, and not getIsUserInRole. The consequence is that, within a tag, you must always omit the verb:
${pageContext.request.userInRole('ROLE_ADMIN')}
Why am i to explicitly define servlet-api of any kind, doesn't the servlet container have it? If so, how to tell JBoss to use servlet version 3.0.1?
In compilation, the web container is not already available, so you actually need to put on the classpath a JEE runtime (the servlet-api.jar). You have done it well.
If so, how to tell JBoss to use servlet version 3.0.1?
AFAIK no way: You choose which servlet container (and version) you want to use, and it comes bundled with a specific runtime. So you must accomplish to that runtime when compiling.
The warning about the canvas tag: Ensure you are coding in HTML5: Put this declaration at the beginning of the JSP:
<%# page language="java"
import="..."
%><!DOCTYPE html>
<html>
...
</html>

Maven - Suppress Overriding managed version warning in Eclipse

I am using spring-boot, and experienced an error similar to the one described here. I added the following to my pom.xml.
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId><!--$NO-MVN-MAN-VER$-->
<version>1.1.0.Final</version>
</dependency>
I am overriding the validation-api 1.0.0 dependency defined in my parent pom.xml, by way of Spring boot, and this gives the pesky warning message:
Overriding managed version 1.0.0.GA for validation-api
How can I permanently suppress this warning message in Eclipse? It shows up both in my pom.xml and my problems view.
When that warning shows up, you can open the Quick-Fix menu on the warning (Ctrl+1) and select
Ignore this warning
This will add the comment on the version line, like :
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version><!--$NO-MVN-MAN-VER$-->
</dependency>
Your problem is you manually added that comment on the wrong line.
Since the project is using spring-boot, a more proper answer could be found here: https://stackoverflow.com/a/35385268/1568658
(And since I got the same issue, and the above answer also is not very complete. I would add an answer here.)
Reason of issue:
spring-boot has defined many dependencies & their versions, when you use spring-boot as parent, these dependencies got inherited, and overriding one of the dependency with a different version would get the warning, because it might break other libraries' dependencies.
Solution:
Define a property for that dependency between <properties></properties>, to specify the version.
e.g
<properties>
<reactor.version>2.5.0.BUILD-SNAPSHOT</reactor.version>
</properties>
How to find the property name:
Open your pom.xml in IDEA or Eclipse.
Ctrl + Click on the <parent> tag to open pom of parent, and need to click twice recursively to finally get to the pom file with artifactId as spring-boot-dependencies.
Once you have opened that pom, search for your dependency, e.g servlet-api, and you can see the default version.
There is a document from spring explains it better: https://spring.io/blog/2016/04/13/overriding-dependency-versions-with-spring-boot
Enter version that you need in main pom.
This warning means that you are trying to override artifact version that is defined in your main (top level) pom. Just enter version that you need in main pom and you don't even need to use <version /> in other poms for this dependency.
My issue is with lombok.jar version. I do have multiple lombok versions and eclipse somehow taking a version but it detected more versions so unable to pick it's version. So I went to maven folder (.m2) and deleted the extra versions of lombok, did maven update on project, error gone.
But I haven't provided lombok version anywhere, eclipse choose a version, don't know how.
useful ! I resolve the problem. As the module pom file declare 9.2.12.M0 while the spring-boot refer to the V9.3 . I overwrite the V9.2 in the parent pom file. follow by "Eric Wang"

Can't use JSTL in JSP page, with project that includes juel-impl jar because of ClassCastException with ExpressionFactoryImpl

The error is:
SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [Unable to compile class for JSP] with root cause
java.lang.ClassCastException: de.odysseus.el.ExpressionFactoryImpl cannot be cast to javax.el.ExpressionFactory
at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:180)
at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:107)
at org.apache.jasper.compiler.PageInfo.<init>(PageInfo.java:79)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:110)
.....
The project is using a war overlay, in which the overlaid project has the juel-impl jar, which is necessary for its use of shindig. Any way to use jstl in the child project jsp pages?
Seems you have two rivaling EL APIs in your class path, tomcat's and another one from your application. Your war file must not contain an el-api.jar or juel-api.jar. Make sure to exclude those dependencies.
The Juel 2.1.3 jar is a combination of the following Jars juel-impl.jar, juel-spi.jar and juel-api.jar.
We had the same issue when we included juel 2.1.3 jar in the pom and deployed in tomcat 7.
The issue is resolved by removing Juel 2.1.3 from pom and by adding only juel-impl.
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-impl</artifactId>
<version>2.2.6</version>
</dependency>
you need to also add
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-api</artifactId>
<version>2.2.6</version>
</dependency>
The juel 2.1.3 jar contains the javax/el interfaces and are also a part of jsp-api jar.
I hope this will help.

Module dependency has friend dependency on org.netbeans.libs.javacimpl/1but is not listed as friend

I am developing some application on NetBeans Platform 6.9.1 with Maven. I have Netbeans Platform Application created from maven artefact. I need to depend on Java Source API, because my application is performing some kind of analysis on the source code of Java projects.
I have followed partially this tutorial: http://platform.netbeans.org/tutorials/60/nbm-copyfqn.html (with the exception, that I tried to do dependency management with Maven).
When I try to satisfy all dependencies (add them to pom.xml), I get this message:
Module dependency has friend dependency on org.netbeans.libs.javacimpl/1but is not listed as friend.
For javacimpl package (it's requested by the application that starts up)... the same error it writes for another two packages...
I have read many discussions in other forums, but none of them gave me clear solution.
Does anyone know?
In your module.xml you have to define an impl dependency
Have a look at the codehause page It would be better if you could use a spec dependency, but I have a feeling you wont be able to.
As an example your module.xml will look like this
<?xml version="1.0" encoding="UTF-8"?>
<nbm>
<licenseName>Apache License, Version 2.0</licenseName>
<licenseFile>license.txt</licenseFile>
<dependencies>
<dependency>
<id>org.netbeans.api:org-netbeans-modules-java-source</id>
<type>impl</type>
<explicitValue>0.60.2.10.8.4</explicitValue>
</dependency>
</dependencies>
</nbm>

How to deploy a library with Java EE 6 / Glassfish 3.x

I have got an EAR with two plain libraries. One of them being scala-library. If I deploy the EAR with Netbeans it works as expected. While this is OK for development the final product should be deployable via the command line. For this I use:
asadmin --user … deploy --upload ./target/…-ear.ear
which fails with:
org.glassfish.api.admin.CommandException: remote failure: Error occurred during deployment: Exception while deploying the app […-ear] : C:\Work\Workspa
ces\…\Glassfish\…\applications\scala-library-2.8.0.jar. Please see server.log for more details.
Befehl deploy fehlgeschlagen.
Searching the net I found out that handling libraries have become more strict with Java EE 6 / Glassfish 3.x and that it is not enough to add them to the lib folder inside the ear any more. Only the author neglected to mention what is needed now.
I found new <module><java> entries for the META-INF\application.xml — but that did not help either:
<module>
<java>scala-library-2.8.0.jar</java>
</module>
So the question: Does anybody know what you have to do to add libraries to an EAR file for Java EE 6 / Glassfish 3.x?
PS: I use Maven to build - if that makes any difference.
Well it seems I found the solution myself (again). After adding a library-directory entry to the end of the META-INF\application.xml the deployment runs thou:
<library-directory>lib</library-directory>
</application>
The strange thing is that lib the default for library-directory. So I guess it must be a bug in Glassfish itself not handling the default correctly. If you use Maven make sure to use bundleDir in your pom.xml so that the libs are place in the right place:
<jarModule>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>