org.jboss.as.controller.ResourceDefinition Java Examples

The following examples show how to use org.jboss.as.controller.ResourceDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrincipalTransformerDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static ResourceDefinition getRegexPrincipalTransformerDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { PATTERN, REPLACEMENT, REPLACE_ALL };
    AbstractAddStepHandler add = new TrivialAddHandler<PrincipalTransformer>(PrincipalTransformer.class, attributes, PRINCIPAL_TRANSFORMER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<PrincipalTransformer> getValueSupplier(ServiceBuilder<PrincipalTransformer> serviceBuilder,
                OperationContext context, ModelNode model) throws OperationFailedException {

            final Pattern pattern     = Pattern.compile(PATTERN.resolveModelAttribute(context, model).asString());
            final String  replacement = REPLACEMENT.resolveModelAttribute(context, model).asString();
            final boolean replaceAll  = REPLACE_ALL.resolveModelAttribute(context, model).asBoolean();

            return () -> PrincipalTransformer.from(new RegexNameRewriter(pattern, replacement, replaceAll).asPrincipalRewriter());
        }
    };

    return new TrivialResourceDefinition(REGEX_PRINCIPAL_TRANSFORMER, add, attributes, PRINCIPAL_TRANSFORMER_RUNTIME_CAPABILITY);
}
 
Example #2
Source File: TrivialResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private TrivialResourceDefinition(String pathKey, ResourceDescriptionResolver resourceDescriptionResolver, AbstractAddStepHandler add, AbstractRemoveStepHandler remove, AttributeDefinition[] attributes,
        Map<AttributeDefinition, OperationStepHandler> readOnlyAttributes, Map<OperationDefinition, OperationStepHandler> operations, List<ResourceDefinition> children,
        RuntimeCapability<?>[] runtimeCapabilities) {
    super(new Parameters(PathElement.pathElement(pathKey),
            resourceDescriptionResolver)
        .setAddHandler(add)
        .setRemoveHandler(remove)
        .setAddRestartLevel(OperationEntry.Flag.RESTART_RESOURCE_SERVICES)
        .setRemoveRestartLevel(OperationEntry.Flag.RESTART_RESOURCE_SERVICES)
        .setCapabilities(runtimeCapabilities));

    this.attributes = attributes;
    this.readOnlyAttributes = readOnlyAttributes;
    this.operations = operations;
    this.children = children;
}
 
Example #3
Source File: ApplicationTypeConstraintUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void setupResources(boolean isA, boolean isB) {

        a.setConfiguredApplication(isA);
        b.setConfiguredApplication(isB);

        ResourceDefinition rootRd = new SimpleResourceDefinition(null, new NonResolvingResourceDescriptionResolver()) {
            @Override
            public List<AccessConstraintDefinition> getAccessConstraints() {
                return rootResourceConstraints;
            }
        };
        ManagementResourceRegistration rootRegistration = ManagementResourceRegistration.Factory.forProcessType(ProcessType.EMBEDDED_SERVER).createRegistration(rootRd);
        rootRegistration.registerOperationHandler(WRITE_CONFIG_DEF, NoopOperationStepHandler.WITHOUT_RESULT, true);

        PathElement childPE = PathElement.pathElement("child");
        ResourceDefinition childRd = new SimpleResourceDefinition(childPE, new NonResolvingResourceDescriptionResolver()) {
            @Override
            public List<AccessConstraintDefinition> getAccessConstraints() {
                return childResourceConstraints;
            }
        };
        ManagementResourceRegistration childRegistration = rootRegistration.registerSubModel(childRd);
        rootTarget = TargetResource.forStandalone(PathAddress.EMPTY_ADDRESS, rootRegistration, Resource.Factory.create());
        childTarget = TargetResource.forStandalone(PathAddress.pathAddress(childPE), childRegistration, Resource.Factory.create());
    }
 
Example #4
Source File: SensitiveTargetConstraintUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void setupResources() {
    ResourceDefinition rootRd = new SimpleResourceDefinition(null, new NonResolvingResourceDescriptionResolver()) {
        @Override
        public List<AccessConstraintDefinition> getAccessConstraints() {
            return rootResourceConstraints;
        }
    };
    ManagementResourceRegistration rootRegistration = ManagementResourceRegistration.Factory.forProcessType(ProcessType.EMBEDDED_SERVER).createRegistration(rootRd);
    rootRegistration.registerOperationHandler(READ_CONFIG_DEF, NoopOperationStepHandler.WITH_RESULT, true);
    PathElement childPE = PathElement.pathElement("child");
    ResourceDefinition childRd = new SimpleResourceDefinition(childPE, new NonResolvingResourceDescriptionResolver()) {
        @Override
        public List<AccessConstraintDefinition> getAccessConstraints() {
            return childResourceConstraints;
        }
    };
    ManagementResourceRegistration childRegistration = rootRegistration.registerSubModel(childRd);

    rootTarget = TargetResource.forStandalone(PathAddress.EMPTY_ADDRESS, rootRegistration, Resource.Factory.create());
    childTarget = TargetResource.forStandalone(PathAddress.pathAddress(childPE), childRegistration, Resource.Factory.create());
}
 
Example #5
Source File: ModelTestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This is the constructor to use for 18.0.x core model tests.
 */
protected ModelTestModelControllerService(final ProcessType processType, final RunningModeControl runningModeControl, final TransformerRegistry transformerRegistry,
                                          final StringConfigurationPersister persister, final ModelTestOperationValidatorFilter validateOpsFilter,
                                          final ResourceDefinition rootResourceDefinition, ControlledProcessState processState,
                                          final ExpressionResolver expressionResolver, final CapabilityRegistry capabilityRegistry, final Controller18x version) {
    super(processType,
            runningModeControl,
            persister,
            processState == null ? new ControlledProcessState(true) : processState,
            rootResourceDefinition,
            null,
            expressionResolver,
            AuditLogger.NO_OP_LOGGER,
            new DelegatingConfigurableAuthorizer(),
            new ManagementSecurityIdentitySupplier(),
            capabilityRegistry
    );

    this.persister = persister;
    this.transformerRegistry = transformerRegistry;
    this.validateOpsFilter = validateOpsFilter;
    this.runningModeControl = runningModeControl;
}
 
Example #6
Source File: PermissionMapperDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static ResourceDefinition getLogicalPermissionMapper() {
    AttributeDefinition[] attributes = new AttributeDefinition[] {LOGICAL_OPERATION, LEFT, RIGHT};
    TrivialAddHandler<PermissionMapper> add = new TrivialAddHandler<PermissionMapper>(PermissionMapper.class, attributes, PERMISSION_MAPPER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<PermissionMapper> getValueSupplier(ServiceBuilder<PermissionMapper> serviceBuilder,
                OperationContext context, ModelNode model) throws OperationFailedException {

            final InjectedValue<PermissionMapper> leftPermissionMapperInjector = new InjectedValue<>();
            final InjectedValue<PermissionMapper> rightPermissionMapperInjector = new InjectedValue<>();

            LogicalMapperOperation operation = LogicalMapperOperation.valueOf(LogicalMapperOperation.class, LOGICAL_OPERATION.resolveModelAttribute(context, model).asString().toUpperCase(Locale.ENGLISH));

            serviceBuilder.addDependency(context.getCapabilityServiceName(RuntimeCapability.buildDynamicCapabilityName(PERMISSION_MAPPER_CAPABILITY, LEFT.resolveModelAttribute(context, model).asString()),
                    PermissionMapper.class), PermissionMapper.class, leftPermissionMapperInjector);

            serviceBuilder.addDependency(context.getCapabilityServiceName(RuntimeCapability.buildDynamicCapabilityName(PERMISSION_MAPPER_CAPABILITY, RIGHT.resolveModelAttribute(context, model).asString()),
                    PermissionMapper.class), PermissionMapper.class, rightPermissionMapperInjector);

            return () -> operation.create(leftPermissionMapperInjector.getValue(), rightPermissionMapperInjector.getValue());
        }
    };

    return new TrivialResourceDefinition(ElytronDescriptionConstants.LOGICAL_PERMISSION_MAPPER, add, attributes, PERMISSION_MAPPER_RUNTIME_CAPABILITY);
}
 
Example #7
Source File: RoleMapperDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static ResourceDefinition getRegexRoleMapperDefinition() {
    AbstractAddStepHandler add = new RoleMapperAddHandler(PATTERN, REPLACEMENT, KEEP_NON_MAPPED, REPLACE_ALL) {

        @Override
        protected ValueSupplier<RoleMapper> getValueSupplier(OperationContext context, ModelNode model) throws OperationFailedException {
            final String regex = PATTERN.resolveModelAttribute(context, model).asString();
            final String replacement = REPLACEMENT.resolveModelAttribute(context, model).asString();
            final Boolean keepNonMapped = KEEP_NON_MAPPED.resolveModelAttribute(context, model).asBoolean();
            final Boolean replaceAll = REPLACE_ALL.resolveModelAttribute(context, model).asBoolean();

            final RegexRoleMapper roleMapper = new RegexRoleMapper.Builder()
                    .setPattern(regex)
                    .setReplacement(replacement)
                    .setKeepNonMapped(keepNonMapped)
                    .setReplaceAll(replaceAll)
                    .build();

            return () -> roleMapper;

        }
    };

    return new RoleMapperResourceDefinition(ElytronDescriptionConstants.REGEX_ROLE_MAPPER, add, PATTERN, REPLACEMENT, KEEP_NON_MAPPED, REPLACE_ALL);
}
 
Example #8
Source File: PrincipalTransformerDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static ResourceDefinition getRegexValidatingPrincipalTransformerDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { PATTERN, MATCH };
    AbstractAddStepHandler add = new TrivialAddHandler<PrincipalTransformer>(PrincipalTransformer.class, attributes, PRINCIPAL_TRANSFORMER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<PrincipalTransformer> getValueSupplier(ServiceBuilder<PrincipalTransformer> serviceBuilder,
                OperationContext context, ModelNode model) throws OperationFailedException {
            final Pattern pattern = Pattern.compile(PATTERN.resolveModelAttribute(context, model).asString());
            final boolean match = MATCH.resolveModelAttribute(context, model).asBoolean();

            return () -> PrincipalTransformer.from(new RegexNameValidatingRewriter(pattern, match).asPrincipalRewriter());
        }
    };

    return new TrivialResourceDefinition(REGEX_VALIDATING_PRINCIPAL_TRANSFORMER, add, attributes, PRINCIPAL_TRANSFORMER_RUNTIME_CAPABILITY);
}
 
Example #9
Source File: RealmMapperDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static ResourceDefinition getConstantRealmMapper() {
    AbstractAddStepHandler add = new TrivialAddHandler<RealmMapper>(RealmMapper.class, CONSTANT_REALM_MAPPER_ATTRIBUTES, REALM_MAPPER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<RealmMapper> getValueSupplier(ServiceBuilder<RealmMapper> serviceBuilder,
                OperationContext context, ModelNode model) throws OperationFailedException {
            final String realmName = REALM_NAME.resolveModelAttribute(context, model).asString();

            return () -> RealmMapper.single(realmName);
        }
    };

    return TrivialResourceDefinition.builder()
            .setPathKey(ElytronDescriptionConstants.CONSTANT_REALM_MAPPER)
            .setAddHandler(add)
            .setAttributes(CONSTANT_REALM_MAPPER_ATTRIBUTES)
            .setRuntimeCapabilities(REALM_MAPPER_RUNTIME_CAPABILITY).build();
}
 
Example #10
Source File: CoreManagementResourceRegistrationUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testInheritedAccessConstraints() {

    ResourceDefinition rootRd = new SimpleResourceDefinition(new Parameters(null, new NonResolvingResourceDescriptionResolver())
        .setAccessConstraints(SensitiveTargetAccessConstraintDefinition.EXTENSIONS, ApplicationTypeAccessConstraintDefinition.DEPLOYMENT));
    ManagementResourceRegistration root = ManagementResourceRegistration.Factory.forProcessType(ProcessType.EMBEDDED_SERVER).createRegistration(rootRd);

    List<AccessConstraintDefinition> acds = root.getAccessConstraints();
    assertEquals(2, acds.size());
    assertTrue(acds.contains(SensitiveTargetAccessConstraintDefinition.EXTENSIONS));
    assertTrue(acds.contains(ApplicationTypeAccessConstraintDefinition.DEPLOYMENT));

    ResourceDefinition childRd = new SimpleResourceDefinition(
            new Parameters(PathElement.pathElement("child"), new NonResolvingResourceDescriptionResolver())
                .setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SECURITY_DOMAIN, ApplicationTypeAccessConstraintDefinition.DEPLOYMENT));
    ManagementResourceRegistration child = root.registerSubModel(childRd);
    acds = child.getAccessConstraints();
    assertEquals(4, acds.size());
    assertTrue(acds.contains(SensitiveTargetAccessConstraintDefinition.EXTENSIONS));
    assertTrue(acds.contains(SensitiveTargetAccessConstraintDefinition.SECURITY_DOMAIN));
    assertTrue(acds.contains(ApplicationTypeAccessConstraintDefinition.DEPLOYMENT));
}
 
Example #11
Source File: ModelTestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This is the constructor to use for 18.0.x subsystem tests.
 */
protected ModelTestModelControllerService(final ProcessType processType, final RunningModeControl runningModeControl, final TransformerRegistry transformerRegistry,
                                          final StringConfigurationPersister persister, final ModelTestOperationValidatorFilter validateOpsFilter,
                                          final ResourceDefinition resourceDefinition, final ControlledProcessState processState,
                                          final CapabilityRegistry capabilityRegistry, final Controller18x version) {
    super(processType,
            runningModeControl,
            persister,
            processState == null ? new ControlledProcessState(true) : processState,
            resourceDefinition,
            null,
            ExpressionResolver.TEST_RESOLVER,
            AuditLogger.NO_OP_LOGGER,
            new DelegatingConfigurableAuthorizer(),
            new ManagementSecurityIdentitySupplier(),
            capabilityRegistry
    );

    this.persister = persister;
    this.transformerRegistry = transformerRegistry;
    this.validateOpsFilter = validateOpsFilter;
    this.runningModeControl = runningModeControl;
}
 
Example #12
Source File: LdapCacheResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static ResourceDefinition create(final PathElement pathElement, final CacheFor cacheFor) {
    SimpleAttributeDefinition[] configurationAttributes = new SimpleAttributeDefinition[] { EVICTION_TIME, CACHE_FAILURES, MAX_CACHE_SIZE };
    SimpleAttributeDefinition[] runtimeAttributes = new SimpleAttributeDefinition[] { CACHE_SIZE };
    final SimpleOperationDefinition[] runtimeOperations;
    final OperationStepHandler runtimeHandler;
    switch (cacheFor) {
        case AuthUser:
            runtimeOperations = new SimpleOperationDefinition[] { FLUSH_CACHE_NAME_ONLY, CONTAINS_NAME_ONLY };
            runtimeHandler = NAME_ONLY_HANDLER;
            break;
        default:
            runtimeOperations = new SimpleOperationDefinition[] { FLUSH_CACHE_FULL, CONTAINS_FULL };
            runtimeHandler = FULL_HANDLER;
    }

    return new LdapCacheResourceDefinition(pathElement, configurationAttributes, runtimeAttributes, runtimeOperations,
            runtimeHandler);
}
 
Example #13
Source File: PrincipalTransformerDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceDefinition getConstantPrincipalTransformerDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { CONSTANT };
    AbstractAddStepHandler add = new TrivialAddHandler<PrincipalTransformer>(PrincipalTransformer.class, attributes, PRINCIPAL_TRANSFORMER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<PrincipalTransformer> getValueSupplier(ServiceBuilder<PrincipalTransformer> serviceBuilder,
                OperationContext context, ModelNode model) throws OperationFailedException {
            final Principal principal = new NamePrincipal(CONSTANT.resolveModelAttribute(context, model).asString());

            return () -> p -> principal;
        }
    };

    return new TrivialResourceDefinition(CONSTANT_PRINCIPAL_TRANSFORMER, add, attributes, PRINCIPAL_TRANSFORMER_RUNTIME_CAPABILITY);
}
 
Example #14
Source File: TestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected TestModelControllerService(final ProcessType processType, final RunningModeControl runningModeControl, Supplier<ExecutorService> executorService,
                                     final ConfigurationPersister configurationPersister, final ControlledProcessState processState,
                                     final ResourceDefinition rootResourceDefinition, final CapabilityRegistry capabilityRegistry) {
    super(executorService, null, processType, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER,
            AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry);
    this.capabilityRegistry = capabilityRegistry;
}
 
Example #15
Source File: TransformationUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ResourceDefinition loadSubsystemDefinitionFromFile(final Class<?> classForDmrPackage, final String subsystemName, ModelVersion version) {
    final ModelNode desc = getSubsystemDefinitionForVersion(classForDmrPackage, subsystemName, version);
    if (desc == null) {
        return null;
    }
    return new LegacyResourceDefinition(desc);
}
 
Example #16
Source File: ModelTestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This is the constructor to use for 11.0.x subsystem tests
 */
protected ModelTestModelControllerService(final ProcessType processType, final RunningModeControl runningModeControl, final TransformerRegistry transformerRegistry,
                                          final StringConfigurationPersister persister, final ModelTestOperationValidatorFilter validateOpsFilter,
                                          final ResourceDefinition resourceDefinition, ControlledProcessState processState, Controller11x version) {
    super(processType, runningModeControl, persister,
            processState == null ? new ControlledProcessState(true) : processState, resourceDefinition, null, ExpressionResolver.TEST_RESOLVER);
    this.persister = persister;
    this.transformerRegistry = transformerRegistry;
    this.validateOpsFilter = validateOpsFilter;
    this.runningModeControl = runningModeControl;
}
 
Example #17
Source File: EnhancedSyntaxTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void initModel(ManagementModel managementModel) {
    ManagementResourceRegistration rootRegistration = managementModel.getRootResourceRegistration();
    // register the global operations to be able to call :read-attribute and :write-attribute
    GlobalOperationHandlers.registerGlobalOperations(rootRegistration, processType);
    // register the global notifications so there is no warning that emitted notifications are not described by the resource.
    GlobalNotifications.registerGlobalNotifications(rootRegistration, processType);

    rootRegistration.registerOperationHandler(CompositeOperationHandler.DEFINITION, CompositeOperationHandler.INSTANCE);

    ResourceDefinition profileDefinition = createDummyProfileResourceDefinition();
    rootRegistration.registerSubModel(profileDefinition);
}
 
Example #18
Source File: LegacyConfigurationChangeResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceDefinition forDomain() {
    return new SimpleResourceDefinition(new Parameters(PATH, DomainManagementResolver.getResolver(CORE, MANAGEMENT, SERVICE, CONFIGURATION_CHANGES))
            .setAddHandler(new OperationStepHandler() {
                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    String warning = DomainManagementLogger.ROOT_LOGGER.removedBrokenResource(context.getCurrentAddress().toCLIStyleString());
                    DomainManagementLogger.ROOT_LOGGER.warn(warning);
                    context.getResult().add(warning);
                }

            })
            .setDeprecatedSince(ModelVersion.create(4, 2)));
}
 
Example #19
Source File: TestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected TestModelControllerService(final ProcessType processType, final ConfigurationPersister configurationPersister, final ControlledProcessState processState,
                                     final ResourceDefinition rootResourceDefinition, final ManagedAuditLogger auditLogger,
                                     final AbstractControllerTestBase.DelegatingResourceDefinitionInitializer initializer,
                                     final CapabilityRegistry capabilityRegistry) {
    super(processType, new RunningModeControl(RunningMode.NORMAL), configurationPersister, processState, rootResourceDefinition,
            null, ExpressionResolver.TEST_RESOLVER, auditLogger, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry);
    this.processState = processState;
    internalExecutor = new InternalExecutor();
    this.initializer = initializer;
}
 
Example #20
Source File: JaspiDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceDefinition getJaspiServletConfigurationDefinition() {
    return TrivialResourceDefinition.builder()
            .setPathKey(ElytronDescriptionConstants.JASPI_CONFIGURATION)
            .setAttributes(ATTRIBUTES)
            .setAddHandler(ADD)
            .setRemoveHandler(REMOVE)
            .build();
}
 
Example #21
Source File: TrivialResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerChildren(ManagementResourceRegistration resourceRegistration) {
    if (children != null) {
        for (ResourceDefinition child : children) {
            resourceRegistration.registerSubModel(child);
        }
    }
}
 
Example #22
Source File: TrivialResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
Builder addChild(ResourceDefinition child) {
    if (children == null) {
        children = new ArrayList<>();
    }

    children.add(child);

    return this;
}
 
Example #23
Source File: PermissionMapperDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceDefinition getConstantPermissionMapper() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { PERMISSIONS, PERMISSION_SETS };
    TrivialAddHandler<PermissionMapper>  add = new TrivialAddHandler<PermissionMapper>(PermissionMapper.class, attributes, PERMISSION_MAPPER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<PermissionMapper> getValueSupplier(ServiceBuilder<PermissionMapper> serviceBuilder,
                                                                   OperationContext context, ModelNode model) throws OperationFailedException {

            List<Permission> permissions = new ArrayList<>();
            if (model.hasDefined(ElytronDescriptionConstants.PERMISSIONS)) {
                for (ModelNode permission : model.require(ElytronDescriptionConstants.PERMISSIONS).asList()) {
                    permissions.add(new Permission(CLASS_NAME.resolveModelAttribute(context, permission).asString(),
                            MODULE.resolveModelAttribute(context, permission).asStringOrNull(),
                            TARGET_NAME.resolveModelAttribute(context, permission).asStringOrNull(),
                            ACTION.resolveModelAttribute(context, permission).asStringOrNull()));
                }
            }

            List<InjectedValue<Permissions>> permissionSetInjectors = new ArrayList<>();
            if (model.hasDefined(ElytronDescriptionConstants.PERMISSION_SETS)) {
                for (ModelNode permissionSet : model.require(ElytronDescriptionConstants.PERMISSION_SETS).asList()) {
                    InjectedValue<Permissions> permissionSetInjector = new InjectedValue<>();
                    String permissionSetName = PERMISSION_SET_NAME.resolveModelAttribute(context, permissionSet).asString();
                    String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(PERMISSION_SET_CAPABILITY, permissionSetName);
                    ServiceName permissionSetServiceName = context.getCapabilityServiceName(runtimeCapability, Permissions.class);
                    serviceBuilder.addDependency(permissionSetServiceName, Permissions.class, permissionSetInjector);
                    permissionSetInjectors.add(permissionSetInjector);
                }
            }

            return () -> createConstantPermissionMapper(permissions, permissionSetInjectors);
        }
    };

    return new TrivialResourceDefinition(ElytronDescriptionConstants.CONSTANT_PERMISSION_MAPPER, add, attributes, PERMISSION_MAPPER_RUNTIME_CAPABILITY);
}
 
Example #24
Source File: EvidenceDecoderDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceDefinition getX500SubjectEvidenceDecoderDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] {};
    AbstractAddStepHandler add = new TrivialAddHandler<EvidenceDecoder>(EvidenceDecoder.class, attributes, EVIDENCE_DECODER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<EvidenceDecoder> getValueSupplier(ServiceBuilder<EvidenceDecoder> serviceBuilder,
                                                                       OperationContext context, ModelNode model) throws OperationFailedException {
            return () -> new X500SubjectEvidenceDecoder();
        }
    };
    return new TrivialResourceDefinition(X500_SUBJECT_EVIDENCE_DECODER, add, attributes, EVIDENCE_DECODER_RUNTIME_CAPABILITY);
}
 
Example #25
Source File: EvidenceDecoderDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceDefinition getX509SubjectAltNameEvidenceDecoderDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { ALT_NAME_TYPE, SEGMENT };
    AbstractAddStepHandler add = new TrivialAddHandler<EvidenceDecoder>(EvidenceDecoder.class, attributes, EVIDENCE_DECODER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<EvidenceDecoder> getValueSupplier(ServiceBuilder<EvidenceDecoder> serviceBuilder,
                                                                       OperationContext context, ModelNode model) throws OperationFailedException {
            final String  altNameType = ALT_NAME_TYPE.resolveModelAttribute(context, model).asString();
            final int segment  = SEGMENT.resolveModelAttribute(context, model).asInt();
            return () -> new X509SubjectAltNameEvidenceDecoder(SubjectAltNameType.fromName(altNameType).getType(), segment);
        }
    };
    return new TrivialResourceDefinition(X509_SUBJECT_ALT_NAME_EVIDENCE_DECODER, add, attributes, EVIDENCE_DECODER_RUNTIME_CAPABILITY);
}
 
Example #26
Source File: SSLDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ResourceDefinition createSSLContextDefinition(String pathKey, boolean server, AbstractAddStepHandler addHandler, AttributeDefinition[] attributes, boolean serverOrHostController) {
    Builder builder = TrivialResourceDefinition.builder()
            .setPathKey(pathKey)
            .setAddHandler(addHandler)
            .setAttributes(attributes)
            .setRuntimeCapabilities(SSL_CONTEXT_RUNTIME_CAPABILITY);

    if (serverOrHostController) {
        builder.addReadOnlyAttribute(ACTIVE_SESSION_COUNT, new SSLContextRuntimeHandler() {
            @Override
            protected void performRuntime(ModelNode result, ModelNode operation, SSLContext sslContext) throws OperationFailedException {
                SSLSessionContext sessionContext = server ? sslContext.getServerSessionContext() : sslContext.getClientSessionContext();
                int sum = 0;
                for (byte[] b : Collections.list(sessionContext.getIds())) {
                    int i = 1;
                    sum += i;
                }
                result.set(sum);
            }

            @Override
            protected ServiceUtil<SSLContext> getSSLContextServiceUtil() {
                return server ? SERVER_SERVICE_UTIL : CLIENT_SERVICE_UTIL;
            }
        }).addChild(new SSLSessionDefinition(server));
    }

    return builder.build();
}
 
Example #27
Source File: PrincipalDecoderDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceDefinition getConstantPrincipalDecoder() {
    AttributeDefinition[] attributes = new AttributeDefinition[] { CONSTANT };
    AbstractAddStepHandler add = new PrincipalDecoderAddHandler(attributes) {

        @Override
        protected ValueSupplier<PrincipalDecoder> getValueSupplier(ServiceBuilder<?> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String constant = CONSTANT.resolveModelAttribute(context, model).asString();
            return () -> PrincipalDecoder.constant(constant);
        }

    };

    return new PrincipalDecoderResourceDefinition(ElytronDescriptionConstants.CONSTANT_PRINCIPAL_DECODER, add, attributes);
}
 
Example #28
Source File: CoreManagementResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerChildren(ManagementResourceRegistration resourceRegistration) {
    if (environment != Environment.DOMAIN) {
        resourceRegistration.registerSubModel(ManagementControllerResourceDefinition.INSTANCE);
        resourceRegistration.registerSubModel(SecurityRealmResourceDefinition.INSTANCE);
        resourceRegistration.registerSubModel(LdapConnectionResourceDefinition.newInstance());
        // Configuration Changes
        resourceRegistration.registerSubModel(LegacyConfigurationChangeResourceDefinition.INSTANCE);
    }

    for (ResourceDefinition current : interfaces) {
        resourceRegistration.registerSubModel(current);
    }

    switch (environment) {
        case DOMAIN:
            resourceRegistration.registerSubModel(AccessAuthorizationResourceDefinition.forDomain(authorizer));
            resourceRegistration.registerSubModel(LegacyConfigurationChangeResourceDefinition.forDomain());
            break;
        case DOMAIN_SERVER:
            resourceRegistration.registerSubModel(AccessAuthorizationResourceDefinition.forDomainServer(authorizer));
            break;
        case STANDALONE_SERVER:
            resourceRegistration.registerSubModel(AccessAuthorizationResourceDefinition.forStandaloneServer(authorizer));
    }

    if (environment != Environment.DOMAIN) {
        resourceRegistration.registerSubModel(new AccessAuditResourceDefinition(auditLogger, pathManager, environmentReader));
        resourceRegistration.registerSubModel(AccessIdentityResourceDefinition.newInstance(securityIdentitySupplier));
    }
}
 
Example #29
Source File: CoreManagementResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CoreManagementResourceDefinition(final Environment environment, final DelegatingConfigurableAuthorizer authorizer,
        final ManagementSecurityIdentitySupplier securityIdentitySupplier, final ManagedAuditLogger auditLogger,
        final PathManagerService pathManager, final EnvironmentNameReader environmentReader,
        final List<ResourceDefinition> interfaces, final BootErrorCollector bootErrorCollector) {
    super(PATH_ELEMENT, DomainManagementResolver.getResolver(CORE, MANAGEMENT));
    this.environment = environment;
    this.authorizer = authorizer;
    this.securityIdentitySupplier = securityIdentitySupplier;
    this.interfaces = interfaces;
    this.auditLogger = auditLogger;
    this.pathManager = pathManager;
    this.environmentReader = environmentReader;
    this.bootErrorCollector = bootErrorCollector;
}
 
Example #30
Source File: TestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected TestModelControllerService(final ProcessType processType, final ConfigurationPersister configurationPersister, final ControlledProcessState processState,
                                     final ResourceDefinition rootResourceDefinition, final ManagedAuditLogger auditLogger, final DelegatingConfigurableAuthorizer authorizer) {
    super(processType, new RunningModeControl(RunningMode.NORMAL), configurationPersister, processState, rootResourceDefinition,
            null, ExpressionResolver.TEST_RESOLVER, auditLogger, authorizer == null ? new DelegatingConfigurableAuthorizer() : authorizer,
                    new ManagementSecurityIdentitySupplier(), new CapabilityRegistry(true));
    this.processState = processState;
    this.processType = processType;
}