maven 注入
<dependencyManagement> <dependencies> <dependency> <groupId>org.apache.deltaspike.distribution</groupId> <artifactId>distributions-bom</artifactId> <version>${deltaspike.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.picketlink</groupId> <artifactId>picketlink-javaee-7.0</artifactId> <version>${version.picketlink.javaee.bom}</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- deltaspike --> <dependency> <groupId>org.apache.deltaspike.core</groupId> <artifactId>deltaspike-core-api</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.core</groupId> <artifactId>deltaspike-core-impl</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-jpa-module-api</artifactId> <version>${deltaspike.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-jpa-module-impl</artifactId> <version>${deltaspike.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-security-module-api</artifactId> <version>${deltaspike.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-security-module-impl</artifactId> <version>${deltaspike.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-proxy-module-api</artifactId> <version>${deltaspike.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-proxy-module-impl-asm5</artifactId> <version>${deltaspike.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-jsf-module-api</artifactId> <version>${deltaspike.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-jsf-module-impl</artifactId> <version>${deltaspike.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.picketlink</groupId> <artifactId>picketlink-api</artifactId> </dependency> <dependency> <groupId>org.picketlink</groupId> <artifactId>picketlink-impl</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.picketlink</groupId> <artifactId>picketlink-idm-api</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.picketlink</groupId> <artifactId>picketlink-idm-impl</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.picketlink</groupId> <artifactId>picketlink-idm-simple-schema</artifactId> </dependency> <dependency> <groupId>org.picketlink</groupId> <artifactId>picketlink-deltaspike</artifactId> <version>2.7.0.Final</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>${javaee.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.omnifaces</groupId> <artifactId>omnifaces</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>net.bootsfaces</groupId> <artifactId>bootsfaces</artifactId> <version>0.8.5</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.primefaces</groupId> <artifactId>primefaces</artifactId> <version>5.3</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.primefaces.extensions</groupId> <artifactId>all-themes</artifactId> <version>1.0.8</version> <scope>compile</scope> </dependency> </dependencies>
注 picketlink 按官方推荐的方式会有错误, 和DeltaSpike有冲突 启起时出错,分开就没有问题了。 Caused by: java.lang.InternalError: Enclosing method not found at java.lang.Class.getEnclosingMethod(Class.java:957) [rt.jar:1.7.0_71] at sun.reflect.generics.scope.ClassScope.computeEnclosingScope(ClassScope.java:50) [rt.jar:1.7.0_71] at sun.reflect.generics.scope.AbstractScope.getEnclosingScope(AbstractScope.java:74) [rt.jar:1.7.0_71] at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:90) [rt.jar:1.7.0_71] at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:90) [rt.jar:1.7.0_71] at sun.reflect.generics.factory.CoreReflectionFactory.findTypeVariable(CoreReflectionFactory.java:110) [rt.jar:1.7.0_71] at sun.reflect.generics.visitor.Reifier.visitTypeVariableSignature(Reifier.java:165) [rt.jar:1.7.0_71] at sun.reflect.generics.tree.TypeVariableSignature.accept(TypeVariableSignature.java:43) [rt.jar:1.7.0_71] at sun.reflect.generics.repository.MethodRepository.getReturnType(MethodRepository.java:68) [rt.jar:1.7.0_71] at java.lang.reflect.Method.getGenericReturnType(Method.java:245) [rt.jar:1.7.0_71] at org.jboss.weld.annotated.slim.backed.BackedAnnotatedMethod.<init>(BackedAnnotatedMethod.java:38) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedMethod.of(BackedAnnotatedMethod.java:32) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.computeValue(BackedAnnotatedType.java:199) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.computeValue(BackedAnnotatedType.java:192) at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:35) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$EagerlyInitializedLazyValueHolder.<init>(BackedAnnotatedType.java:160) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.<init>(BackedAnnotatedType.java:192) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.<init>(BackedAnnotatedType.java:192) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.<init>(BackedAnnotatedType.java:67) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.of(BackedAnnotatedType.java:48) at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.load(ClassTransformer.java:83) at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.load(ClassTransformer.java:80) at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317) at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280) at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195) 1.认证
有几种方式
1.使用 picketlink 的 存储
使用ibm的存储结构:
<dependency> <groupId>org.picketlink</groupId> <artifactId>picketlink-idm-simple-schema</artifactId> </dependency>
也可以根据接口自定义存储结构
具体后续补充。。。
2、自定义认证
@PicketLink public class SimpleAuthenticator extends BaseAuthenticator { @Inject private DefaultLoginCredentials credentials; @Inject @ErpEM private EntityManager entityManager; @Inject private FacesContext facesContext; public void authenticate() { if ("root".equals(credentials.getUserId()) && "cooper".equals(credentials.getPassword())) { setStatus(AuthenticationStatus.SUCCESS); setAccount(new User("root")); //TODO roles; } else { facesContext.addMessage(null, new FacesMessage( "Authentication Failure - The username or password you provided were invalid.")); } } }