use of org.apache.catalina.realm.GenericPrincipal in project tomcat by apache.
the class TestCallbackHandlerImpl method testPasswordValidationCallback.
@Test
public void testPasswordValidationCallback() throws Exception {
CallbackHandler callbackHandler = createCallbackHandler(null);
Container container = new TestContainer();
container.setRealm(new TestRealm());
((Contained) callbackHandler).setContainer(container);
Subject clientSubject = new Subject();
PasswordValidationCallback pvc1 = new PasswordValidationCallback(clientSubject, "name1", "password".toCharArray());
callbackHandler.handle(new Callback[] { pvc1 });
Assert.assertTrue(pvc1.getResult());
PasswordValidationCallback pvc2 = new PasswordValidationCallback(clientSubject, "name2", "invalid".toCharArray());
callbackHandler.handle(new Callback[] { pvc2 });
Assert.assertFalse(pvc2.getResult());
Set<Object> credentials = clientSubject.getPrivateCredentials();
Assert.assertTrue(credentials.size() == 1);
GenericPrincipal gp = (GenericPrincipal) credentials.iterator().next();
Assert.assertEquals("name1", gp.getName());
}
use of org.apache.catalina.realm.GenericPrincipal in project tomcat by apache.
the class DeltaRequest method setPrincipal.
/**
* Only support principals from type {@link GenericPrincipal GenericPrincipal}
* @param p Session principal
* @see GenericPrincipal
*/
public void setPrincipal(Principal p) {
int action = (p == null) ? ACTION_REMOVE : ACTION_SET;
GenericPrincipal gp = null;
if (p != null) {
if (p instanceof GenericPrincipal) {
gp = (GenericPrincipal) p;
if (log.isDebugEnabled()) {
log.debug(sm.getString("deltaRequest.showPrincipal", p.getName(), getSessionId()));
}
} else {
log.error(sm.getString("deltaRequest.wrongPrincipalClass", p.getClass().getName()));
}
}
addAction(TYPE_PRINCIPAL, action, NAME_PRINCIPAL, gp);
}
use of org.apache.catalina.realm.GenericPrincipal in project tomcat by apache.
the class MemoryUserDatabaseTests method testSerializePrincipal.
@Test
public void testSerializePrincipal() throws Exception {
User user = db.findUser("admin");
GenericPrincipal gpIn = new UserDatabaseRealm.UserDatabasePrincipal(user, db);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(gpIn);
byte[] data = bos.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(data);
ObjectInputStream ois = new ObjectInputStream(bis);
GenericPrincipal gpOut = (GenericPrincipal) ois.readObject();
Assert.assertEquals("admin", gpOut.getName());
assertPrincipalNames(gpOut.getRoles(), user.getRoles());
}
Aggregations