Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'OpenIDProviderExampleTest' of https://github.com/smigie…
…lski/security into smig-openidtest
- Loading branch information
Showing
10 changed files
with
687 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 17 additions & 6 deletions
23
...id-op/src/main/java/org/jboss/seam/security/examples/openid/OpenIdProviderCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
examples/openid-op/src/main/java/org/jboss/seam/security/examples/openid/PropertyReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
examples/openid-op/src/test/java/org/jboss/seam/security/examples/openid/DeploymentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.