use of javax.security.auth.login.Configuration in project jackrabbit-oak by apache.
the class TokenLoginModuleCredentialsSupportTest method getConfiguration.
@Override
protected Configuration getConfiguration() {
return new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
AppConfigurationEntry tokenEntry = new AppConfigurationEntry(TokenLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, Collections.<String, Object>emptyMap());
AppConfigurationEntry testEntry = new AppConfigurationEntry(TestLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, ImmutableMap.of("credsSupport", credentialsSupport));
AppConfigurationEntry defaultEntry = new AppConfigurationEntry(LoginModuleImpl.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap());
return new AppConfigurationEntry[] { tokenEntry, testEntry, defaultEntry };
}
};
}
use of javax.security.auth.login.Configuration in project jackrabbit-oak by apache.
the class L9_NullLoginTest method testJr2CompatibleLoginConfiguration.
public void testJr2CompatibleLoginConfiguration() throws RepositoryException {
// EXERCISE: define the JAAS configuration that allows you to have null-login treated as anonymous login.
Configuration configuration = null;
Configuration.setConfiguration(configuration);
try {
testSession = repository.login();
Session guest = repository.login(new GuestCredentials());
String expectedId = guest.getUserID();
guest.logout();
assertEquals(expectedId, testSession.getUserID());
} finally {
Configuration.setConfiguration(null);
}
}
use of javax.security.auth.login.Configuration in project calcite-avatica by apache.
the class KerberosConnectionTest method previousContextLoggedOut.
@Test
public void previousContextLoggedOut() throws Exception {
KerberosConnection krbUtil = mock(KerberosConnection.class);
Subject subject = new Subject();
Subject loggedInSubject = new Subject();
Configuration conf = mock(Configuration.class);
LoginContext originalContext = mock(LoginContext.class);
LoginContext context = mock(LoginContext.class);
// Call the real login(LoginContext, Configuration, Subject) method
when(krbUtil.login(any(LoginContext.class), any(Configuration.class), any(Subject.class))).thenCallRealMethod();
// Return a fake LoginContext
when(krbUtil.createLoginContext(conf)).thenReturn(context);
// Return a fake Subject from that fake LoginContext
when(context.getSubject()).thenReturn(loggedInSubject);
Entry<LoginContext, Subject> pair = krbUtil.login(originalContext, conf, subject);
// Verify we get the fake LoginContext and Subject
assertEquals(context, pair.getKey());
assertEquals(loggedInSubject, pair.getValue());
verify(originalContext).logout();
// login should be called on the LoginContext
verify(context).login();
}
use of javax.security.auth.login.Configuration in project calcite-avatica by apache.
the class KerberosConnectionTest method noPreviousContextOnLogin.
@Test
public void noPreviousContextOnLogin() throws Exception {
KerberosConnection krbUtil = mock(KerberosConnection.class);
Subject subject = new Subject();
Subject loggedInSubject = new Subject();
Configuration conf = mock(Configuration.class);
LoginContext context = mock(LoginContext.class);
// Call the real login(LoginContext, Configuration, Subject) method
when(krbUtil.login(nullable(LoginContext.class), any(Configuration.class), any(Subject.class))).thenCallRealMethod();
// Return a fake LoginContext
when(krbUtil.createLoginContext(conf)).thenReturn(context);
// Return a fake Subject from that fake LoginContext
when(context.getSubject()).thenReturn(loggedInSubject);
Entry<LoginContext, Subject> pair = krbUtil.login(null, conf, subject);
// Verify we get the fake LoginContext and Subject
assertEquals(context, pair.getKey());
assertEquals(loggedInSubject, pair.getValue());
// login should be called on the LoginContext
verify(context).login();
}
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);
}
}
Aggregations