Search in sources :

Example 1 with AuthenticateUserRequest

use of org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest 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();
}
Also used : User(org.haiku.haikudepotserver.dataobjects.User) AuthenticateUserRequest(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest) ObjectContext(org.apache.cayenne.ObjectContext) AuthenticateUserResult(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with AuthenticateUserRequest

use of org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest 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();
}
Also used : User(org.haiku.haikudepotserver.dataobjects.User) AuthenticateUserRequest(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest) ObjectContext(org.apache.cayenne.ObjectContext) SignedJWT(com.nimbusds.jwt.SignedJWT) AuthenticateUserResult(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with AuthenticateUserRequest

use of org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest 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();
    }
}
Also used : AuthenticateUserRequest(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest) User(org.haiku.haikudepotserver.dataobjects.User) ObjectContext(org.apache.cayenne.ObjectContext) SignedJWT(com.nimbusds.jwt.SignedJWT) AuthenticateUserResult(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with AuthenticateUserRequest

use of org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest 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)));
}
Also used : org.haiku.haikudepotserver.api1.model.user(org.haiku.haikudepotserver.api1.model.user) AuthenticateUserResult(org.haiku.haikudepotserver.api2.model.AuthenticateUserResult)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)3 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)3 AuthenticateUserRequest (org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest)3 AuthenticateUserResult (org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult)3 User (org.haiku.haikudepotserver.dataobjects.User)3 Test (org.junit.jupiter.api.Test)3 SignedJWT (com.nimbusds.jwt.SignedJWT)2 org.haiku.haikudepotserver.api1.model.user (org.haiku.haikudepotserver.api1.model.user)1 AuthenticateUserResult (org.haiku.haikudepotserver.api2.model.AuthenticateUserResult)1