我正在尝试将Spring Security集成到ui:composition中。 我从这个有用的链接获得了帮助:https://raichand-java.blogspot.in/2016/12/springsecurity4primefaces5springdatajpa.html
也可以。
但是,在将代码集成到ui:composition之后,我得到了一个例外。 知道我添加了文件 springsecurity.taglib.xml :
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://www.springframework.org/security/tags</namespace>
<tag>
<tag-name>authorize</tag-name>
<handler-class>org.springframework.faces.security.FaceletsAuthorizeTagHandler</handler-class>
</tag>
<function>
<function-name>areAllGranted</function-name>
<function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
<function-signature>boolean areAllGranted(java.lang.String)</function-signature>
</function>
<function>
<function-name>areAnyGranted</function-name>
<function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
<function-signature>boolean areAnyGranted(java.lang.String)</function-signature>
</function>
<function>
<function-name>areNotGranted</function-name>
<function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
<function-signature>boolean areNotGranted(java.lang.String)</function-signature>
</function>
<function>
<function-name>isAllowed</function-name>
<function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
<function-signature>boolean isAllowed(java.lang.String, java.lang.String)</function-signature>
</function>
</facelet-taglib>
我已添加到文件 web.xml :
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
运行此页面后:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Login</title>
<h:outputScript library="primefaces" name="jquery/jquery.js"
target="head" />
<h:outputScript library="primefaces" name="jquery/jquery-plugins.js"
target="head" />
</h:head>
<h:body>
<ui:composition template="/templates/homeTemplate.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:sec="http://www.springframework.org/security/tags"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<center><h2>Login</h2></center>
<c:if test="${'fail' eq param.auth}">
<div style="color:red">
Login Failed!!!<br/>
Reason : Bad Credentials!Please Try Again.
</div>
</c:if>
<center>
<h:form prependId="false" id="form">
<p:panelGrid columns="2" style="border-bottom-width: 0px;">
<h:outputText value="UserName:"/>
<p:inputText value="#{loginController.username}" id="username" required="true" requiredMessage="UserName is required"/>
<h:outputText value="Password:"/>
<p:password value="#{loginController.password}" id="password" required="true" requiredMessage="Password is required"/>
</p:panelGrid>
<p:spacer height="20px" width="10px"> </p:spacer>
<p:row>
<p:selectBooleanCheckbox label="Remember Me" id="remember-me" >Remember Me </p:selectBooleanCheckbox>
<h:outputText value=" " />
</p:row>
<br/>
<p:row>
<p:commandButton action="#{loginController.login()}" value="Login" ajax="false"/>
</p:row>
</h:form>
</center>
</ui:define>
</ui:composition>
</h:body>
</html>
我遇到了这个例外:
SEVERE [javax.enterprise.resource.webcontainer.jsf.config](ServerService线程池 - 175)部署期间出现严重错误:: com.sun.faces.config.ConfigurationException:CONFIGURATION FAILED! org.springframework.faces.security.FaceletsAuthorizeTagHandler来自[Module“deployment.mission-man-ear.ear.mission-man-web.war:main”from Service Module Loader] 在com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:453) at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:227) at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187) 在io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:198) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:82) at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:748) 在org.jboss.threads.JBossThread.run(JBossThread.java:320)
谷歌搜索后,我找到了这个帖子java.lang.ClassNotFoundException: org.springframework.faces.security.FaceletsAuthorizeTagHandler,但没有帮助我!我认为 spring-security-taglibs 依赖版本 版本存在问题。你有没有想过要解决这个问题。任何帮助表示赞赏。非常感谢。
答案 0 :(得分:0)
我没有必要进行新的更改。 试试Run As&gt; Maven Clean,Run As&gt; Maven安装然后Maven&gt;更新项目。 这就是全部。
HTH