use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class ElytronSubjectFactory method createSubject.
/**
* {@inheritDoc}
*/
public Subject createSubject(final String authenticationContextName) {
AuthenticationContext context;
if (authenticationContextName != null && !authenticationContextName.isEmpty()) {
final ServiceContainer container = this.currentServiceContainer();
final ServiceName authContextServiceName = AUTHENTICATION_CONTEXT_RUNTIME_CAPABILITY.getCapabilityServiceName(authenticationContextName);
context = (AuthenticationContext) container.getRequiredService(authContextServiceName).getValue();
} else {
context = getAuthenticationContext();
}
final Subject subject = this.createSubject(context);
if (ROOT_LOGGER.isTraceEnabled()) {
ROOT_LOGGER.subject(subject, Integer.toHexString(System.identityHashCode(subject)));
}
return subject;
}
use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class DataSourceService method start.
@Override
public void start(StartContext context) throws StartException {
Class<?> providerClass = driverInjector.getOptionalValue();
if (xa) {
if (!XADataSource.class.isAssignableFrom(providerClass)) {
throw AgroalLogger.SERVICE_LOGGER.invalidXAConnectionProvider();
}
} else {
if (providerClass != null && !DataSource.class.isAssignableFrom(providerClass) && !Driver.class.isAssignableFrom(providerClass)) {
throw AgroalLogger.SERVICE_LOGGER.invalidConnectionProvider();
}
}
dataSourceConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().connectionProviderClass(providerClass);
if (jta || xa) {
TransactionManager transactionManager = ContextTransactionManager.getInstance();
TransactionSynchronizationRegistry transactionSynchronizationRegistry = transactionSynchronizationRegistryInjector.getValue();
if (transactionManager == null || transactionSynchronizationRegistry == null) {
throw AgroalLogger.SERVICE_LOGGER.missingTransactionManager();
}
TransactionIntegration txIntegration = new NarayanaTransactionIntegration(transactionManager, transactionSynchronizationRegistry, jndiName, connectable);
dataSourceConfiguration.connectionPoolConfiguration().transactionIntegration(txIntegration);
}
AuthenticationContext authenticationContext = authenticationContextInjector.getOptionalValue();
if (authenticationContext != null) {
try {
// Probably some other thing should be used as URI. Using jndiName for consistency with the datasources subsystem (simplicity as a bonus)
URI targetURI = new URI(jndiName);
NameCallback nameCallback = new NameCallback("Username: ");
PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
CredentialCallback credentialCallback = new CredentialCallback(GSSKerberosCredential.class);
AuthenticationConfiguration authenticationConfiguration = AUTH_CONFIG_CLIENT.getAuthenticationConfiguration(targetURI, authenticationContext, -1, "jdbc", "jboss");
AUTH_CONFIG_CLIENT.getCallbackHandler(authenticationConfiguration).handle(new Callback[] { nameCallback, passwordCallback, credentialCallback });
// if a GSSKerberosCredential was found, add the enclosed GSSCredential and KerberosTicket to the private set in the Subject.
if (credentialCallback.getCredential() != null) {
GSSKerberosCredential kerberosCredential = credentialCallback.getCredential(GSSKerberosCredential.class);
// use the GSSName to build a kerberos principal
dataSourceConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().principal(new NamePrincipal(kerberosCredential.getGssCredential().getName().toString()));
dataSourceConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().credential(kerberosCredential.getKerberosTicket());
dataSourceConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().credential(kerberosCredential.getGssCredential());
}
// use the name / password from the callbacks
if (nameCallback.getName() != null) {
dataSourceConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().principal(new NamePrincipal(nameCallback.getName()));
}
if (passwordCallback.getPassword() != null) {
dataSourceConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().credential(new SimplePassword(new String(passwordCallback.getPassword())));
}
} catch (URISyntaxException | UnsupportedCallbackException | IOException | GSSException e) {
throw AgroalLogger.SERVICE_LOGGER.invalidAuthentication(e, dataSourceName);
}
}
ExceptionSupplier<CredentialSource, Exception> credentialSourceExceptionExceptionSupplier = credentialSourceSupplierInjector.getOptionalValue();
if (credentialSourceExceptionExceptionSupplier != null) {
try {
String password = new String(credentialSourceExceptionExceptionSupplier.get().getCredential(PasswordCredential.class).getPassword(ClearPassword.class).getPassword());
dataSourceConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().credential(new SimplePassword(password));
} catch (Exception e) {
throw AgroalLogger.SERVICE_LOGGER.invalidCredentialSourceSupplier(e, dataSourceName);
}
}
try {
agroalDataSource = AgroalDataSource.from(dataSourceConfiguration, new LoggingDataSourceListener(dataSourceName));
ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
BinderService binderService = new BinderService(bindInfo.getBindName());
binderService.getManagedObjectInjector().inject(new ImmediateManagedReferenceFactory(agroalDataSource));
context.getChildTarget().addService(bindInfo.getBinderServiceName(), binderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).install();
if (xa) {
AgroalLogger.SERVICE_LOGGER.startedXADataSource(dataSourceName, jndiName);
} else {
AgroalLogger.SERVICE_LOGGER.startedDataSource(dataSourceName, jndiName);
}
} catch (SQLException e) {
agroalDataSource = null;
if (xa) {
throw AgroalLogger.SERVICE_LOGGER.xaDatasourceStartException(e, dataSourceName);
} else {
throw AgroalLogger.SERVICE_LOGGER.datasourceStartException(e, dataSourceName);
}
}
}
use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class HttpRemoteIdentityTestCase method setup.
@BeforeClass
public static void setup() {
AuthenticationConfiguration config = AuthenticationConfiguration.EMPTY.useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, config);
old = AuthenticationContext.captureCurrent();
AuthenticationContext.getContextManager().setGlobalDefault(context);
}
Aggregations