Skip to content

Commit

Permalink
[WFLY-8278] Tests for Elytron+Batch subsystem integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartisk committed Mar 3, 2017
1 parent 509c3ef commit 80f5b25
Show file tree
Hide file tree
Showing 14 changed files with 1,034 additions and 18 deletions.

Large diffs are not rendered by default.

@@ -0,0 +1,51 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.batch;

import javax.batch.api.BatchProperty;
import javax.batch.api.Batchlet;
import javax.inject.Inject;
import javax.inject.Named;

/**
* @author Jan Martiska
*/
@Named
public class FailingBatchlet implements Batchlet {

@Inject
@BatchProperty(name = "should.fail")
private Boolean shouldFail;

@Override
public String process() throws Exception {
if(shouldFail)
throw new Exception("failing the job on purpose");
return "OK";
}

@Override
public void stop() throws Exception {

}
}
@@ -0,0 +1,51 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.batch;

import javax.batch.api.Batchlet;
import javax.inject.Named;

import org.jboss.logging.Logger;
import org.wildfly.security.auth.server.SecurityDomain;

/**
* @author Jan Martiska
*/
@Named
public class IdentityBatchlet implements Batchlet {

private Logger logger = Logger.getLogger(IdentityBatchlet.class);

@Override
public String process() throws Exception {
final String name = SecurityDomain.getCurrent().getCurrentSecurityIdentity().getPrincipal().getName();
logger.info("Batchlet running as username: " + name);
BatchSubsystemSecurityTestCase.identityWithinJob.complete(name);
return "OK";
}

@Override
public void stop() throws Exception {

}
}
@@ -0,0 +1,55 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.batch;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import javax.batch.api.Batchlet;
import javax.batch.runtime.context.JobContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.jboss.as.test.shared.TimeoutUtil;

/**
* @author Jan Martiska
*/
@Named
public class LongRunningBatchlet implements Batchlet {

private final CompletableFuture<Void> SHOULD_STOP = new CompletableFuture<>();

@Inject
JobContext ctx;

@Override
public String process() throws Exception {
SHOULD_STOP.get(TimeoutUtil.adjust(10), TimeUnit.SECONDS);
return null;
}

@Override
public void stop() throws Exception {
SHOULD_STOP.complete(null);
}
}
@@ -0,0 +1,39 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.batch;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import org.jboss.ejb3.annotation.SecurityDomain;

/**
* This is here as just a hack to be able to set the security domain of a deployment.
* See https://issues.jboss.org/browse/JBEAP-8702 discussion for more context.
* @author Jan Martiska
*/
@Stateless
@SecurityDomain("BatchDomain")
@LocalBean
public class SecurityDomainSettingEJB {
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<job id="assert-identity" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">

<step id="perform">
<batchlet ref="identityBatchlet"/>
</step>

</job>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<job id="failing-batchlet" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">

<step id="perform">
<batchlet ref="failingBatchlet">
<properties>
<property name="should.fail" value="#{jobParameters['should.fail']}"/>
</properties>
</batchlet>
</step>

</job>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<job id="long-running-batchlet" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">

<step id="perform">
<batchlet ref="longRunningBatchlet"/>
</step>

</job>
Expand Up @@ -38,7 +38,7 @@
* @author Josef Cacek
*/
public abstract class AbstractElytronSetupTask
implements org.wildfly.core.testrunner.ServerSetupTask, org.jboss.as.arquillian.api.ServerSetupTask {
implements org.jboss.as.arquillian.api.ServerSetupTask {

private static final Logger LOGGER = Logger.getLogger(AbstractElytronSetupTask.class);

Expand All @@ -56,16 +56,6 @@ public void tearDown(final org.jboss.as.arquillian.container.ManagementClient ma
tearDown(managementClient.getControllerClient());
}

@Override
public void setup(org.wildfly.core.testrunner.ManagementClient managementClient) throws Exception {
setup(managementClient.getControllerClient());
}

@Override
public void tearDown(org.wildfly.core.testrunner.ManagementClient managementClient) throws Exception {
tearDown(managementClient.getControllerClient());
}

/**
* Creates configuration elements (provided by implementation of {@link #getConfigurableElements()} method) and calls
* {@link ConfigurableElement#create(CLIWrapper)} for them.
Expand Down
Expand Up @@ -37,9 +37,12 @@ public abstract class AbstractUserRolesSecurityDomain extends AbstractConfigurab

private final List<UserWithRoles> usersWithRoles;

protected final String permissionMapper;

protected AbstractUserRolesSecurityDomain(Builder<?> builder) {
super(builder);
this.usersWithRoles = Collections.unmodifiableList(new ArrayList<>(builder.usersWithRoles));
this.permissionMapper = builder.permMapper;
}

@Override
Expand All @@ -52,6 +55,7 @@ public List<UserWithRoles> getUsersWithRoles() {
*/
public abstract static class Builder<T extends Builder<T>> extends AbstractConfigurableElement.Builder<T> {
private List<UserWithRoles> usersWithRoles = new ArrayList<>();
private String permMapper;

protected Builder() {
}
Expand All @@ -78,6 +82,11 @@ public final T withUser(String username, String password, String... roles) {
return self();
}

public final T permissionMapper(String name) {
permMapper = name;
return self();
}

}

}
@@ -0,0 +1,55 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.security.common.elytron;

import org.jboss.as.test.integration.management.util.CLIWrapper;

/**
* @author Jan Martiska
*/
public class EJBApplicationSecurityDomainMapping implements ConfigurableElement {

private final String appDomain;
private final String elytronDomain;


public EJBApplicationSecurityDomainMapping(String appDomain, String elytronDomain) {
this.appDomain = appDomain;
this.elytronDomain = elytronDomain;
}

@Override
public String getName() {
return appDomain;
}

@Override
public void create(CLIWrapper cli) throws Exception {
cli.sendLine("/subsystem=ejb3/application-security-domain="+ appDomain +":add(security-domain="+elytronDomain+")");
}

@Override
public void remove(CLIWrapper cli) throws Exception {
cli.sendLine("/subsystem=ejb3/application-security-domain="+ appDomain +":remove");
}
}
@@ -0,0 +1,49 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.security.common.elytron;

/**
* @author Jan Martiska
*/
public interface PermissionMapper extends ConfigurableElement {

enum MappingMode {
AND("and"),
FIRST("first"),
OR("or"),
UNLESS("unless"),
XOR("xor");

MappingMode(String string) {
this.string = string;
}

private String string;

@Override
public String toString() {
return string;
}
}

}

0 comments on commit 80f5b25

Please sign in to comment.