Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Arquillian resources initial project setup

  • Loading branch information...
commit c537a622fb82f869d60de25e1d549a11491c7124 1 parent 36726d1
Bruno Oliveira authored
View
2  .gitignore
@@ -0,0 +1,2 @@
+.idea/
+*.iml
View
106 pom.xml
@@ -0,0 +1,106 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.jboss.aerogear.security</groupId>
+ <artifactId>aerogear-security</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>aerogear-core</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <deltaspike.version>0.2-incubating-SNAPSHOT</deltaspike.version>
+ <resteasy.version>2.3.1.GA</resteasy.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-bom</artifactId>
+ <version>1.0.0.CR7</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-6.0</artifactId>
+ <version>1.0.0.Final</version>
+ <type>pom</type>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easytesting</groupId>
+ <artifactId>fest-assert</artifactId>
+ <version>1.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.protocol</groupId>
+ <artifactId>arquillian-protocol-servlet</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxrs</artifactId>
+ <version>${resteasy.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-security</artifactId>
+ <version>7.1.1.Final</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>arq-jbossas-remote</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-arquillian-container-remote</artifactId>
+ <version>7.1.1.Final</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+</project>
View
54 src/main/java/org/jboss/aerogear/security/auth/Authenticator.java
@@ -0,0 +1,54 @@
+package org.jboss.aerogear.security.auth;
+
+import org.jboss.security.AuthenticationManager;
+import org.jboss.security.SecurityContext;
+import org.picketbox.config.PicketBoxConfiguration;
+import org.picketbox.factories.SecurityFactory;
+
+import java.security.Principal;
+
+public class Authenticator {
+
+ //Arbitrary Method for authentication
+ public void authenticate() {
+ //The security domain name is the one used in the configuration file listing the modules
+ String securityDomainName = "test";
+ SecurityFactory.prepare();
+ try {
+ String configFile = "authentication.conf";
+ PicketBoxConfiguration idtrustConfig = new PicketBoxConfiguration();
+ idtrustConfig.load(configFile);
+
+ SecurityContext securityContext = SecurityFactory.establishSecurityContext(securityDomainName);
+ AuthenticationManager authenticationManager = securityContext.getAuthenticationManager();
+
+ if (authenticationManager == null)
+ throw new RuntimeException("Authentication Manager is null");
+
+ //Subject subject = new Subject();
+ Principal principal = getPrincipal("anil");
+ Object credential = new String("pass");
+
+ boolean result = authenticationManager.isValid(principal, credential);
+ if (result == false)
+ throw new RuntimeException("Authentication Failed");
+
+ result = authenticationManager.isValid(principal, credential);
+ if (result == false)
+ throw new RuntimeException("Authentication Failed");
+
+ System.out.println("Authentication Successful");
+ } finally {
+ SecurityFactory.release();
+ }
+ }
+
+ //Simple method to return a principal
+ private Principal getPrincipal(final String name) {
+ return new Principal() {
+ public String getName() {
+ return name;
+ }
+ };
+ }
+}
View
14 src/main/resources/authentication.conf
@@ -0,0 +1,14 @@
+<?xml version='1.0'?>
+
+<policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:security-config:5.0"
+ xmlns="urn:jboss:security-config:5.0"
+ xmlns:jbxb="urn:jboss:security-config:5.0">
+ <application-policy name = "test">
+ <authentication>
+ <login-module code = "org.jboss.security.auth.spi.UsersRolesLoginModule"
+ flag = "required">
+ </login-module>
+ </authentication>
+ </application-policy>
+</policy>
View
1  src/main/resources/defaultRoles.properties
@@ -0,0 +1 @@
+anil=validuser
View
1  src/main/resources/defaultUsers.properties
@@ -0,0 +1 @@
+anil=pass
View
34 src/test/java/org/jboss/aerogear/security/auth/integration/AuthenticatorTest.java
@@ -0,0 +1,34 @@
+package org.jboss.aerogear.security.auth.integration;
+
+import org.jboss.aerogear.security.auth.Authenticator;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.inject.Inject;
+
+@RunWith(Arquillian.class)
+public class AuthenticatorTest {
+
+ @Inject
+ private Authenticator authenticator;
+
+ @Deployment
+ public static WebArchive createTestArchive() {
+ return ShrinkWrap.create(WebArchive.class, "test.war")
+ .addClasses(Authenticator.class)
+ .addAsResource("authentication.conf", "authentication.conf")
+ .addAsResource("defaultRoles.properties", "defaultRoles.properties")
+ .addAsResource("defaultUsers.properties", "defaultUsers.properties")
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @Test
+ public void testAuthenticate() throws Exception {
+ authenticator.authenticate();
+ }
+}
View
23 src/test/resources/arquillian.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<arquillian xmlns="http://jboss.org/schema/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian
+ http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+ <!-- Uncomment to have test archives exported to the file system for inspection -->
+ <!-- <engine> -->
+ <!-- <property name="deploymentExportPath">target/</property> -->
+ <!-- </engine> -->
+
+ <!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
+ <defaultProtocol type="Servlet 3.0" />
+
+ <!-- Example configuration for a remote JBoss AS 7 instance -->
+ <container qualifier="jboss" default="true">
+ <!-- If you want to use the JBOSS_HOME environment variable, just delete the jbossHome property -->
+ <configuration>
+ <property name="jbossHome">/Users/Bruno/Servers/jboss-current</property>
+ </configuration>
+ </container>
+
+</arquillian>
View
28 src/test/resources/beans.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ JBoss, Home of Professional Open Source
+ Copyright 2012, Red Hat, Inc., and individual contributors
+ by the @authors tag. See the copyright.txt in the distribution for a
+ full listing of individual contributors.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<!-- This file can be an empty text file (0 bytes) -->
+<!-- We're declaring the schema to save you time if you do have to configure
+ this in the future -->
+<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">
+</beans>
Please sign in to comment.
Something went wrong with that request. Please try again.