How To Setup Seam3-Security Inward Jboss 7

Recently, I've done to a greater extent than or less query on several Java Security Framework that tin perform authentication, authorisation together with cryptography.

I've worked amongst Apache Shiro, it's actually practiced together with consummate precisely I've flora several problems similar there's no default implementation for CDI interceptor for safety annotations. Here's a sample implementation together with setup that I did long ago: https://ngeblognow.blogspot.com//search?q=how-to-integrate-apache-shiro-with.

And long fourth dimension agone I've used seam2-security together with directly I'm trying amongst seam3, hither goes.

1.) I started yesteryear creating a javaee6 projection generated from jboss maven archetype (ear type). This could likewise live on done on a nation of war type projection ofcourse (where the ejbs are inwards ejb project).

2.) In your master copy projection maven's depedencyManagement department add:
<dependency>  <groupId>org.jboss.seam</groupId>  <artifactId>seam-bom</artifactId>  <version>3.1.0.Final</version>  <scope>import</scope>  <type>pom</type> </dependency> 
This volition ensure that nosotros are using the right seam-jar versions across our projects.

3.) And inwards the ejb projection maven's dependencies department add together seam3-security dependency:
<dependency>  <groupId>org.jboss.seam.security</groupId>  <artifactId>seam-security</artifactId>  <scope>compile</scope> </dependency> 

4.) In spider web project, do a beans.xml file inwards WEB-INF folder. This file is likewise required for CDI to work. And hither nosotros define the interceptor:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:s="urn:java:ee" xmlns:security="urn:java:org.jboss.seam.security"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">   <interceptors>   <class>org.jboss.seam.security.SecurityInterceptor</class>  </interceptors>   <security:IdentityImpl>   <s:modifies />   <security:authenticatorClass>com.czetsuya.security.Authenticator   </security:authenticatorClass>  </security:IdentityImpl>  </beans> 

5.) Then nosotros accept to define the interceptor class:
package com.czetsuya.security;  import javax.enterprise.inject.Model; import javax.inject.Inject;  import org.jboss.seam.security.BaseAuthenticator; import org.jboss.seam.security.Credentials; import org.picketlink.idm.impl.api.PasswordCredential; import org.picketlink.idm.impl.api.model.SimpleUser;  @Model populace degree Authenticator extends BaseAuthenticator {  @Inject  Credentials credentials;   populace Authenticator() {   }   @Override  populace void authenticate() {   System.out.println("logging in: " + credentials.getUsername());    if ("demo".equals(credentials.getUsername())     && credentials.getCredential() instanceof PasswordCredential     && "demo".equals(((PasswordCredential) credentials.getCredential()).getValue())) {     setStatus(AuthenticationStatus.SUCCESS);    setUser(new SimpleUser("demo"));    }   }  } 

6.) To cover a factor inwards the UI you lot tin move identity.hasPermission or identity.hasRole.

7.) You tin download the origin code from google code at: http://code.google.com/p/czetsuya/source/browse/#svn%2Ftrunk%2Fjboss7-seam3-security
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.