use of org.jboss.as.subsystem.test.KernelServices in project wildfly by wildfly.
the class SecurityDomainModelv12UnitTestCase method testOrder.
@Test
public void testOrder() throws Exception {
KernelServices service = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXmlResource("securitysubsystemv12.xml").build();
PathAddress address = PathAddress.pathAddress().append("subsystem", "security").append("security-domain", "ordering");
address = address.append("authentication", "classic");
ModelNode writeOp = Util.createOperation("write-attribute", address);
writeOp.get("name").set("login-modules");
for (int i = 1; i <= 6; i++) {
ModelNode module = writeOp.get("value").add();
module.get("code").set("module-" + i);
module.get("flag").set("optional");
module.get("module-options");
}
service.executeOperation(writeOp);
ModelNode readOp = Util.createOperation("read-attribute", address);
readOp.get("name").set("login-modules");
ModelNode result = service.executeForResult(readOp);
List<ModelNode> modules = result.asList();
Assert.assertEquals("There should be exactly 6 modules but there are not", 6, modules.size());
for (int i = 1; i <= 6; i++) {
ModelNode module = modules.get(i - 1);
Assert.assertEquals(module.get("code").asString(), "module-" + i);
}
}
use of org.jboss.as.subsystem.test.KernelServices in project wildfly by wildfly.
the class SecurityDomainModelv1UnitTestCase method testParseAndMarshalModel.
@Test
public void testParseAndMarshalModel() throws Exception {
//Parse the subsystem xml and install into the first controller
String subsystemXml = readResource("securitysubsystemv1.xml");
KernelServices servicesA = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT).setSubsystemXml(subsystemXml).build();
//Get the model and the persisted xml from the first controller
ModelNode modelA = servicesA.readWholeModel();
String marshalled = servicesA.getPersistedSubsystemXml();
servicesA.shutdown();
//Install the persisted xml from the first controller into a second controller
KernelServices servicesB = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT).setSubsystemXml(marshalled).build();
ModelNode modelB = servicesB.readWholeModel();
//Make sure the models from the two controllers are identical
super.compare(modelA, modelB);
}
use of org.jboss.as.subsystem.test.KernelServices in project wildfly by wildfly.
the class SecurityDomainModelv30UnitTestCase method testTransformers.
private void testTransformers(ModelTestControllerVersion controllerVersion) throws Exception {
KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization());
ModelVersion version = ModelVersion.create(1, 3, 0);
final String mavenGavVersion = controllerVersion.getMavenGavVersion();
final String artifactId;
if (controllerVersion.isEap() && mavenGavVersion.equals(controllerVersion.getCoreVersion())) {
/* EAP 6 */
artifactId = "jboss-as-security";
} else {
artifactId = "wildfly-security";
}
builder.createLegacyKernelServicesBuilder(AdditionalInitialization.MANAGEMENT, controllerVersion, version).addMavenResourceURL(controllerVersion.getMavenGroupId() + ":" + artifactId + ":" + mavenGavVersion);
KernelServices mainServices = builder.build();
assertTrue(mainServices.isSuccessfulBoot());
KernelServices legacyServices = mainServices.getLegacyServices(version);
assertNotNull(legacyServices);
assertTrue(legacyServices.isSuccessfulBoot());
// any elytron-related resources in the model should get rejected as those are not supported in model version 1.3.0.
PathAddress subsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, getMainSubsystemName()));
ModelTestUtils.checkFailedTransformedBootOperations(mainServices, version, builder.parseXmlResource("securitysubsystemv30.xml"), new FailedOperationTransformationConfig().addFailedAttribute(PathAddress.pathAddress(subsystemAddress, PathElement.pathElement(Constants.ELYTRON_REALM)), FailedOperationTransformationConfig.REJECTED_RESOURCE).addFailedAttribute(PathAddress.pathAddress(subsystemAddress, PathElement.pathElement(Constants.ELYTRON_KEY_STORE)), FailedOperationTransformationConfig.REJECTED_RESOURCE).addFailedAttribute(PathAddress.pathAddress(subsystemAddress, PathElement.pathElement(Constants.ELYTRON_TRUST_STORE)), FailedOperationTransformationConfig.REJECTED_RESOURCE).addFailedAttribute(PathAddress.pathAddress(subsystemAddress, PathElement.pathElement(Constants.ELYTRON_KEY_MANAGER)), FailedOperationTransformationConfig.REJECTED_RESOURCE).addFailedAttribute(PathAddress.pathAddress(subsystemAddress, PathElement.pathElement(Constants.ELYTRON_TRUST_MANAGER)), FailedOperationTransformationConfig.REJECTED_RESOURCE).addFailedAttribute(PathAddress.pathAddress(subsystemAddress, PathElement.pathElement(Constants.SECURITY_DOMAIN, "domain-with-custom-audit-provider"), SecurityExtension.PATH_AUDIT_CLASSIC, PathElement.pathElement(Constants.PROVIDER_MODULE, "org.myorg.security.MyCustomLogAuditProvider")), new FailedOperationTransformationConfig.NewAttributesConfig(Constants.MODULE)).addFailedAttribute(PathAddress.pathAddress(subsystemAddress, PathElement.pathElement(Constants.SECURITY_MANAGEMENT)), new FailedOperationTransformationConfig.NewAttributesConfig(Constants.INITIALIZE_JACC)));
}
use of org.jboss.as.subsystem.test.KernelServices in project wildfly by wildfly.
the class MailSubsystem21TestCase method testOperations.
@Test
public void testOperations() throws Exception {
KernelServicesBuilder builder = createKernelServicesBuilder(new MailSubsystem10TestCase.Initializer()).setSubsystemXml(getSubsystemXml());
KernelServices mainServices = builder.build();
if (!mainServices.isSuccessfulBoot()) {
Assert.fail(mainServices.getBootError().toString());
}
PathAddress sessionAddress = PathAddress.pathAddress(MailExtension.SUBSYSTEM_PATH, PathElement.pathElement(MailExtension.MAIL_SESSION_PATH.getKey(), "defaultMail"));
ModelNode result;
ModelNode removeServerOp = Util.createRemoveOperation(sessionAddress.append("server", "imap"));
removeServerOp.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
result = mainServices.executeOperation(removeServerOp);
checkResult(result);
ModelNode addServerOp = Util.createAddOperation(sessionAddress.append("server", "imap"));
addServerOp.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
addServerOp.get("outbound-socket-binding-ref").set("mail-imap");
addServerOp.get("username").set("user");
addServerOp.get("password").set("pswd");
result = mainServices.executeOperation(addServerOp);
checkResult(result);
//to make sure noting is left behind
checkResult(mainServices.executeOperation(removeServerOp));
checkResult(mainServices.executeOperation(addServerOp));
ModelNode writeOp = Util.createEmptyOperation(WRITE_ATTRIBUTE_OPERATION, sessionAddress);
writeOp.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
writeOp.get("name").set("debug");
writeOp.get("value").set(false);
result = mainServices.executeOperation(writeOp);
checkResult(result);
ServiceController<?> javaMailService = mainServices.getContainer().getService(MailSessionAdd.MAIL_SESSION_SERVICE_NAME.append("defaultMail"));
javaMailService.setMode(ServiceController.Mode.ACTIVE);
Session session = (Session) javaMailService.getValue();
Assert.assertNotNull("session should not be null", session);
Properties properties = session.getProperties();
Assert.assertNotNull("smtp host should be set", properties.getProperty("mail.smtp.host"));
Assert.assertNotNull("imap host should be set", properties.getProperty("mail.imap.host"));
PathAddress nonExisting = PathAddress.pathAddress(MailExtension.SUBSYSTEM_PATH, PathElement.pathElement(MailExtension.MAIL_SESSION_PATH.getKey(), "non-existing-session"));
ModelNode addSession = Util.createAddOperation(nonExisting);
addSession.get("jndi-name").set("java:/bah");
checkResult(mainServices.executeOperation(addSession));
removeServerOp = Util.createRemoveOperation(nonExisting.append("server", "imap"));
//removeServerOp.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
result = mainServices.executeOperation(removeServerOp);
checkForFailure(result);
}
use of org.jboss.as.subsystem.test.KernelServices in project wildfly by wildfly.
the class MailSubsystem21TestCase method testRuntime.
@Test
public void testRuntime() throws Exception {
KernelServicesBuilder builder = createKernelServicesBuilder(new MailSubsystem10TestCase.Initializer()).setSubsystemXml(getSubsystemXml());
KernelServices mainServices = builder.build();
if (!mainServices.isSuccessfulBoot()) {
Assert.fail(mainServices.getBootError().toString());
}
ServiceController<?> javaMailService = mainServices.getContainer().getService(MailSessionAdd.MAIL_SESSION_SERVICE_NAME.append("defaultMail"));
javaMailService.setMode(ServiceController.Mode.ACTIVE);
Session session = (Session) javaMailService.getValue();
Assert.assertNotNull("session should not be null", session);
Properties properties = session.getProperties();
Assert.assertNotNull("smtp host should be set", properties.getProperty("mail.smtp.host"));
Assert.assertNotNull("pop3 host should be set", properties.getProperty("mail.pop3.host"));
Assert.assertNotNull("imap host should be set", properties.getProperty("mail.imap.host"));
PasswordAuthentication auth = session.requestPasswordAuthentication(InetAddress.getLocalHost(), 25, "smtp", "", "");
Assert.assertEquals("nobody", auth.getUserName());
Assert.assertEquals("pass", auth.getPassword());
ServiceController<?> defaultMailService = mainServices.getContainer().getService(MailSessionAdd.MAIL_SESSION_SERVICE_NAME.append("default2"));
session = (Session) defaultMailService.getValue();
Assert.assertEquals("Debug should be true", true, session.getDebug());
ServiceController<?> customMailService = mainServices.getContainer().getService(MailSessionAdd.MAIL_SESSION_SERVICE_NAME.append("custom"));
session = (Session) customMailService.getValue();
properties = session.getProperties();
String host = properties.getProperty("mail.smtp.host");
Assert.assertNotNull("smtp host should be set", host);
Assert.assertEquals("mail.example.com", host);
//this one should be read out of socket binding
Assert.assertEquals("localhost", properties.get("mail.pop3.host"));
//this one should be extra property
Assert.assertEquals("some-custom-prop-value", properties.get("mail.pop3.custom_prop"));
//this one should be extra property
Assert.assertEquals("fully-qualified-prop-name", properties.get("some.fully.qualified.property"));
MailSessionService service = (MailSessionService) customMailService.getService();
Credentials credentials = service.getConfig().getCustomServers()[0].getCredentials();
Assert.assertEquals(credentials.getUsername(), "username");
Assert.assertEquals(credentials.getPassword(), "password");
}
Aggregations