use of org.keycloak.representations.idm.EventRepresentation in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailNewBrowserSession.
@Test
public void verifyEmailNewBrowserSession() throws IOException, MessagingException {
loginPage.open();
loginPage.login("test-user@localhost", "password");
verifyEmailPage.assertCurrent();
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
AssertEvents.ExpectedEvent emailEvent = events.expectRequiredAction(EventType.SEND_VERIFY_EMAIL).detail("email", "test-user@localhost");
EventRepresentation sendEvent = emailEvent.assertEvent();
String mailCodeId = sendEvent.getDetails().get(Details.CODE_ID);
driver.manage().deleteAllCookies();
driver.navigate().to(verificationUrl.trim());
proceedPage.assertCurrent();
proceedPage.clickProceedLink();
infoPage.assertCurrent();
events.expectRequiredAction(EventType.VERIFY_EMAIL).user(testUserId).detail(Details.CODE_ID, Matchers.not(Matchers.is(mailCodeId))).client(// the "test-app" client specified in loginPage.open() is expected
oauth.getClientId()).detail(Details.REDIRECT_URI, Matchers.any(String.class)).assertEvent();
infoPage.assertCurrent();
assertEquals("Your email address has been verified.", infoPage.getInfo());
loginPage.open();
loginPage.assertCurrent();
}
use of org.keycloak.representations.idm.EventRepresentation in project keycloak by keycloak.
the class EntitlementAPITest method testInvalidTokenSignature.
@Test
public void testInvalidTokenSignature() throws Exception {
RealmEventsConfigRepresentation eventConfig = getRealm().getRealmEventsConfig();
eventConfig.setEventsEnabled(true);
eventConfig.setEnabledEventTypes(Arrays.asList(EventType.PERMISSION_TOKEN_ERROR.name()));
getRealm().updateRealmEventsConfig(eventConfig);
ClientResource client = getClient(getRealm(), RESOURCE_SERVER_TEST);
AuthorizationResource authorization = client.authorization();
JSPolicyRepresentation policy = new JSPolicyRepresentation();
policy.setName(KeycloakModelUtils.generateId());
policy.setCode("$evaluation.grant();");
authorization.policies().js().create(policy).close();
ResourceRepresentation resource = new ResourceRepresentation();
resource.setName("Sensors");
try (Response response = authorization.resources().create(resource)) {
response.readEntity(ResourceRepresentation.class);
}
ResourcePermissionRepresentation permission = new ResourcePermissionRepresentation();
permission.setName("View Sensor");
permission.addPolicy(policy.getName());
authorization.permissions().resource().create(permission).close();
String accessToken = new OAuthClient().realm("authz-test").clientId(RESOURCE_SERVER_TEST).doGrantAccessTokenRequest("secret", "marta", "password").getAccessToken();
AuthzClient authzClient = getAuthzClient(AUTHZ_CLIENT_CONFIG);
AuthorizationRequest request = new AuthorizationRequest();
request.addPermission("Sensors");
request.setSubjectToken(accessToken + "i");
try {
authzClient.authorization().authorize(request);
fail("should fail, session invalidated");
} catch (Exception e) {
Throwable expected = e.getCause();
assertEquals(400, HttpResponseException.class.cast(expected).getStatusCode());
assertTrue(HttpResponseException.class.cast(expected).toString().contains("unauthorized_client"));
}
List<EventRepresentation> events = getRealm().getEvents(Arrays.asList(EventType.PERMISSION_TOKEN_ERROR.name()), null, null, null, null, null, null, null);
assertEquals(1, events.size());
}
use of org.keycloak.representations.idm.EventRepresentation in project keycloak by keycloak.
the class RealmTest method deleteSession.
@Test
public void deleteSession() {
setupTestAppAndUser();
oauth.doLogin("testuser", "password");
AccessTokenResponse tokenResponse = oauth.doAccessTokenRequest(oauth.getCurrentQuery().get(OAuth2Constants.CODE), "secret");
assertEquals(200, tokenResponse.getStatusCode());
EventRepresentation event = events.poll();
assertNotNull(event);
realm.deleteSession(event.getSessionId());
assertAdminEvents.assertEvent(realmId, OperationType.DELETE, AdminEventPaths.deleteSessionPath(event.getSessionId()), ResourceType.USER_SESSION);
try {
realm.deleteSession(event.getSessionId());
fail("Expected 404");
} catch (NotFoundException e) {
// Expected
assertAdminEvents.assertEmpty();
}
tokenResponse = oauth.doRefreshTokenRequest(tokenResponse.getRefreshToken(), "secret");
assertEquals(400, tokenResponse.getStatusCode());
assertEquals("Session not active", tokenResponse.getErrorDescription());
}
use of org.keycloak.representations.idm.EventRepresentation in project keycloak by keycloak.
the class LoginTest method loginAgainWithoutRememberMe.
// KEYCLOAK-2741
@Test
public void loginAgainWithoutRememberMe() {
setRememberMe(true);
try {
// login with remember me
loginPage.open();
assertFalse(loginPage.isRememberMeChecked());
loginPage.setRememberMe(true);
assertTrue(loginPage.isRememberMeChecked());
loginPage.login("login-test", "password");
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE));
EventRepresentation loginEvent = events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").detail(Details.REMEMBER_ME, "true").assertEvent();
String sessionId = loginEvent.getSessionId();
// Expire session
testingClient.testing().removeUserSession("test", sessionId);
// Assert rememberMe checked and username/email prefilled
loginPage.open();
assertTrue(loginPage.isRememberMeChecked());
Assert.assertEquals("login-test", loginPage.getUsername());
// login without remember me
loginPage.setRememberMe(false);
loginPage.login("login-test", "password");
// Expire session
loginEvent = events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent();
sessionId = loginEvent.getSessionId();
testingClient.testing().removeUserSession("test", sessionId);
// Assert rememberMe not checked nor username/email prefilled
loginPage.open();
assertFalse(loginPage.isRememberMeChecked());
assertNotEquals("login-test", loginPage.getUsername());
} finally {
setRememberMe(false);
}
}
use of org.keycloak.representations.idm.EventRepresentation in project keycloak by keycloak.
the class LevelOfAssuranceFlowTest method assertLoggedInWithAcr.
private void assertLoggedInWithAcr(String acr) {
EventRepresentation loginEvent = events.expectLogin().detail(Details.USERNAME, "test-user@localhost").assertEvent();
IDToken idToken = sendTokenRequestAndGetIDToken(loginEvent);
Assert.assertEquals(acr, idToken.getAcr());
}
Aggregations