use of org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult in project haikudepotserver by haiku.
the class UserApiIT method testAuthenticateUser_fail.
@Test
public void testAuthenticateUser_fail() {
ObjectContext context = serverRuntime.newContext();
User user = integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
setAuthenticatedUser("testuser");
// ------------------------------------
AuthenticateUserResult result = userApi.authenticateUser(new AuthenticateUserRequest("testuser", "y63j20f22"));
// ------------------------------------
Assertions.assertThat(result.token).isNull();
}
use of org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult in project haikudepotserver by haiku.
the class UserApiIT method testAuthenticateUser_succcessWithAgreement.
@Test
public void testAuthenticateUser_succcessWithAgreement() throws Exception {
ObjectContext context = serverRuntime.newContext();
User user = integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
integrationTestSupportService.agreeToUserUsageConditions(context, user);
setAuthenticatedUser("testuser");
// ------------------------------------
AuthenticateUserResult result = userApi.authenticateUser(new AuthenticateUserRequest("testuser", "U7vqpsu6BB"));
// ------------------------------------
Assertions.assertThat(result.token).isNotNull();
Assertions.assertThat(userAuthenticationService.authenticateByToken(result.token).isPresent()).isTrue();
SignedJWT signedJWT = SignedJWT.parse(result.token);
Map<String, Object> claims = signedJWT.getJWTClaimsSet().getClaims();
Assertions.assertThat(signedJWT.getJWTClaimsSet().getSubject()).isEqualTo("testuser@hds");
// because the user has agreed to the usage conditions they will not get
// this flag in the response JWT token.
Assertions.assertThat(claims.get("ucnd")).isNull();
}
use of org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult in project haikudepotserver by haiku.
the class UserApiIT method testAuthenticateUser_succcessNoAgreement.
@Test
public void testAuthenticateUser_succcessNoAgreement() throws Exception {
ObjectContext context = serverRuntime.newContext();
integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
setAuthenticatedUser("testuser");
// ------------------------------------
AuthenticateUserResult result = userApi.authenticateUser(new AuthenticateUserRequest("testuser", "U7vqpsu6BB"));
// ------------------------------------
Assertions.assertThat(result.token).isNotNull();
Assertions.assertThat(userAuthenticationService.authenticateByToken(result.token).isPresent()).isTrue();
SignedJWT signedJWT = SignedJWT.parse(result.token);
Map<String, Object> claims = signedJWT.getJWTClaimsSet().getClaims();
Assertions.assertThat(signedJWT.getJWTClaimsSet().getSubject()).isEqualTo("testuser@hds");
// because the user has not agreed to the usage conditions they will get
// this flag come up in their token.
Assertions.assertThat(claims.get("ucnd")).isEqualTo(Boolean.TRUE);
{
User userAfter = User.getByNickname(context, "testuser");
Assertions.assertThat(userAfter.getLastAuthenticationTimestamp()).isNotNull();
}
}
use of org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult in project haikudepotserver by haiku.
the class UserApiImpl method authenticateUser.
@Override
public ResponseEntity<AuthenticateUserResponseEnvelope> authenticateUser(AuthenticateUserRequestEnvelope authenticateUserRequestEnvelope) {
AuthenticateUserRequest requestV1 = new AuthenticateUserRequest();
requestV1.nickname = authenticateUserRequestEnvelope.getNickname();
requestV1.passwordClear = authenticateUserRequestEnvelope.getPasswordClear();
org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult resultV1 = userApiV1.authenticateUser(requestV1);
return ResponseEntity.ok(new AuthenticateUserResponseEnvelope().result(new AuthenticateUserResult().token(resultV1.token)));
}
Aggregations