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());
}
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);
}
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());
}
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();
}
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();
}
Aggregations