use of javax.security.auth.callback.CallbackHandler in project jspwiki by apache.
the class CookieAssertionLoginModuleTest method testLogout.
public final void testLogout() {
MockHttpServletRequest request = m_engine.newHttpRequest();
Cookie cookie = new Cookie(CookieAssertionLoginModule.PREFS_COOKIE_NAME, "Bullwinkle");
request.setCookies(new Cookie[] { cookie });
try {
CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
LoginModule module = new CookieAssertionLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("Bullwinkle")));
Assert.assertFalse(principals.contains(Role.ANONYMOUS));
Assert.assertFalse(principals.contains(Role.ALL));
module.logout();
Assert.assertEquals(0, principals.size());
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of javax.security.auth.callback.CallbackHandler in project jspwiki by apache.
the class UserDatabaseLoginModuleTest method testLogout.
public final void testLogout() {
try {
CallbackHandler handler = new WikiCallbackHandler(m_engine, null, "user", "password");
LoginModule module = new UserDatabaseLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("user", WikiPrincipal.LOGIN_NAME)));
Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
Assert.assertFalse(principals.contains(Role.ALL));
module.logout();
Assert.assertEquals(0, principals.size());
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of javax.security.auth.callback.CallbackHandler in project jspwiki by apache.
the class UserDatabaseLoginModuleTest method testLogin.
public final void testLogin() {
try {
// Log in with a user that isn't in the database
CallbackHandler handler = new WikiCallbackHandler(m_engine, null, "user", "password");
LoginModule module = new UserDatabaseLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("user", WikiPrincipal.LOGIN_NAME)));
Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
Assert.assertFalse(principals.contains(Role.ALL));
// Login with a user that IS in the database
m_subject = new Subject();
handler = new WikiCallbackHandler(m_engine, null, "janne", "myP@5sw0rd");
module = new UserDatabaseLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("janne", WikiPrincipal.LOGIN_NAME)));
Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
Assert.assertFalse(principals.contains(Role.ALL));
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of javax.security.auth.callback.CallbackHandler in project teiid by teiid.
the class AdminFactory method createAdmin.
/**
* Creates a ServerAdmin with the specified connection properties.
* @param userName
* @param password
* @param serverURL
* @param applicationName
* @return
* @throws AdminException
*/
public Admin createAdmin(String host, int port, String userName, char[] password) throws AdminException {
if (host == null) {
// $NON-NLS-1$
host = "localhost";
}
if (port < 0) {
port = 9990;
}
try {
CallbackHandler cbh = new AuthenticationCallbackHandler(userName, password);
ModelControllerClient newClient = ModelControllerClient.Factory.create(host, port, cbh);
List<String> nodeTypes = Util.getNodeTypes(newClient, new DefaultOperationRequestAddress());
if (!nodeTypes.isEmpty()) {
// $NON-NLS-1$
boolean domainMode = nodeTypes.contains("server-group");
LOGGER.info(// $NON-NLS-1$
"Connected to " + // $NON-NLS-1$ //$NON-NLS-2$
(domainMode ? "domain controller at " : "standalone controller at ") + host + ":" + // $NON-NLS-1$
port);
return new AdminImpl(newClient);
}
LOGGER.info(AdminPlugin.Util.gs(AdminPlugin.Event.TEIID70051, host, port));
} catch (UnknownHostException e) {
throw new AdminProcessingException(AdminPlugin.Event.TEIID70000, AdminPlugin.Util.gs(AdminPlugin.Event.TEIID70000, host, e.getLocalizedMessage()));
}
return null;
}
use of javax.security.auth.callback.CallbackHandler in project jmulticard by ctt-gob-es.
the class TestJseProvider method testProviderWithCustomConnection.
static void testProviderWithCustomConnection() throws Exception {
final Provider p = new DnieProvider(new SmartcardIoConnection());
Security.addProvider(p);
// $NON-NLS-1$
final KeyStore ks = KeyStore.getInstance("DNI");
final CallbackHandler callbackHandler;
// $NON-NLS-1$
callbackHandler = (CallbackHandler) Class.forName("es.gob.jmulticard.ui.passwordcallback.gui.DnieCallbackHandler").getConstructor().newInstance();
final LoadStoreParameter lsp = new LoadStoreParameter() {
@Override
public ProtectionParameter getProtectionParameter() {
return new KeyStore.CallbackHandlerProtection(callbackHandler);
}
};
ks.load(lsp);
final Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
System.out.println(aliases.nextElement());
}
// $NON-NLS-1$
final Signature signature = Signature.getInstance("SHA1withRSA");
// $NON-NLS-1$
signature.initSign((PrivateKey) ks.getKey("CertFirmaDigital", PASSWORD));
// $NON-NLS-1$
signature.update("Hola Mundo!!".getBytes());
signature.sign();
// $NON-NLS-1$
System.out.println("Firma generada correctamente");
}
Aggregations