Search in sources :

Example 46 with Configuration

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 };
        }
    };
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginModuleImpl(org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl) CompositeTokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.CompositeTokenConfiguration) TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) Configuration(javax.security.auth.login.Configuration)

Example 47 with Configuration

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);
    }
}
Also used : Configuration(javax.security.auth.login.Configuration) GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session)

Example 48 with Configuration

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();
}
Also used : LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 49 with Configuration

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();
}
Also used : LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 50 with Configuration

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);
    }
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) LoginException(javax.security.auth.login.LoginException) Subject(javax.security.auth.Subject)

Aggregations

Configuration (javax.security.auth.login.Configuration)52 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)26 LoginContext (javax.security.auth.login.LoginContext)18 HashMap (java.util.HashMap)17 Subject (javax.security.auth.Subject)12 Test (org.junit.Test)9 IOException (java.io.IOException)7 LoginException (javax.security.auth.login.LoginException)5 File (java.io.File)4 URI (java.net.URI)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 Callback (javax.security.auth.callback.Callback)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)4 PasswordCallback (javax.security.auth.callback.PasswordCallback)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4 URIParameter (java.security.URIParameter)3 Map (java.util.Map)3 NameCallback (javax.security.auth.callback.NameCallback)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 SSOException (com.iplanet.sso.SSOException)2