From 5e1b5c345a978d21a6ad6a713df8a03153d04049 Mon Sep 17 00:00:00 2001 From: Tomaz Cerar Date: Tue, 16 May 2017 16:43:20 +0200 Subject: [PATCH] security transformers - non deprecated api --- .../jboss/as/security/SecurityExtension.java | 29 --------- .../as/security/SecurityTransformers.java | 65 +++++++++++++++++++ ...transform.ExtensionTransformerRegistration | 23 +++++++ 3 files changed, 88 insertions(+), 29 deletions(-) create mode 100644 security/subsystem/src/main/java/org/jboss/as/security/SecurityTransformers.java create mode 100644 security/subsystem/src/main/resources/META-INF/services/org.jboss.as.controller.transform.ExtensionTransformerRegistration diff --git a/security/subsystem/src/main/java/org/jboss/as/security/SecurityExtension.java b/security/subsystem/src/main/java/org/jboss/as/security/SecurityExtension.java index f3a1917ed23f..6ee4835cbc2c 100644 --- a/security/subsystem/src/main/java/org/jboss/as/security/SecurityExtension.java +++ b/security/subsystem/src/main/java/org/jboss/as/security/SecurityExtension.java @@ -33,10 +33,6 @@ import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; import org.jboss.as.controller.parsing.ExtensionParsingContext; import org.jboss.as.controller.registry.ManagementResourceRegistration; -import org.jboss.as.controller.transform.description.DiscardAttributeChecker; -import org.jboss.as.controller.transform.description.RejectAttributeChecker; -import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; -import org.jboss.as.controller.transform.description.TransformationDescription; import org.jboss.as.security.elytron.ElytronIntegrationResourceDefinitions; import org.jboss.msc.service.ServiceName; @@ -116,9 +112,6 @@ public void initialize(ExtensionContext context) { // register the subsystem XML persister. subsystem.registerXMLElementWriter(SecuritySubsystemPersister.INSTANCE); - if (context.isRegisterTransformers()) { - registerTransformers(subsystem); - } } @Override @@ -128,26 +121,4 @@ public void initializeParsers(ExtensionParsingContext context) { context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.SECURITY_1_2.getUriString(), SecuritySubsystemParser::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.SECURITY_3_0.getUriString(), SecuritySubsystemParser_3_0::new); } - - private void registerTransformers(SubsystemRegistration subsystemRegistration) { - // only register transformers for model version 1.3.0 (EAP 6.2+). - registerTransformers_1_3_0(subsystemRegistration); - } - - private void registerTransformers_1_3_0(SubsystemRegistration subsystemRegistration) { - ResourceTransformationDescriptionBuilder builder = ResourceTransformationDescriptionBuilder.Factory.createSubsystemInstance(); - builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_REALM)); - builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_KEY_STORE)); - builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_TRUST_STORE)); - builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_KEY_MANAGER)); - builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_TRUST_MANAGER)); - builder.addChildResource(PathElement.pathElement(Constants.SECURITY_MANAGEMENT)) - .getAttributeBuilder() - .addRejectCheck(RejectAttributeChecker.DEFINED, SecuritySubsystemRootResourceDefinition.INITIALIZE_JACC) - .setDiscard(DiscardAttributeChecker.UNDEFINED, SecuritySubsystemRootResourceDefinition.INITIALIZE_JACC); - - SecurityDomainResourceDefinition.registerTransformers_1_3_0(builder); - - TransformationDescription.Tools.register(builder.build(), subsystemRegistration, ModelVersion.create(1, 3, 0)); - } } \ No newline at end of file diff --git a/security/subsystem/src/main/java/org/jboss/as/security/SecurityTransformers.java b/security/subsystem/src/main/java/org/jboss/as/security/SecurityTransformers.java new file mode 100644 index 000000000000..ff03e52570b5 --- /dev/null +++ b/security/subsystem/src/main/java/org/jboss/as/security/SecurityTransformers.java @@ -0,0 +1,65 @@ +/* + * 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.jboss.as.security; + +import org.jboss.as.controller.ModelVersion; +import org.jboss.as.controller.PathElement; +import org.jboss.as.controller.transform.ExtensionTransformerRegistration; +import org.jboss.as.controller.transform.SubsystemTransformerRegistration; +import org.jboss.as.controller.transform.description.DiscardAttributeChecker; +import org.jboss.as.controller.transform.description.RejectAttributeChecker; +import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; +import org.jboss.as.controller.transform.description.TransformationDescription; + +/** + * @author Tomaz Cerar (c) 2017 Red Hat Inc. + */ +public class SecurityTransformers implements ExtensionTransformerRegistration { + @Override + public String getSubsystemName() { + return SecurityExtension.SUBSYSTEM_NAME; + } + + @Override + public void registerTransformers(SubsystemTransformerRegistration subsystemRegistration) { +// only register transformers for model version 1.3.0 (EAP 6.2+). + registerTransformers_1_3_0(subsystemRegistration); + } + + private void registerTransformers_1_3_0(SubsystemTransformerRegistration subsystemRegistration) { + ResourceTransformationDescriptionBuilder builder = ResourceTransformationDescriptionBuilder.Factory.createSubsystemInstance(); + builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_REALM)); + builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_KEY_STORE)); + builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_TRUST_STORE)); + builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_KEY_MANAGER)); + builder.rejectChildResource(PathElement.pathElement(Constants.ELYTRON_TRUST_MANAGER)); + builder.addChildResource(PathElement.pathElement(Constants.SECURITY_MANAGEMENT)) + .getAttributeBuilder() + .addRejectCheck(RejectAttributeChecker.DEFINED, SecuritySubsystemRootResourceDefinition.INITIALIZE_JACC) + .setDiscard(DiscardAttributeChecker.UNDEFINED, SecuritySubsystemRootResourceDefinition.INITIALIZE_JACC); + + SecurityDomainResourceDefinition.registerTransformers_1_3_0(builder); + + TransformationDescription.Tools.register(builder.build(), subsystemRegistration, ModelVersion.create(1, 3, 0)); + } +} diff --git a/security/subsystem/src/main/resources/META-INF/services/org.jboss.as.controller.transform.ExtensionTransformerRegistration b/security/subsystem/src/main/resources/META-INF/services/org.jboss.as.controller.transform.ExtensionTransformerRegistration new file mode 100644 index 000000000000..146ca88515da --- /dev/null +++ b/security/subsystem/src/main/resources/META-INF/services/org.jboss.as.controller.transform.ExtensionTransformerRegistration @@ -0,0 +1,23 @@ +# +# 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. +# + +org.jboss.as.security.SecurityTransformers \ No newline at end of file