Skip to content

Commit

Permalink
Merge branch 'OpenIDProviderExampleTest' of https://github.com/smigie…
Browse files Browse the repository at this point in the history
…lski/security into smig-openidtest
  • Loading branch information
sbryzak committed Mar 3, 2011
2 parents 6d20c64 + 2defdcd commit 2cc659a
Show file tree
Hide file tree
Showing 10 changed files with 687 additions and 9 deletions.
141 changes: 138 additions & 3 deletions examples/openid-op/pom.xml
Expand Up @@ -5,7 +5,10 @@
<artifactId>openid-op</artifactId>
<packaging>war</packaging>
<name>OpenID Relying Party</name>


<properties>
<jboss-javaee6-spec.version>1.0.0.Final</jboss-javaee6-spec.version>
</properties>
<parent>
<groupId>org.jboss.seam.security</groupId>
<artifactId>seam-security-parent</artifactId>
Expand Down Expand Up @@ -67,7 +70,139 @@
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>

<!-- Needed for running tests (you may also use TestNG) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Optional, but highly recommended -->
<!--
Arquillian allows you to test enterprise code such as EJBs and
Transactional(JTA) JPA from JUnit/TestNG
-->
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<!--
The default profile skips all tests, though you can tune it to run
just unit tests based on a custom pattern
-->
<!--
Seperate profiles are provided for running all tests, including
Arquillian tests that execute in the specified container
-->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<!-- Java EE 6 API dependency -->
<!--
This one dependency imports all APIs available for a Java EE 6.0
application
-->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${jboss-javaee6-spec.version}</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!--
Optional JBoss deployer plugin will deploy your war to a local
JBoss AS container if you've declared $JBOSS_HOME in your OS
-->
<!--
To use, set the JBOSS_HOME environment variable (or jboss.home in
$HOME/.m2/settings.xml) and run 'mvn package jboss:hard-deploy'
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.4.1</version>
<configuration>
<jbossHome>${jboss.home}</jbossHome>
<serverName>${jboss.domain}</serverName>
<fileNames>
<fileName>${project.build.directory}/${project.build.finalName}.war</fileName>
<!--
JNDI Datasource that connects to in-memory HSQLDB to
demonstrate JPA
-->
<fileName>src/main/resources-jbossas/default-ds.xml</fileName>
</fileNames>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!--
An optional Arquillian testing profile that executes tests in a
remote JBoss AS instance
-->
<!-- Run with 'mvn clean test -Pjbossas-remote-6' -->
<id>jbossas-remote-6</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-remote-6</artifactId>
<scope>test</scope>
</dependency>
<!-- Java EE 6 API dependency -->
<!--
This one dependency imports all APIs available for a Java EE 6.0
application
-->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${jboss-javaee6-spec.version}</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<!-- needed for org.jnp.interfaces.NamingContextFactory -->
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/main/webapp</directory>
</testResource>
<!--
Overrides default configuration to use alternate persistence.xml
with Hibernate settings and declare a JBoss AS Datasource
-->
<!-- Used by Arquillian -->
<testResource>
<directory>src/test/resources-jbossas</directory>
</testResource>
</testResources>
</build>
</profile>
</profiles>
</project>
@@ -1,18 +1,29 @@
package org.jboss.seam.security.examples.openid;

import java.util.Properties;

import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.servlet.ServletContext;

import org.jboss.seam.security.external.openid.api.OpenIdProviderConfigurationApi;
import org.jboss.seam.servlet.event.Initialized;
import org.jboss.seam.solder.resourceLoader.Resource;


public class OpenIdProviderCustomizer
{
public void servletInitialized(@Observes @Initialized final ServletContext context, OpenIdProviderConfigurationApi op)
{
op.setHostName("www.openid-op.com");
op.setPort(8080);
op.setProtocol("http");
}
@Inject
@Resource("openIdProviderCustomizer.properties")
private Properties properties;

public void servletInitialized(@Observes @Initialized final ServletContext context, OpenIdProviderConfigurationApi op) {

PropertyReader propertyReader = new PropertyReader(properties);

op.setHostName(propertyReader.getString("hostName", "www.openid-op.com"));
op.setPort(propertyReader.getInt("port", 8080));
op.setProtocol(propertyReader.getString("protocol", "http"));
}

}
@@ -0,0 +1,54 @@
package org.jboss.seam.security.examples.openid;

import java.util.Properties;

import org.jboss.seam.solder.core.Veto;


@Veto
public class PropertyReader
{
private Properties properties;

public PropertyReader(Properties properties)
{
super();
this.properties = properties;
}

public String getString(String name, String defaultValue)
{
if (properties != null)
{
return properties.getProperty(name, defaultValue);
}
return defaultValue;
}

public int getInt(String name, int defaultValue)
{
if (properties != null && properties.containsKey(name))
{
return Integer.parseInt(properties.getProperty(name));
}
return defaultValue;
}

public boolean getBoolean(String name, boolean defaultValue)
{
if (properties != null && properties.containsKey(name))
{
return Boolean.parseBoolean(properties.getProperty(name));
}
return defaultValue;
}

public String[] getStringArray(String name, String[] defaultValue)
{
if (properties != null && properties.containsKey(name))
{
return properties.getProperty(name).split(";");
}
return defaultValue;
}
}
@@ -0,0 +1,85 @@
package org.jboss.seam.security.examples.openid;


import javax.inject.Inject;

import junit.framework.Assert;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.security.examples.openidClient.OpenIdTestClient;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;


/**
* Test class for HomePage and SeamWicketTester.
*
* @author oranheim
*/
@RunWith(Arquillian.class)
public class DeploymentTest
{

@Deployment
public static WebArchive createTestArchive()
{

WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
.addPackage(OpenIdProviderSpiImpl.class.getPackage())
.addClass(OpenIdTestClient.class)
.addWebResource("WEB-INF/beans.xml", "beans.xml")
.addWebResource("WEB-INF/faces-config.xml", "faces-config.xml")
//Jsf pages particpating in login process
.addResource("Login.xhtml","Login.xhtml")
.addResource("PageTemplate.xhtml","PageTemplate.xhtml")
.addResource("Attributes.xhtml","Attributes.xhtml")
.addResource("Menu.xhtml","Menu.xhtml")
.addResource("openIdProviderCustomizer.properties","WEB-INF/classes/openIdProviderCustomizer.properties")
.addLibraries(MavenArtifactResolver.resolve("org.jboss.seam.security:seam-security-external"))

// .addLibraries(MavenArtifactResolver.resolve("org.picketlink.idm:picketlink-idm-api"))
// .addLibraries(MavenArtifactResolver.resolve("org.picketlink.idm:picketlink-idm-core"))
// .addLibraries(MavenArtifactResolver.resolve("org.picketlink.idm:picketlink-idm-spi"))
// .addLibraries(MavenArtifactResolver.resolve("org.jboss.seam.persistence:seam-persistence"))

.addLibraries(MavenArtifactResolver.resolve("org.openid4java:openid4java-server"))
.addLibraries(MavenArtifactResolver.resolve("org.openid4java:openid4java-nodeps"))
.addLibraries(MavenArtifactResolver.resolve("commons-httpclient:commons-httpclient"))
.addLibraries(MavenArtifactResolver.resolve("nekohtml:nekohtml"))
.addLibraries(MavenArtifactResolver.resolve("org.jboss.seam.servlet:seam-servlet"))
.addLibraries(MavenArtifactResolver.resolve("org.jboss.seam.solder:seam-solder"))
.setWebXML("WEB-INF/web.xml");;
return archive;
}


@Inject
OpenIdTestClient openIdTestClient;

@Test
public void testDeploy() throws Exception
{

String destinationUrl = openIdTestClient.authRequest("http://localhost:8080/test/users/test_user");
Assert.assertNotNull(destinationUrl);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(destinationUrl);
int statusCode = client.executeMethod(method);
Assert.assertEquals(200, statusCode);

//Rest of test should be done in jsfunit or similar framework.

//Form processing is: Login.jsf , login -> Attributes.jsf, ok -> back to relaying party



}


}

0 comments on commit 2cc659a

Please sign in to comment.