Java Code Examples for org.jboss.as.controller.OperationContext#getCapabilityServiceName()

The following examples show how to use org.jboss.as.controller.OperationContext#getCapabilityServiceName() . 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: LocalOutboundConnectionAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
void installRuntimeService(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    final String connectionName = address.getLastElement().getValue();
    final String outboundSocketBindingRef = LocalOutboundConnectionResourceDefinition.OUTBOUND_SOCKET_BINDING_REF.resolveModelAttribute(context, operation).asString();
    final ServiceName outboundSocketBindingDependency = context.getCapabilityServiceName(OUTBOUND_SOCKET_BINDING_CAPABILITY_NAME, outboundSocketBindingRef, OutboundSocketBinding.class);

    final ServiceName serviceName = OUTBOUND_CONNECTION_CAPABILITY.getCapabilityServiceName(connectionName);
    final ServiceName aliasServiceName = LocalOutboundConnectionService.LOCAL_OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionName);
    final ServiceName deprecatedServiceName = AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionName);

    final ServiceBuilder<?> builder = context.getServiceTarget().addService(serviceName);
    final Consumer<LocalOutboundConnectionService> serviceConsumer = builder.provides(deprecatedServiceName, aliasServiceName);
    final Supplier<OutboundSocketBinding> osbSupplier = builder.requires(outboundSocketBindingDependency);
    builder.requires(RemotingServices.SUBSYSTEM_ENDPOINT);
    builder.setInstance(new LocalOutboundConnectionService(serviceConsumer, osbSupplier));
    builder.install();
}
 
Example 2
Source File: AggregateComponentDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<?> instanceRuntimeCapability = runtimeCapability.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName componentName = instanceRuntimeCapability.getCapabilityServiceName(aggregationType);

    AggregateComponentService<T> aggregateComponentService = new AggregateComponentService<T>(aggregationType, aggregator);

    ServiceBuilder<T> serviceBuilder = serviceTarget.addService(componentName, aggregateComponentService);

    List<String> aggregates = aggregateReferences.unwrap(context, model);

    String baseCapabilityName = runtimeCapability.getName();
    for (String current : aggregates) {
        String runtimeCapabilityName = RuntimeCapability.buildDynamicCapabilityName(baseCapabilityName, current);
        ServiceName realmServiceName = context.getCapabilityServiceName(runtimeCapabilityName, aggregationType);

        serviceBuilder.addDependency(realmServiceName, aggregationType, aggregateComponentService.newInjector());
    }

    commonDependencies(serviceBuilder, true, dependOnProviderRegistration)
        .setInitialMode(Mode.LAZY)
        .install();
}
 
Example 3
Source File: CredentialReference.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static boolean applyCredentialReferenceUpdateToRuntime(OperationContext context, ModelNode operation,
                                                              ModelNode resolvedValue, ModelNode currentValue,
                                                              String attributeName) throws OperationFailedException {
    if (resolvedValue.isDefined()) {
        final String store = CredentialReference.credentialReferencePartAsStringIfDefined(resolvedValue, STORE);
        final String alias = CredentialReference.credentialReferencePartAsStringIfDefined(resolvedValue, ALIAS);
        final String secret = CredentialReference.credentialReferencePartAsStringIfDefined(operation.get(VALUE), CLEAR_TEXT);

        if (alias != null && secret != null) {
            final String credentialStoreCapabilityName = RuntimeCapability.buildDynamicCapabilityName(CREDENTIAL_STORE_CAPABILITY, store);
            final ServiceName credentialStoreServiceName = context.getCapabilityServiceName(credentialStoreCapabilityName, CredentialStore.class);
            final CredentialStore credentialStore = getCredentialStore(context.getServiceRegistry(true), credentialStoreServiceName);
            try {
                Map<String, CredentialStoreUpdateInfo> credentialStoreUpdateInfoMap = context.getAttachment(CREDENTIAL_STORE_UPDATE_INFO);
                CredentialStoreUpdateInfo credentialStoreUpdateInfo = credentialStoreUpdateInfoMap.get(getAttachmentMapKey(context, attributeName));
                updateCredentialStore(credentialStore, alias, secret, context.getResult(), credentialStoreUpdateInfo);
            } catch (CredentialStoreException e) {
                throw new OperationFailedException(e);
            }
        }
    }
    return ! operation.get(VALUE).equals(currentValue);
}
 
Example 4
Source File: CredentialReference.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void rollbackCredentialStoreUpdate(AttributeDefinition credentialReferenceAD, OperationContext context, String store, String alias) {
    try {
        Map<String, CredentialStoreUpdateInfo> credentialStoreUpdateInfoMap = context.getAttachment(CREDENTIAL_STORE_UPDATE_INFO);
        CredentialStoreUpdateInfo credentialStoreUpdateInfo = credentialStoreUpdateInfoMap != null ? credentialStoreUpdateInfoMap.get(getAttachmentMapKey(context, credentialReferenceAD.getName())) : null;
        if (store != null && credentialStoreUpdateInfo != null && credentialStoreUpdateInfo.getClearText() != null) {
            final String credentialStoreCapabilityName = RuntimeCapability.buildDynamicCapabilityName(CREDENTIAL_STORE_CAPABILITY, store);
            final ServiceName credentialStoreServiceName = context.getCapabilityServiceName(credentialStoreCapabilityName, CredentialStore.class);
            final CredentialStore credentialStore = getCredentialStore(context.getServiceRegistry(true), credentialStoreServiceName);
            ModelNode credentialStoreUpdateResult = context.getResult().get(CREDENTIAL_STORE_UPDATE);
            if (credentialStoreUpdateInfo.getPreviousAlias() == null) {
                // alias didn't exist before so remove the newly created entry
                removeSecret(credentialStore, alias, credentialStoreUpdateInfo.getClearText());
                credentialStoreUpdateResult.remove(NEW_ALIAS);
            } else {
                // revert back to previous value
                storeSecret(credentialStore, alias, credentialStoreUpdateInfo.getPreviousClearText());
            }
            credentialStoreUpdateResult.get(STATUS).set(UPDATE_ROLLED_BACK);
        }
    } catch (CredentialStoreException e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: ManagementRemotingServices.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Installs a remoting stream server for a domain instance
 *  @param serviceTarget the service target to install the services into
 * @param endpointName the name of the endpoint to install the stream server into
 * @param networkInterfaceBinding the network interface binding
 * @param port the port
 * @param securityRealm the security real name
 * @param options the remoting options
 */
public static void installDomainConnectorServices(final OperationContext context,
                                                  final ServiceTarget serviceTarget,
                                                  final ServiceName endpointName,
                                                  final ServiceName networkInterfaceBinding,
                                                  final int port,
                                                  final OptionMap options,
                                                  final ServiceName securityRealm,
                                                  final ServiceName saslAuthenticationFactory,
                                                  final ServiceName sslContext) {
    String sbmCap = "org.wildfly.management.socket-binding-manager";
    ServiceName sbmName = context.hasOptionalCapability(sbmCap, NATIVE_MANAGEMENT_RUNTIME_CAPABILITY.getName(), null)
            ? context.getCapabilityServiceName(sbmCap, SocketBindingManager.class) : null;
    installConnectorServicesForNetworkInterfaceBinding(serviceTarget, endpointName, MANAGEMENT_CONNECTOR,
            networkInterfaceBinding, port, options, securityRealm, saslAuthenticationFactory, sslContext, sbmName);
}
 
Example 6
Source File: RemoteOutboundConnectionAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
void installRuntimeService(final OperationContext context, final ModelNode operation, final ModelNode fullModel) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    final String connectionName = address.getLastElement().getValue();
    final String outboundSocketBindingRef = RemoteOutboundConnectionResourceDefinition.OUTBOUND_SOCKET_BINDING_REF.resolveModelAttribute(context, operation).asString();
    final ServiceName outboundSocketBindingDependency = context.getCapabilityServiceName(OUTBOUND_SOCKET_BINDING_CAPABILITY_NAME, outboundSocketBindingRef, OutboundSocketBinding.class);
    final OptionMap connOpts = ConnectorUtils.getOptions(context, fullModel.get(CommonAttributes.PROPERTY));
    final String username = RemoteOutboundConnectionResourceDefinition.USERNAME.resolveModelAttribute(context, fullModel).asStringOrNull();
    final String securityRealm = fullModel.hasDefined(CommonAttributes.SECURITY_REALM) ? fullModel.require(CommonAttributes.SECURITY_REALM).asString() : null;
    final String authenticationContext = fullModel.hasDefined(CommonAttributes.AUTHENTICATION_CONTEXT) ? fullModel.require(CommonAttributes.AUTHENTICATION_CONTEXT).asString() : null;
    final String protocol = authenticationContext != null ? null : RemoteOutboundConnectionResourceDefinition.PROTOCOL.resolveModelAttribute(context, operation).asString();

    // create the service
    final ServiceName serviceName = OUTBOUND_CONNECTION_CAPABILITY.getCapabilityServiceName(connectionName);
    final ServiceName aliasServiceName = RemoteOutboundConnectionService.REMOTE_OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionName);
    final ServiceName deprecatedName = AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionName);

    final ServiceBuilder<?> builder = context.getServiceTarget().addService(serviceName);
    final Consumer<RemoteOutboundConnectionService> serviceConsumer = builder.provides(deprecatedName, aliasServiceName);
    final Supplier<OutboundSocketBinding> osbSupplier = builder.requires(outboundSocketBindingDependency);
    final Supplier<SecurityRealm> srSupplier = securityRealm != null ? SecurityRealm.ServiceUtil.requires(builder, securityRealm) : null;
    final Supplier<AuthenticationContext> acSupplier = authenticationContext != null ? builder.requires(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, authenticationContext, AuthenticationContext.class)) : null;
    builder.requires(RemotingServices.SUBSYSTEM_ENDPOINT);
    builder.setInstance(new RemoteOutboundConnectionService(serviceConsumer, osbSupplier, srSupplier, acSupplier, connOpts, username, protocol));
    builder.install();
}
 
Example 7
Source File: SecureServerDefinition.java    From keycloak with Apache License 2.0 6 votes vote down vote up
static void installCapability(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    String factoryName = pathAddress.getLastElement().getValue();
    ServiceName serviceName = context.getCapabilityServiceName(HTTP_SERVER_AUTHENTICATION_CAPABILITY, factoryName, HttpServerAuthenticationMechanismFactory.class);
    boolean publicClient = SecureServerDefinition.PUBLIC_CLIENT.resolveModelAttribute(context, operation).asBoolean(false);

    if (!publicClient) {
        throw new OperationFailedException("Only public clients are allowed to have their configuration exposed through the management interface");
    }

    KeycloakHttpAuthenticationFactoryService service = new KeycloakHttpAuthenticationFactoryService(factoryName);
    ServiceTarget serviceTarget = context.getServiceTarget();
    InjectedValue<ExtensibleHttpManagement> injectedValue = new InjectedValue<>();
    serviceTarget.addService(serviceName.append("http-management-context"), createHttpManagementConfigContextService(factoryName, injectedValue))
            .addDependency(context.getCapabilityServiceName(HTTP_MANAGEMENT_HTTP_EXTENSIBLE_CAPABILITY, ExtensibleHttpManagement.class), ExtensibleHttpManagement.class, injectedValue).setInitialMode(Mode.ACTIVE).install();
    serviceTarget.addService(serviceName, service).setInitialMode(Mode.ACTIVE).install();
}
 
Example 8
Source File: RemotingConnectorAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {

    boolean useManagementEndpoint = RemotingConnectorResource.USE_MANAGEMENT_ENDPOINT.resolveModelAttribute(context, model).asBoolean();

    ServiceName remotingCapability;
    if (!useManagementEndpoint) {
        // Use the remoting capability
        // if (context.getProcessType() == ProcessType.DOMAIN_SERVER) then DomainServerCommunicationServices
        // installed the "remoting subsystem" endpoint and we don't even necessarily *have to* have a remoting
        // subsystem and possibly we could skip adding the requirement for its capability. But really, specifying
        // not to use the management endpoint and then not configuring a remoting subsystem is a misconfiguration,
        // and we should treat it as such. So, we add the requirement no matter what.
        context.requireOptionalCapability(RemotingConnectorResource.REMOTING_CAPABILITY, RemotingConnectorResource.REMOTE_JMX_CAPABILITY.getName(),
                    RemotingConnectorResource.USE_MANAGEMENT_ENDPOINT.getName());
        remotingCapability = context.getCapabilityServiceName(RemotingConnectorResource.REMOTING_CAPABILITY, Endpoint.class);
    } else {
        remotingCapability = ManagementRemotingServices.MANAGEMENT_ENDPOINT;
    }
    // Read the model for the JMX subsystem to find the domain name for the resolved/expressions models (if they are exposed).
    PathAddress address = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
    PathAddress parentAddress = address.subAddress(0, address.size() - 1);
    ModelNode jmxSubsystemModel = Resource.Tools.readModel(context.readResourceFromRoot(parentAddress, true));
    String resolvedDomain = getDomainName(context, jmxSubsystemModel, CommonAttributes.RESOLVED);
    String expressionsDomain = getDomainName(context, jmxSubsystemModel, CommonAttributes.EXPRESSION);

    RemotingConnectorService.addService(context.getServiceTarget(), remotingCapability, resolvedDomain, expressionsDomain);
}
 
Example 9
Source File: KeycloakHttpServerAuthenticationMechanismFactoryDefinition.java    From keycloak with Apache License 2.0 5 votes vote down vote up
static void installCapability(OperationContext context, ModelNode operation) {
    PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    String factoryName = pathAddress.getLastElement().getValue();
    ServiceName serviceName = context.getCapabilityServiceName(HTTP_SERVER_AUTHENTICATION_CAPABILITY, factoryName, HttpServerAuthenticationMechanismFactory.class);
    KeycloakHttpAuthenticationFactoryService service = new KeycloakHttpAuthenticationFactoryService(factoryName);
    context.getServiceTarget().addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).install();
}
 
Example 10
Source File: PrincipalDecoderDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceDefinition getConcatenatingPrincipalDecoder() {
    AttributeDefinition[] attributes = new AttributeDefinition[] { JOINER, PRINCIPAL_DECODERS };

    AbstractAddStepHandler add = new PrincipalDecoderAddHandler(attributes) {

        @Override
        protected ValueSupplier<PrincipalDecoder> getValueSupplier(ServiceBuilder<?> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String joiner = JOINER.resolveModelAttribute(context, model).asString();
            final List<String> decoders = PRINCIPAL_DECODERS.unwrap(context, model);

            final List<InjectedValue<PrincipalDecoder>> principalDecoderInjectors = new ArrayList<>();
            final String baseCapabilityName = PRINCIPAL_DECODER_RUNTIME_CAPABILITY.getName();
            for (String decoder : decoders) {
                InjectedValue<PrincipalDecoder> principalDecoderInjector = new InjectedValue<>();
                String runtimeCapabilityName = RuntimeCapability.buildDynamicCapabilityName(baseCapabilityName, decoder);
                ServiceName decoderServiceName = context.getCapabilityServiceName(runtimeCapabilityName, PrincipalDecoder.class);
                serviceBuilder.addDependency(decoderServiceName, PrincipalDecoder.class, principalDecoderInjector);
                principalDecoderInjectors.add(principalDecoderInjector);
            }
            return () -> {
                final ArrayList<PrincipalDecoder> principalDecoders = new ArrayList<>(principalDecoderInjectors.size());
                for (InjectedValue<PrincipalDecoder> current : principalDecoderInjectors) {
                    principalDecoders.add(current.getValue());
                }
                return PrincipalDecoder.concatenating(joiner, principalDecoders.toArray(new PrincipalDecoder[principalDecoders.size()]));
            };
        }

    };

    return new PrincipalDecoderResourceDefinition(ElytronDescriptionConstants.CONCATENATING_PRINCIPAL_DECODER, add, attributes);
}
 
Example 11
Source File: SecureServerDefinition.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    super.performRuntime(context, operation, model);
    PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    String factoryName = pathAddress.getLastElement().getValue();
    ServiceName serviceName = context.getCapabilityServiceName(HTTP_SERVER_AUTHENTICATION_CAPABILITY, factoryName, HttpServerAuthenticationMechanismFactory.class);
    context.removeService(serviceName);
}
 
Example 12
Source File: DomainDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void injectRoleMapper(String roleMapper, OperationContext context, ServiceBuilder<SecurityDomain> domainBuilder, Injector<RoleMapper> injector) {
    if (roleMapper == null) {
        return;
    }

    if (injector == null) {
        // Service did not supply one as one is already present for this name.
        return;
    }

    String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(ROLE_MAPPER_CAPABILITY, roleMapper);
    ServiceName roleMapperServiceName = context.getCapabilityServiceName(runtimeCapability, RoleMapper.class);

    domainBuilder.addDependency(roleMapperServiceName, RoleMapper.class, injector);
}
 
Example 13
Source File: DomainDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void injectPrincipalTransformer(String principalTransformer, OperationContext context, ServiceBuilder<SecurityDomain> domainBuilder, Injector<PrincipalTransformer> injector) {
    if (principalTransformer == null) {
        return;
    }

    if (injector == null) {
        // Service did not supply one as one is already present for this name.
        return;
    }

    String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(PRINCIPAL_TRANSFORMER_CAPABILITY, principalTransformer);
    ServiceName principalTransformerServiceName = context.getCapabilityServiceName(runtimeCapability, PrincipalTransformer.class);

    domainBuilder.addDependency(principalTransformerServiceName, PrincipalTransformer.class, injector);
}
 
Example 14
Source File: LdapRealmDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void configureDirContext(OperationContext context, ModelNode model, LdapSecurityRealmBuilder realmBuilder, ServiceBuilder<SecurityRealm> serviceBuilder) throws OperationFailedException {
    String dirContextName = DIR_CONTEXT.resolveModelAttribute(context, model).asStringOrNull();

    String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(DIR_CONTEXT_CAPABILITY, dirContextName);
    ServiceName dirContextServiceName = context.getCapabilityServiceName(runtimeCapability, DirContextSupplier.class);

    final InjectedValue<DirContextSupplier> dirContextInjector = new InjectedValue<>();
    serviceBuilder.addDependency(dirContextServiceName, DirContextSupplier.class, dirContextInjector);

    realmBuilder.setDirContextSupplier(() -> {
        ExceptionSupplier<DirContext, NamingException> supplier = dirContextInjector.getValue();
        return supplier.get();
    });
}
 
Example 15
Source File: FileResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String resolve(final OperationContext context, final String relativeToPath, final String path) {
    // TODO it would be better if this came via the ExtensionContext
    ServiceName pathMgrSvc = context.getCapabilityServiceName("org.wildfly.management.path-manager", PathManager.class);
    @SuppressWarnings("unchecked") final ServiceController<PathManager> controller = (ServiceController<PathManager>) context.getServiceRegistry(false).getService(pathMgrSvc);
    if (controller == null) {
        return null;
    }
    return controller.getValue().resolveRelativePathEntry(path, relativeToPath);
}
 
Example 16
Source File: RealmMapperDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = REALM_MAPPER_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName realmMapperName = runtimeCapability.getCapabilityServiceName(RealmMapper.class);

    final String pattern = PATTERN_CAPTURE_GROUP.resolveModelAttribute(context, model).asString();
    String delegateRealmMapper = DELEGATE_REALM_MAPPER.resolveModelAttribute(context, model).asStringOrNull();

    final InjectedValue<RealmMapper> delegateRealmMapperInjector = new InjectedValue<RealmMapper>();

    TrivialService<RealmMapper> realmMapperService = new TrivialService<RealmMapper>(() -> {
        RealmMapper delegate = delegateRealmMapperInjector.getOptionalValue();
        Pattern compiledPattern = Pattern.compile(pattern);
        if (delegate == null) {
            return new SimpleRegexRealmMapper(compiledPattern);
        } else {
            return new SimpleRegexRealmMapper(compiledPattern, delegate);
        }
    });

    ServiceBuilder<RealmMapper> realmMapperBuilder = serviceTarget.addService(realmMapperName, realmMapperService);

    if (delegateRealmMapper != null) {
        String delegateCapabilityName = RuntimeCapability.buildDynamicCapabilityName(REALM_MAPPER_CAPABILITY, delegateRealmMapper);
        ServiceName delegateServiceName = context.getCapabilityServiceName(delegateCapabilityName, RealmMapper.class);

        realmMapperBuilder.addDependency(delegateServiceName, RealmMapper.class, delegateRealmMapperInjector);
    }

    commonDependencies(realmMapperBuilder)
        .setInitialMode(Mode.LAZY)
        .install();
}
 
Example 17
Source File: ProviderDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    ServiceName providerLoaderName = context.getCapabilityServiceName(PROVIDERS_CAPABILITY, context.getCurrentAddressValue(), Provider[].class);
    ServiceController<Provider[]> serviceContainer = getRequiredService(context.getServiceRegistry(false), providerLoaderName, Provider[].class);
    if (serviceContainer.getState() != State.UP) {
        return;
    }

    populateProviders(context.getResult(), serviceContainer.getValue());
}
 
Example 18
Source File: PermissionMapperDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static ResourceDefinition getSimplePermissionMapper() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { MAPPING_MODE, PERMISSION_MAPPINGS };
    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 MappingMode mappingMode = MappingMode.valueOf(MappingMode.class, MAPPING_MODE.resolveModelAttribute(context, model).asString().toUpperCase(Locale.ENGLISH));

            final List<Mapping> permissionMappings = new ArrayList<>();
            if (model.hasDefined(ElytronDescriptionConstants.PERMISSION_MAPPINGS)) {
                for (ModelNode permissionMapping : model.get(ElytronDescriptionConstants.PERMISSION_MAPPINGS).asList()) {
                    boolean matchAll = MATCH_ALL.resolveModelAttribute(context, permissionMapping).asBoolean(false);
                    Set<String> principals = !matchAll ? new HashSet<>(PRINCIPALS.unwrap(context, permissionMapping)) : Collections.emptySet();
                    Set<String> roles = !matchAll ? new HashSet<>(ROLES.unwrap(context, permissionMapping)) : Collections.emptySet();

                    List<Permission> permissions = new ArrayList<>();
                    if (permissionMapping.hasDefined(ElytronDescriptionConstants.PERMISSIONS)) {
                        for (ModelNode permission : permissionMapping.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 (permissionMapping.hasDefined(ElytronDescriptionConstants.PERMISSION_SETS)) {
                        for (ModelNode permissionSet : permissionMapping.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);
                        }
                    }

                    permissionMappings.add(new Mapping(principals, roles, permissions, permissionSetInjectors, matchAll));
                }
            }

            return () -> createSimplePermissionMapper(mappingMode, permissionMappings);
        }
    };

    return new TrivialResourceDefinition(ElytronDescriptionConstants.SIMPLE_PERMISSION_MAPPER, add, attributes, PERMISSION_MAPPER_RUNTIME_CAPABILITY);
}
 
Example 19
Source File: CachingRealmDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void addRealmDependency(OperationContext context, ServiceBuilder<SecurityRealm> serviceBuilder, String realmName, Injector<SecurityRealm> securityRealmInjector) {
    String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(SECURITY_REALM_CAPABILITY, realmName);
    ServiceName realmServiceName = context.getCapabilityServiceName(runtimeCapability, SecurityRealm.class);
    REALM_SERVICE_UTIL.addInjection(serviceBuilder, securityRealmInjector, realmServiceName);
}
 
Example 20
Source File: FilteringKeyStoreDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    ModelNode model = resource.getModel();

    String sourceKeyStoreName = KEY_STORE.resolveModelAttribute(context, model).asStringOrNull();
    String aliasFilter = ALIAS_FILTER.resolveModelAttribute(context, model).asStringOrNull();

    String sourceKeyStoreCapability = RuntimeCapability.buildDynamicCapabilityName(KEY_STORE_CAPABILITY, sourceKeyStoreName);
    ServiceName sourceKeyStoreServiceName = context.getCapabilityServiceName(sourceKeyStoreCapability, KeyStore.class);


    final InjectedValue<KeyStore> keyStore = new InjectedValue<>();

    FilteringKeyStoreService filteringKeyStoreService = new FilteringKeyStoreService(keyStore, aliasFilter);

    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = KEY_STORE_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName(KeyStore.class);
    ServiceBuilder<KeyStore> serviceBuilder = serviceTarget.addService(serviceName, filteringKeyStoreService).setInitialMode(ServiceController.Mode.ACTIVE);

    FILTERING_KEY_STORE_UTIL.addInjection(serviceBuilder, keyStore, sourceKeyStoreServiceName);

    commonDependencies(serviceBuilder).install();
}