Skip to content

Commit

Permalink
[WFLY-10614] Fork existing test cases to test authentication using ma…
Browse files Browse the repository at this point in the history
…ppings to security domains instead of authentication factories.
  • Loading branch information
darranl committed Jun 25, 2018
1 parent 938d6eb commit a4f62b1
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 127 deletions.
Expand Up @@ -98,34 +98,42 @@ protected String getSecurityDomain() {
return DEFAULT_SECURITY_DOMAIN; return DEFAULT_SECURITY_DOMAIN;
} }


protected boolean useAuthenticationFactory() {
return true;
}

@Override @Override
protected ConfigurableElement[] getConfigurableElements() { protected ConfigurableElement[] getConfigurableElements() {
return new ConfigurableElement[] { ConfigurableElement[] elements = useAuthenticationFactory() ? new ConfigurableElement[2] : new ConfigurableElement[1];
SimpleHttpAuthenticationFactory.builder() if (useAuthenticationFactory()) {
.withName(HTTP_FACTORY) elements[0] = SimpleHttpAuthenticationFactory.builder()
.withHttpServerMechanismFactory(DEFAULT_MECHANISM_FACTORY) .withName(HTTP_FACTORY)
.withSecurityDomain(getSecurityDomain()) .withHttpServerMechanismFactory(DEFAULT_MECHANISM_FACTORY)
.addMechanismConfiguration(getMechanismConfiguration()) .withSecurityDomain(getSecurityDomain())
.build(), .addMechanismConfiguration(getMechanismConfiguration())
new ConfigurableElement() { .build();

}
@Override elements[elements.length - 1] = new ConfigurableElement() {
public String getName() {
return "Configure undertow application-security-domain " + APP_DOMAIN; @Override
} public String getName() {

return "Configure undertow application-security-domain " + APP_DOMAIN;
@Override }
public void create(CLIWrapper cli) throws Exception {
cli.sendLine("/subsystem=undertow/application-security-domain=" + APP_DOMAIN + ":add(http-authentication-factory=" + HTTP_FACTORY + ")"); @Override
} public void create(CLIWrapper cli) throws Exception {

String argument = useAuthenticationFactory() ? "http-authentication-factory=" + HTTP_FACTORY : "security-domain=" + getSecurityDomain();
@Override cli.sendLine("/subsystem=undertow/application-security-domain=" + APP_DOMAIN + ":add(" + argument + ")");
public void remove(CLIWrapper cli) throws Exception { }
cli.sendLine("/subsystem=undertow/application-security-domain=" + APP_DOMAIN + ":remove");
} @Override

public void remove(CLIWrapper cli) throws Exception {
} cli.sendLine("/subsystem=undertow/application-security-domain=" + APP_DOMAIN + ":remove");
}

}; };

return elements;
} }
} }


Expand Down
@@ -0,0 +1,48 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.test.integration.elytron.http;

import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.junit.runner.RunWith;
import org.wildfly.test.security.common.elytron.MechanismConfiguration;

/**
* Test of FORM HTTP mechanism.
*
* @author Jan Kalina
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({ FormMechTestBase.ServerSetup.class })
public class FormMechTestBase extends FormMechTestCase {

static class ServerSetup extends AbstractMechTestBase.ServerSetup {
@Override protected MechanismConfiguration getMechanismConfiguration() {
return MechanismConfiguration.builder()
.withMechanismName("FORM")
.build();
}
}
}
Expand Up @@ -46,28 +46,20 @@
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.integration.security.common.Utils; import org.jboss.as.test.integration.security.common.Utils;
import org.jboss.as.test.integration.security.common.servlets.SimpleServlet; import org.jboss.as.test.integration.security.common.servlets.SimpleServlet;
import org.jboss.as.test.integration.web.sso.LogoutServlet; import org.jboss.as.test.integration.web.sso.LogoutServlet;
import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.security.common.elytron.MechanismConfiguration;


/** /**
* Test of FORM HTTP mechanism. * Test of FORM HTTP mechanism.
* *
* @author Jan Kalina * @author Jan Kalina
*/ */
@RunWith(Arquillian.class) abstract class FormMechTestCase extends AbstractMechTestBase {
@RunAsClient
@ServerSetup({ FormMechTestCase.ServerSetup.class })
public class FormMechTestCase extends AbstractMechTestBase {


private static final String NAME = FormMechTestCase.class.getSimpleName(); private static final String NAME = FormMechTestCase.class.getSimpleName();
private static final String LOGIN_PAGE_CONTENT = "LOGINPAGE"; private static final String LOGIN_PAGE_CONTENT = "LOGINPAGE";
Expand Down Expand Up @@ -206,11 +198,4 @@ public void testInvalidCredential() throws Exception {
} }
} }


static class ServerSetup extends AbstractMechTestBase.ServerSetup {
@Override protected MechanismConfiguration getMechanismConfiguration() {
return MechanismConfiguration.builder()
.withMechanismName("FORM")
.build();
}
}
} }
@@ -0,0 +1,71 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.test.integration.elytron.http;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.integration.security.common.Utils;
import org.jboss.as.test.integration.security.common.servlets.SimpleServlet;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;
import org.wildfly.test.security.common.elytron.MechanismConfiguration;

/**
* Test of BASIC HTTP mechanism using a direct reference to the security domain instead of an authentication factory.
*
* @author Jan Kalina
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({ MinimalBasicMechTestCase.ServerSetup.class })
public class MinimalBasicMechTestCase extends PasswordMechTestBase {

private static final String NAME = MinimalBasicMechTestCase.class.getSimpleName();

@Deployment(testable = false)
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class, NAME + ".war")
.addClasses(SimpleServlet.class)
.addAsWebInfResource(Utils.getJBossWebXmlAsset(APP_DOMAIN), "jboss-web.xml")
.addAsWebInfResource(MinimalBasicMechTestCase.class.getPackage(), BasicMechTestCase.class.getSimpleName() + "-web.xml", "web.xml");
}

static class ServerSetup extends AbstractMechTestBase.ServerSetup {

@Override
protected boolean useAuthenticationFactory() {
return false;
}

@Override
protected MechanismConfiguration getMechanismConfiguration() {
// As we are not using an authentication factory the mechanisms do not require configuration.
return null;
}

}
}
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>org.jboss.as.test.integration.security.common.servlets.SimpleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<security-constraint>
<web-resource-collection>
<web-resource-name>Role1</web-resource-name>
<url-pattern>/role1</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Role1</role-name>
</auth-constraint>
</security-constraint>

<security-constraint>
<web-resource-collection>
<web-resource-name>Role2</web-resource-name>
<url-pattern>/role2</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Role2</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>DIGEST</auth-method>
<realm-name>Digest kingdom</realm-name>
</login-config>


<security-role>
<role-name>Role1</role-name>
</security-role>
<security-role>
<role-name>Role2</role-name>
</security-role>

</web-app>
@@ -0,0 +1,71 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.test.integration.elytron.http;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.integration.security.common.Utils;
import org.jboss.as.test.integration.security.common.servlets.SimpleServlet;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;
import org.wildfly.test.security.common.elytron.MechanismConfiguration;

/**
* Test of DIGEST HTTP mechanism using a direct reference to the security domain instead of an authentication factory.
*
* @author Jan Kalina
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({ MinimalDigestMechTestCase.ServerSetup.class })
public class MinimalDigestMechTestCase extends PasswordMechTestBase {

private static final String NAME = MinimalDigestMechTestCase.class.getSimpleName();

@Deployment(testable = false)
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class, NAME + ".war")
.addClasses(SimpleServlet.class)
.addAsWebInfResource(Utils.getJBossWebXmlAsset(APP_DOMAIN), "jboss-web.xml")
.addAsWebInfResource(MinimalDigestMechTestCase.class.getPackage(), NAME + "-web.xml", "web.xml");
}

static class ServerSetup extends AbstractMechTestBase.ServerSetup {

@Override
protected boolean useAuthenticationFactory() {
return false;
}

@Override
protected MechanismConfiguration getMechanismConfiguration() {
// As we are not using an authentication factory the mechanisms do not require configuration.
return null;
}

}
}

0 comments on commit a4f62b1

Please sign in to comment.