javax.security.sasl.SaslServerFactory Java Examples
The following examples show how to use
javax.security.sasl.SaslServerFactory.
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: FastSaslServerFactory.java From Bats with Apache License 2.0 | 6 votes |
private void refresh() { final Enumeration<SaslServerFactory> factories = Sasl.getSaslServerFactories(); final Map<String, List<SaslServerFactory>> map = Maps.newHashMap(); while (factories.hasMoreElements()) { final SaslServerFactory factory = factories.nextElement(); // Passing null so factory is populated with all possibilities. Properties passed when // instantiating a server are what really matter. See createSaslServer. for (final String mechanismName : factory.getMechanismNames(null)) { if (!map.containsKey(mechanismName)) { map.put(mechanismName, new ArrayList<SaslServerFactory>()); } map.get(mechanismName).add(factory); } } serverFactories = ImmutableMap.copyOf(map); if (logger.isDebugEnabled()) { logger.debug("Registered sasl server factories: {}", serverFactories.keySet()); } }
Example #2
Source File: SaslRpcServer.java From hadoop with Apache License 2.0 | 6 votes |
@Override public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map<String,?> props, CallbackHandler cbh) throws SaslException { SaslServer saslServer = null; List<SaslServerFactory> factories = factoryCache.get(mechanism); if (factories != null) { for (SaslServerFactory factory : factories) { saslServer = factory.createSaslServer( mechanism, protocol, serverName, props, cbh); if (saslServer != null) { break; } } } return saslServer; }
Example #3
Source File: SaslRpcServer.java From big-c with Apache License 2.0 | 6 votes |
@Override public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map<String,?> props, CallbackHandler cbh) throws SaslException { SaslServer saslServer = null; List<SaslServerFactory> factories = factoryCache.get(mechanism); if (factories != null) { for (SaslServerFactory factory : factories) { saslServer = factory.createSaslServer( mechanism, protocol, serverName, props, cbh); if (saslServer != null) { break; } } } return saslServer; }
Example #4
Source File: FastSaslServerFactory.java From Bats with Apache License 2.0 | 5 votes |
@Override public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map<String, ?> props, CallbackHandler cbh) throws SaslException { final List<SaslServerFactory> factories = serverFactories.get(mechanism); if (factories != null) { for (final SaslServerFactory factory : factories) { final SaslServer saslServer = factory.createSaslServer(mechanism, protocol, serverName, props, cbh); if (saslServer != null) { return saslServer; } } } return null; }
Example #5
Source File: SaslTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testSaslServerDigest() throws Exception { init(); ServiceName serviceNameServer = Capabilities.SASL_SERVER_FACTORY_RUNTIME_CAPABILITY.getCapabilityServiceName("MySaslServer"); SaslServerFactory serverFactory = (SaslServerFactory) services.getContainer().getService(serviceNameServer).getValue(); Map<String, Object> serverClientProps = new HashMap<String, Object>(); serverClientProps.put("javax.security.sasl.qop", "auth-conf"); SaslServer server = serverFactory.createSaslServer(SaslMechanismInformation.Names.DIGEST_MD5, "protocol", "TestingRealm1", serverClientProps, serverCallbackHandler("user1", "TestingRealm1", "password1")); SaslClient client = Sasl.createSaslClient(new String[]{SaslMechanismInformation.Names.DIGEST_MD5}, "user1", "protocol", "TestingRealm1", serverClientProps, clientCallbackHandler("user1", "TestingRealm1", "password1")); testSaslServerClient(server, client); }
Example #6
Source File: SaslRpcServer.java From hadoop with Apache License 2.0 | 5 votes |
FastSaslServerFactory(Map<String,?> props) { final Enumeration<SaslServerFactory> factories = Sasl.getSaslServerFactories(); while (factories.hasMoreElements()) { SaslServerFactory factory = factories.nextElement(); for (String mech : factory.getMechanismNames(props)) { if (!factoryCache.containsKey(mech)) { factoryCache.put(mech, new ArrayList<SaslServerFactory>()); } factoryCache.get(mech).add(factory); } } }
Example #7
Source File: SaslRpcServer.java From big-c with Apache License 2.0 | 5 votes |
FastSaslServerFactory(Map<String,?> props) { final Enumeration<SaslServerFactory> factories = Sasl.getSaslServerFactories(); while (factories.hasMoreElements()) { SaslServerFactory factory = factories.nextElement(); for (String mech : factory.getMechanismNames(props)) { if (!factoryCache.containsKey(mech)) { factoryCache.put(mech, new ArrayList<SaslServerFactory>()); } factoryCache.get(mech).add(factory); } } }
Example #8
Source File: SASLAuthentication.java From Openfire with Apache License 2.0 | 5 votes |
/** * Returns a collection of mechanism names for which the JVM has an implementation available. * <p> * Note that this need not (and likely will not) correspond with the list of mechanisms that is offered to XMPP * peer entities, which is provided by #getSupportedMechanisms. * * @return a collection of SASL mechanism names (never null, possibly empty) */ public static Set<String> getImplementedMechanisms() { final Set<String> result = new HashSet<>(); final Enumeration<SaslServerFactory> saslServerFactories = Sasl.getSaslServerFactories(); while ( saslServerFactories.hasMoreElements() ) { final SaslServerFactory saslServerFactory = saslServerFactories.nextElement(); Collections.addAll( result, saslServerFactory.getMechanismNames( null ) ); } return result; }
Example #9
Source File: SaslServerDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static ResourceDefinition getProviderSaslServerFactoryDefinition() { AbstractAddStepHandler add = new SaslServerAddHandler(PROVIDERS) { @Override protected ServiceBuilder<SaslServerFactory> installService(OperationContext context, ServiceName saslServerFactoryName, ModelNode model) throws OperationFailedException { String providers = PROVIDERS.resolveModelAttribute(context, model).asStringOrNull(); final InjectedValue<Provider[]> providerInjector = new InjectedValue<Provider[]>(); final Supplier<Provider[]> providerSupplier = providers != null ? (providerInjector::getValue) : (Security::getProviders); TrivialService<SaslServerFactory> saslServiceFactoryService = new TrivialService<SaslServerFactory>(() -> new SecurityProviderSaslServerFactory(providerSupplier)); ServiceTarget serviceTarget = context.getServiceTarget(); ServiceBuilder<SaslServerFactory> serviceBuilder = serviceTarget.addService(saslServerFactoryName, saslServiceFactoryService); if (providers != null) { serviceBuilder.addDependency(context.getCapabilityServiceName(RuntimeCapability.buildDynamicCapabilityName(PROVIDERS_CAPABILITY, providers), Provider[].class), Provider[].class, providerInjector); } return serviceBuilder; } }; return wrap(new SaslServerResourceDefinition(ElytronDescriptionConstants.PROVIDER_SASL_SERVER_FACTORY, add, PROVIDERS), SaslServerDefinitions::getSaslServerAvailableMechanisms); }
Example #10
Source File: SaslServerDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static String[] getSaslServerAvailableMechanisms(OperationContext context) { RuntimeCapability<Void> runtimeCapability = SASL_SERVER_FACTORY_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue()); ServiceName saslServerFactoryName = runtimeCapability.getCapabilityServiceName(SaslServerFactory.class); ServiceController<SaslServerFactory> serviceContainer = getRequiredService(context.getServiceRegistry(false), saslServerFactoryName, SaslServerFactory.class); if (serviceContainer.getState() != State.UP) { return null; } return serviceContainer.getValue().getMechanismNames(Collections.emptyMap()); }
Example #11
Source File: SaslServerDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { RuntimeCapability<Void> runtimeCapability = SASL_SERVER_FACTORY_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue()); ServiceName saslServerFactoryName = runtimeCapability.getCapabilityServiceName(SaslServerFactory.class); commonDependencies(installService(context, saslServerFactoryName, model)) .setInitialMode(Mode.ACTIVE) .install(); }
Example #12
Source File: KontalkMechanismSelector.java From tigase-extension with GNU General Public License v3.0 | 4 votes |
protected boolean match(SaslServerFactory factory, String mechanismName, XMPPResourceConnection session) { return !(session.isTlsRequired() && !session.isEncrypted()) && factory instanceof KontalkSaslServerFactory && mechanismName.equals("EXTERNAL"); }
Example #13
Source File: AuthenticationFactoryDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static ResourceDefinition getSaslAuthenticationFactory() { SimpleAttributeDefinition securityDomainAttribute = new SimpleAttributeDefinitionBuilder(BASE_SECURITY_DOMAIN_REF) .setCapabilityReference(SECURITY_DOMAIN_CAPABILITY, SASL_AUTHENTICATION_FACTORY_CAPABILITY) .setRestartAllServices() .build(); AttributeDefinition mechanismConfigurationAttribute = getMechanismConfiguration(SASL_AUTHENTICATION_FACTORY_CAPABILITY); AttributeDefinition[] attributes = new AttributeDefinition[] { securityDomainAttribute, SASL_SERVER_FACTORY, mechanismConfigurationAttribute }; AbstractAddStepHandler add = new TrivialAddHandler<SaslAuthenticationFactory>(SaslAuthenticationFactory.class, ServiceController.Mode.ACTIVE, ServiceController.Mode.PASSIVE, attributes, SASL_AUTHENTICATION_FACTORY_RUNTIME_CAPABILITY) { @Override protected ValueSupplier<SaslAuthenticationFactory> getValueSupplier( ServiceBuilder<SaslAuthenticationFactory> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException { String securityDomain = securityDomainAttribute.resolveModelAttribute(context, model).asString(); String saslServerFactory = SASL_SERVER_FACTORY.resolveModelAttribute(context, model).asString(); final InjectedValue<SecurityDomain> securityDomainInjector = new InjectedValue<SecurityDomain>(); final InjectedValue<SaslServerFactory> saslServerFactoryInjector = new InjectedValue<SaslServerFactory>(); serviceBuilder.addDependency(context.getCapabilityServiceName( buildDynamicCapabilityName(SECURITY_DOMAIN_CAPABILITY, securityDomain), SecurityDomain.class), SecurityDomain.class, securityDomainInjector); serviceBuilder.addDependency(context.getCapabilityServiceName( buildDynamicCapabilityName(SASL_SERVER_FACTORY_CAPABILITY, saslServerFactory), SaslServerFactory.class), SaslServerFactory.class, saslServerFactoryInjector); final Set<String> supportedMechanisms = getConfiguredMechanismNames(mechanismConfigurationAttribute, context, model); final List<ResolvedMechanismConfiguration> resolvedMechanismConfigurations = getResolvedMechanismConfiguration(mechanismConfigurationAttribute, serviceBuilder, context, model); return () -> { SaslServerFactory serverFactory = saslServerFactoryInjector.getValue(); if (! supportedMechanisms.isEmpty()) { // filter non-configured mechanisms out (when we are sure they are not configured) serverFactory = new FilterMechanismSaslServerFactory(serverFactory, true, supportedMechanisms); // sort mechanisms using the configured order serverFactory = new SortedMechanismSaslServerFactory(serverFactory, supportedMechanisms.toArray(new String[supportedMechanisms.size()])); } else { // no mechanisms were configured, sort mechanisms by strength serverFactory = new SortedMechanismSaslServerFactory(serverFactory, AuthenticationFactoryDefinitions::compareSasl); } SaslAuthenticationFactory.Builder builder = SaslAuthenticationFactory.builder() .setSecurityDomain(securityDomainInjector.getValue()) .setFactory(serverFactory); buildMechanismConfiguration(resolvedMechanismConfigurations, builder); return builder.build(); }; } }; return wrap(new TrivialResourceDefinition(ElytronDescriptionConstants.SASL_AUTHENTICATION_FACTORY, add, attributes, SASL_AUTHENTICATION_FACTORY_RUNTIME_CAPABILITY), AuthenticationFactoryDefinitions::getAvailableSaslMechanisms); }
Example #14
Source File: SaslServerDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
protected ValueSupplier<SaslServerFactory> getValueSupplier(OperationContext context, ModelNode model) throws OperationFailedException { return () -> null; }
Example #15
Source File: SaslServerDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
protected ServiceBuilder<SaslServerFactory> installService(OperationContext context, ServiceName saslServerFactoryName, ModelNode model) throws OperationFailedException { ServiceTarget serviceTarget = context.getServiceTarget(); TrivialService<SaslServerFactory> saslServerFactoryService = new TrivialService<SaslServerFactory>(getValueSupplier(context, model)); return serviceTarget.addService(saslServerFactoryName, saslServerFactoryService); }
Example #16
Source File: SaslServerDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static ResourceDefinition getMechanismProviderFilteringSaslServerFactory() { AttributeDefinition[] attributes = new AttributeDefinition[] { SASL_SERVER_FACTORY, ENABLING, MECH_PROVIDER_FILTERS }; AbstractAddStepHandler add = new SaslServerAddHandler(attributes) { @Override protected ServiceBuilder<SaslServerFactory> installService(OperationContext context, ServiceName saslServerFactoryName, ModelNode model) throws OperationFailedException { final String saslServerFactory = SASL_SERVER_FACTORY.resolveModelAttribute(context, model).asString(); BiPredicate<String, Provider> predicate = null; if (model.hasDefined(ElytronDescriptionConstants.FILTERS)) { List<ModelNode> nodes = model.require(ElytronDescriptionConstants.FILTERS).asList(); for (ModelNode current : nodes) { final String mechanismName = MECHANISM_NAME.resolveModelAttribute(context, current).asStringOrNull(); final String providerName = PROVIDER_NAME.resolveModelAttribute(context, current).asString(); final Double providerVersion = PROVIDER_VERSION.resolveModelAttribute(context, current).asDoubleOrNull(); final Predicate<Double> versionPredicate; if (providerVersion != null) { final Comparison comparison = Comparison .getComparison(VERSION_COMPARISON.resolveModelAttribute(context, current).asString()); versionPredicate = (Double d) -> comparison.getPredicate().test(d, providerVersion); } else { versionPredicate = null; } BiPredicate<String, Provider> thisPredicate = (String s, Provider p) -> { return (mechanismName == null || mechanismName.equals(s)) && providerName.equals(p.getName()) && (providerVersion == null || versionPredicate.test(p.getVersion())); }; predicate = predicate == null ? thisPredicate : predicate.or(thisPredicate); } boolean enabling = ENABLING.resolveModelAttribute(context, model).asBoolean(); if (enabling == false) { predicate = predicate.negate(); } } final BiPredicate<String, Provider> finalPredicate = predicate; final InjectedValue<SaslServerFactory> saslServerFactoryInjector = new InjectedValue<SaslServerFactory>(); TrivialService<SaslServerFactory> saslServiceFactoryService = new TrivialService<SaslServerFactory>(() -> { SaslServerFactory theFactory = saslServerFactoryInjector.getValue(); theFactory = finalPredicate != null ? new MechanismProviderFilteringSaslServerFactory(theFactory, finalPredicate) : theFactory; return theFactory; }); ServiceTarget serviceTarget = context.getServiceTarget(); ServiceBuilder<SaslServerFactory> serviceBuilder = serviceTarget.addService(saslServerFactoryName, saslServiceFactoryService); serviceBuilder.addDependency(context.getCapabilityServiceName( RuntimeCapability.buildDynamicCapabilityName(SASL_SERVER_FACTORY_CAPABILITY, saslServerFactory), SaslServerFactory.class), SaslServerFactory.class, saslServerFactoryInjector); return serviceBuilder; } }; return wrap(new SaslServerResourceDefinition(ElytronDescriptionConstants.MECHANISM_PROVIDER_FILTERING_SASL_SERVER_FACTORY, add, attributes), SaslServerDefinitions::getSaslServerAvailableMechanisms); }
Example #17
Source File: SaslServerDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static AggregateComponentDefinition<SaslServerFactory> getRawAggregateSaslServerFactoryDefinition() { return AGGREGATE_SASL_SERVER_FACTORY; }
Example #18
Source File: PlainSaslServerBuilder.java From ballerina-message-broker with Apache License 2.0 | 4 votes |
@Override public Class<? extends SaslServerFactory> getServerFactoryClass() { return PlainSaslServerFactory.class; }
Example #19
Source File: SaslServerBuilder.java From ballerina-message-broker with Apache License 2.0 | 2 votes |
/** * Provides server factory {@link SaslServerFactory} for the Java Cryptography Architecture * (JCA) registration. * * @return Null if no JCA registration is required, otherwise return the class that will be used in JCA registration */ Class<? extends SaslServerFactory> getServerFactoryClass();