use of org.apache.catalina.realm.GenericPrincipal in project tomee by apache.
the class CdiEventRealmTest method userPassword.
@Test
public void userPassword() {
final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate("john", "secret"));
assertEquals("john", gp.getName());
assertEquals("", gp.getPassword());
assertEquals(1, gp.getRoles().length);
assertEquals("admin", gp.getRoles()[0]);
}
use of org.apache.catalina.realm.GenericPrincipal in project tomee by apache.
the class CdiEventRealmTest method digest.
@Test
public void digest() {
final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate("ryan", "md5", "nonce", "nc", "cnonce", "qop", "realm", "md5a2"));
final String[] actual = gp.getRoles();
final String[] expected = new String[] { "ryan", "md5", "nonce", "nc", "cnonce", "qop", "realm", "md5a2" };
Arrays.sort(actual);
Arrays.sort(expected);
assertArrayEquals(actual, expected);
}
use of org.apache.catalina.realm.GenericPrincipal in project tomee by apache.
the class TomcatSecurityService method createSubject.
private Subject createSubject(final Realm realm, final Principal principal) {
final Subject subject = new Subject();
// 1. Add the principal as is
subject.getPrincipals().add(principal);
subject.getPrincipals().add(new TomcatUser(realm, principal));
Principal p = principal;
if (principal instanceof TomcatUser) {
// should never happen
p = ((TomcatUser) principal).getTomcatPrincipal();
subject.getPrincipals().add(p);
}
if (p instanceof GenericPrincipal) {
final GenericPrincipal genericPrincipal = (GenericPrincipal) p;
subject.getPrincipals().add(genericPrincipal.getUserPrincipal());
// todo should we create credentials with the roles? groups?
subject.getPrivateCredentials().add(p);
}
return subject;
}
use of org.apache.catalina.realm.GenericPrincipal in project keycloak by keycloak.
the class CatalinaCookieTokenStore method isCached.
@Override
public boolean isCached(RequestAuthenticator authenticator) {
// Assuming authenticatedPrincipal set by previous call of checkCurrentToken() during this request
if (authenticatedPrincipal != null) {
log.fine("remote logged in already. Establish state from cookie");
RefreshableKeycloakSecurityContext securityContext = authenticatedPrincipal.getKeycloakSecurityContext();
if (!securityContext.getRealm().equals(deployment.getRealm())) {
log.fine("Account from cookie is from a different realm than for the request.");
return false;
}
securityContext.setCurrentRequestInfo(deployment, this);
Set<String> roles = AdapterUtils.getRolesFromSecurityContext(securityContext);
GenericPrincipal principal = principalFactory.createPrincipal(request.getContext().getRealm(), authenticatedPrincipal, roles);
request.setAttribute(KeycloakSecurityContext.class.getName(), securityContext);
request.setUserPrincipal(principal);
request.setAuthType("KEYCLOAK");
return true;
} else {
return false;
}
}
use of org.apache.catalina.realm.GenericPrincipal in project keycloak by keycloak.
the class CatalinaSessionTokenStore method saveAccountInfo.
@Override
public void saveAccountInfo(OidcKeycloakAccount account) {
RefreshableKeycloakSecurityContext securityContext = (RefreshableKeycloakSecurityContext) account.getKeycloakSecurityContext();
Set<String> roles = account.getRoles();
GenericPrincipal principal = principalFactory.createPrincipal(request.getContext().getRealm(), account.getPrincipal(), roles);
SerializableKeycloakAccount sAccount = new SerializableKeycloakAccount(roles, account.getPrincipal(), securityContext);
Session session = request.getSessionInternal(true);
session.setPrincipal(principal);
session.setAuthType("KEYCLOAK");
session.getSession().setAttribute(SerializableKeycloakAccount.class.getName(), sAccount);
session.getSession().setAttribute(KeycloakSecurityContext.class.getName(), account.getKeycloakSecurityContext());
String username = securityContext.getToken().getSubject();
log.fine("userSessionManagement.login: " + username);
this.sessionManagement.login(session);
}
Aggregations