use of javax.security.auth.login.Configuration in project aries by apache.
the class JAASHelper method doAs.
public static <T> void doAs(final String[] groups, PrivilegedAction<T> action) {
Configuration config = new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
Map<String, Object> options = new HashMap<String, Object>();
// The user does not matter
options.put("username", "dummy");
options.put("groups", groups);
AppConfigurationEntry entry = new AppConfigurationEntry(SimpleLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, options);
return new AppConfigurationEntry[] { entry };
}
};
try {
LoginContext lc = new LoginContext("test", new Subject(), null, config);
lc.login();
Subject.doAs(lc.getSubject(), action);
lc.logout();
} catch (LoginException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of javax.security.auth.login.Configuration in project tomcat by apache.
the class JAASRealm method getConfig.
/**
* Load custom JAAS Configuration.
* @return the loaded configuration
*/
protected Configuration getConfig() {
// Local copy to avoid possible NPE due to concurrent change
String configFile = this.configFile;
try {
if (jaasConfigurationLoaded) {
return jaasConfiguration;
}
synchronized (this) {
if (configFile == null) {
jaasConfigurationLoaded = true;
return null;
}
URL resource = Thread.currentThread().getContextClassLoader().getResource(configFile);
URI uri = resource.toURI();
@SuppressWarnings("unchecked") Class<Configuration> sunConfigFile = (Class<Configuration>) Class.forName("com.sun.security.auth.login.ConfigFile");
Constructor<Configuration> constructor = sunConfigFile.getConstructor(URI.class);
Configuration config = constructor.newInstance(uri);
this.jaasConfiguration = config;
this.jaasConfigurationLoaded = true;
return this.jaasConfiguration;
}
} catch (InvocationTargetException ex) {
throw new RuntimeException(ex.getCause());
} catch (SecurityException | URISyntaxException | ReflectiveOperationException | IllegalArgumentException ex) {
throw new RuntimeException(ex);
}
}
use of javax.security.auth.login.Configuration in project keycloak by keycloak.
the class LoginModulesTest method createJaasConfigurationForDirectGrant.
private Configuration createJaasConfigurationForDirectGrant(String scope) {
return new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
Map<String, Object> options = new HashMap<>();
options.put(AbstractKeycloakLoginModule.KEYCLOAK_CONFIG_FILE_OPTION, DIRECT_GRANT_CONFIG_FILE.getAbsolutePath());
if (scope != null) {
options.put(DirectAccessGrantsLoginModule.SCOPE_OPTION, scope);
}
AppConfigurationEntry LMConfiguration = new AppConfigurationEntry(DirectAccessGrantsLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
return new AppConfigurationEntry[] { LMConfiguration };
}
};
}
use of javax.security.auth.login.Configuration in project karaf by apache.
the class KarafJaasAuthenticatorTest method init.
@Before
public void init() throws Exception {
configuration = Configuration.getConfiguration();
Configuration.setConfiguration(new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
return new AppConfigurationEntry[] { new AppConfigurationEntry(SayYes.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, emptyMap()) };
}
});
final SshServer server = new SshServer();
IoHandler ioHandler = new IoHandler() {
@Override
public void sessionCreated(IoSession ioSession) throws Exception {
}
@Override
public void sessionClosed(IoSession ioSession) throws Exception {
}
@Override
public void exceptionCaught(IoSession ioSession, Throwable throwable) throws Exception {
}
@Override
public void messageReceived(IoSession ioSession, Readable readable) throws Exception {
}
};
IoProcessor ioProcessor = new IoProcessor() {
@Override
public boolean isDisposing() {
return false;
}
@Override
public boolean isDisposed() {
return false;
}
@Override
public void dispose() {
}
@Override
public void add(org.apache.mina.core.session.IoSession ioSession) {
}
@Override
public void flush(org.apache.mina.core.session.IoSession ioSession) {
}
@Override
public void write(org.apache.mina.core.session.IoSession ioSession, WriteRequest writeRequest) {
}
@Override
public void updateTrafficControl(org.apache.mina.core.session.IoSession ioSession) {
}
@Override
public void remove(org.apache.mina.core.session.IoSession ioSession) {
}
};
server.setRandomFactory(new SingletonRandomFactory(SecurityUtils.getRandomFactory()));
this.session = new ServerSessionImpl(server, new MinaSession(new MinaConnector(server, ioHandler, ioProcessor), new DummySession(), SshdSocketAddress.LOCALHOST_ADDRESS));
}
use of javax.security.auth.login.Configuration in project knox by apache.
the class RemoteConfigurationRegistryClientServiceTestBase method setupAndStartSecureTestZooKeeper.
/*
* Setup and start a secure test ZooKeeper cluster.
*/
protected TestingCluster setupAndStartSecureTestZooKeeper(String principal, String digestPassword) throws Exception {
final boolean applyAuthentication = (principal != null);
// Configure security for the ZK cluster instances
Map<String, Object> customInstanceSpecProps = new HashMap<>();
customInstanceSpecProps.put("admin.enableServer", false);
if (applyAuthentication) {
customInstanceSpecProps.put("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
customInstanceSpecProps.put("requireClientAuthScheme", "sasl");
}
// Define the test cluster
List<InstanceSpec> instanceSpecs = new ArrayList<>();
for (int i = 0; i < 1; i++) {
InstanceSpec is = new InstanceSpec(null, -1, -1, -1, false, (i + 1), -1, -1, customInstanceSpecProps);
instanceSpecs.add(is);
}
TestingCluster zkCluster = new TestingCluster(instanceSpecs);
if (applyAuthentication) {
// Setup ZooKeeper server SASL
Map<String, String> digestOptions = new HashMap<>();
digestOptions.put("user_" + principal, digestPassword);
final AppConfigurationEntry[] serverEntries = { new AppConfigurationEntry("org.apache.zookeeper.server.auth.DigestLoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, digestOptions) };
Configuration.setConfiguration(new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
return ("Server".equalsIgnoreCase(name)) ? serverEntries : null;
}
});
}
// Start the cluster
zkCluster.start();
return zkCluster;
}
Aggregations