PicketLink / JSF错误SecurityConfigurationException

时间:2013-07-16 14:46:21

标签: jsf tomcat jboss-weld

我刚开始为我的JSF应用程序开发Picketlink。我从this source复制了代码。

我必须做一些更改,例如从IDMInitializer中删除Singleton和Startup Annotations,因为我使用的是Tomcat。

上面的快速入门链接中的代码将不会像Picketlink 2.5 beta 5那样编译,所以我不得不进行一些更改,我不确定是否正确。下面是代码和例外。我会很感激任何指针,特别是如果任何人有一个链接到JSF(在Tomcat上)的工作示例

例外:

<pre><code>
javax.faces.el.EvaluationException: org.picketlink.authentication.AuthenticationException: Authentication failed.
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.picketlink.authentication.AuthenticationException: Authentication failed.
at org.picketlink.internal.DefaultIdentity.authenticate(DefaultIdentity.java:204)
at org.picketlink.internal.DefaultIdentity.login(DefaultIdentity.java:110)
at org.picketlink.internal.DefaultIdentity$Proxy$_$$_WeldClientProxy.login(Unknown Source)
at picketlinkDemo.LoginController.login(LoginController.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 27 more
Caused by: org.picketlink.idm.config.SecurityConfigurationException: To use JPAIdentityStore you must provide an EntityManager producer method qualified with @org.picketlink.annotations.PicketLink.
at org.picketlink.internal.EEJPAContextInitializer.initContextForStore(EEJPAContextInitializer.java:26)
at org.picketlink.idm.internal.DefaultStoreFactory.getStoreForFeature(DefaultStoreFactory.java:213)
at org.picketlink.idm.internal.DefaultStoreFactory.getStoreForFeature(DefaultStoreFactory.java:187)
at org.picketlink.idm.internal.DefaultIdentityManager.validateCredentials(DefaultIdentityManager.java:384)
at org.picketlink.internal.SecuredIdentityManager.validateCredentials(SecuredIdentityManager.java:171)
at org.picketlink.authentication.internal.IdmAuthenticator.authenticate(IdmAuthenticator.java:47)
at org.picketlink.internal.DefaultIdentity.authenticate(DefaultIdentity.java:187)
... 40 more

</pre></code>

我的代码:

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package picketlinkDemo; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; import org.picketlink.Identity; import org.picketlink.Identity.AuthenticationResult; import org.picketlink.idm.IdentityManager; import org.picketlink.idm.config.FileIdentityStoreConfiguration; import org.picketlink.idm.config.FileStoreConfigurationBuilder; import org.picketlink.idm.config.IdentityConfiguration; import org.picketlink.idm.config.IdentityConfigurationBuilder; import org.picketlink.idm.config.IdentityStoresConfigurationBuilder; import org.picketlink.idm.credential.Password; import org.picketlink.idm.file.internal.FileDataSource; import org.picketlink.idm.internal.IdentityManagerFactory; import org.picketlink.idm.model.Realm; import org.picketlink.idm.model.SimpleUser; import org.picketlink.idm.model.User; @Named public class LoginController { //@Inject //private IdentityManager identityManager; @Inject private Identity identity; @Inject private FacesContext facesContext; IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder(); FileIdentityStoreConfiguration configuration; //IDMInitializer initMethod = new IDMInitializer (); public void login() { builder.stores().file().preserveState(false).addRealm(Realm.DEFAULT_REALM, "Testing").addTier("Application") .supportAllFeatures(); IdentityStoresConfigurationBuilder store = new IdentityStoresConfigurationBuilder(builder); FileStoreConfigurationBuilder fileStore = store.file(); configuration = fileStore.create(); //Config is an instance of FileIdentityStoreConfiguration IdentityConfiguration configuration = builder.build(); IdentityManagerFactory identityManagerFactory = new IdentityManagerFactory(configuration); IdentityManager identityManager = identityManagerFactory.createIdentityManager(); User user = new SimpleUser("jane"); user.setEmail("jane@doe.com"); user.setFirstName("Jane"); user.setLastName("Doe"); identityManager.add(user); identityManager.updateCredential(user, new Password("abcd1234")); AuthenticationResult result = identity.login(); if (AuthenticationResult.FAILED.equals(result)) { facesContext.addMessage(null, new FacesMessage( "Authentication was unsuccessful. Please check your username and password " + "before trying again.")); } } } </pre></code>

0 个答案:

没有答案