Search in sources :

Example 91 with Configuration

use of javax.security.auth.login.Configuration in project kafka by apache.

the class BasicAuthSecurityRestExtensionTest method testGoodJaasConfigInitialization.

@Test
public void testGoodJaasConfigInitialization() {
    AtomicBoolean configurationInitializerEvaluated = new AtomicBoolean(false);
    Configuration mockConfiguration = mock(Configuration.class);
    Supplier<Configuration> configuration = BasicAuthSecurityRestExtension.initializeConfiguration(() -> {
        configurationInitializerEvaluated.set(true);
        return mockConfiguration;
    });
    assertTrue(configurationInitializerEvaluated.get());
    assertEquals(mockConfiguration, configuration.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Configuration(javax.security.auth.login.Configuration) Test(org.junit.jupiter.api.Test)

Example 92 with Configuration

use of javax.security.auth.login.Configuration in project kafka by apache.

the class BasicAuthSecurityRestExtensionTest method testBadJaasConfigExtensionSetup.

@Test
public void testBadJaasConfigExtensionSetup() {
    SecurityException jaasConfigurationException = new SecurityException(new IOException("Bad JAAS config is bad"));
    Supplier<Configuration> configuration = () -> {
        throw jaasConfigurationException;
    };
    BasicAuthSecurityRestExtension extension = new BasicAuthSecurityRestExtension(configuration);
    Exception thrownException = assertThrows(Exception.class, () -> extension.configure(Collections.emptyMap()));
    assertEquals(jaasConfigurationException, thrownException);
    thrownException = assertThrows(Exception.class, () -> extension.register(mock(ConnectRestExtensionContext.class)));
    assertEquals(jaasConfigurationException, thrownException);
}
Also used : Configuration(javax.security.auth.login.Configuration) IOException(java.io.IOException) IOException(java.io.IOException) ConnectException(org.apache.kafka.connect.errors.ConnectException) ConnectRestExtensionContext(org.apache.kafka.connect.rest.ConnectRestExtensionContext) Test(org.junit.jupiter.api.Test)

Example 93 with Configuration

use of javax.security.auth.login.Configuration in project kafka by apache.

the class BasicAuthSecurityRestExtensionTest method testBadJaasConfigInitialization.

@Test
public void testBadJaasConfigInitialization() {
    SecurityException jaasConfigurationException = new SecurityException(new IOException("Bad JAAS config is bad"));
    Supplier<Configuration> configuration = BasicAuthSecurityRestExtension.initializeConfiguration(() -> {
        throw jaasConfigurationException;
    });
    ConnectException thrownException = assertThrows(ConnectException.class, configuration::get);
    assertEquals(jaasConfigurationException, thrownException.getCause());
}
Also used : Configuration(javax.security.auth.login.Configuration) IOException(java.io.IOException) ConnectException(org.apache.kafka.connect.errors.ConnectException) Test(org.junit.jupiter.api.Test)

Example 94 with Configuration

use of javax.security.auth.login.Configuration in project SSM by Intel-bigdata.

the class SecurityUtil method loginUsingTicketCache.

@VisibleForTesting
static Subject loginUsingTicketCache(String principal, String ticketCacheFileName) throws IOException {
    Set<Principal> principals = new HashSet<Principal>();
    principals.add(new KerberosPrincipal(principal));
    Subject subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
    Configuration conf = useTicketCache(principal, ticketCacheFileName);
    String confName = "TicketCacheConf";
    LoginContext loginContext = null;
    try {
        loginContext = new LoginContext(confName, subject, null, conf);
    } catch (LoginException e) {
        throw new IOException("Fail to create LoginContext for " + e);
    }
    try {
        loginContext.login();
        LOG.info("Login successful for user " + subject.getPrincipals().iterator().next().getName());
    } catch (LoginException e) {
        throw new IOException("Login failure for " + e);
    }
    return loginContext.getSubject();
}
Also used : KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) LoginException(javax.security.auth.login.LoginException) IOException(java.io.IOException) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Principal(java.security.Principal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 95 with Configuration

use of javax.security.auth.login.Configuration in project SSM by Intel-bigdata.

the class SecurityUtil method loginUserFromTgtTicket.

/**
 * Log a user in from a tgt ticket.
 *
 * @throws IOException
 */
public static synchronized Subject loginUserFromTgtTicket(String smartSecurity) throws IOException {
    TICKET_KERBEROS_OPTIONS.put("smartSecurity", smartSecurity);
    Subject subject = new Subject();
    Configuration conf = new SmartJaasConf();
    String confName = "ticket-kerberos";
    LoginContext loginContext = null;
    try {
        loginContext = new LoginContext(confName, subject, null, conf);
    } catch (LoginException e) {
        throw new IOException("Fail to create LoginContext for " + e);
    }
    try {
        loginContext.login();
        LOG.info("Login successful for user " + subject.getPrincipals().iterator().next().getName());
    } catch (LoginException e) {
        throw new IOException("Login failure for " + e);
    }
    return loginContext.getSubject();
}
Also used : LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) LoginException(javax.security.auth.login.LoginException) IOException(java.io.IOException) Subject(javax.security.auth.Subject)

Aggregations

Configuration (javax.security.auth.login.Configuration)100 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)47 LoginContext (javax.security.auth.login.LoginContext)30 HashMap (java.util.HashMap)27 Subject (javax.security.auth.Subject)22 Test (org.junit.Test)17 IOException (java.io.IOException)15 LoginException (javax.security.auth.login.LoginException)13 File (java.io.File)8 Principal (java.security.Principal)7 CallbackHandler (javax.security.auth.callback.CallbackHandler)7 URI (java.net.URI)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 ArrayList (java.util.ArrayList)6 Test (org.junit.jupiter.api.Test)5 URIParameter (java.security.URIParameter)4 Map (java.util.Map)4 Callback (javax.security.auth.callback.Callback)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4 NoSuchProviderException (java.security.NoSuchProviderException)3