Search in sources :

Example 21 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class UserServiceTest method updateMe.

@Test
public void updateMe() throws Exception {
    User u = new User();
    u.setFullName("the toto");
    u.setUserId("toto");
    u.setEmail("toto@toto.fr");
    u.setPassword("toto123");
    u.setConfirmPassword("toto123");
    u.setValidated(true);
    getUserService(getAdminAuthzHeader()).createUser(u);
    SelfUserData selfUserData = new SelfUserData();
    selfUserData.setFullName("the toto123");
    selfUserData.setEmail("toto@titi.fr");
    selfUserData.setPassword("toto1234");
    selfUserData.setCurrentPassword("toto123");
    getUserService(getUserAuthzHeader("toto")).updateMe(selfUserData);
    UserInfo uInfo = getUserService(getAdminAuthzHeader()).getUser("toto");
    assertEquals("the toto123", uInfo.getFullName());
    assertEquals("toto@titi.fr", uInfo.getEmail());
    selfUserData.setFullName("the toto1234");
    selfUserData.setEmail("toto@tititi.fr");
    selfUserData.setPassword("toto12345");
    selfUserData.setCurrentPassword("toto1234");
    getUserService(getUserAuthzHeader("toto")).updateMe(selfUserData);
    uInfo = getUserService(getAdminAuthzHeader()).getUser("toto");
    assertEquals("the toto1234", uInfo.getFullName());
    assertEquals("toto@tititi.fr", uInfo.getEmail());
    getUserService(getAdminAuthzHeader()).deleteUser("toto");
}
Also used : SelfUserData(org.apache.archiva.redback.rest.api.model.v2.SelfUserData) User(org.apache.archiva.redback.rest.api.model.v2.User) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) Test(org.junit.jupiter.api.Test)

Example 22 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class UserServiceTest method registerWithValidation.

@Test
public void registerWithValidation() throws Exception {
    try {
        mockJavaMailSender.getSendedEmails().clear();
        ServicesAssert assertService = JAXRSClientFactory.create("http://localhost:" + getServerPort() + "/" + getRestServicesPath() + "/testsService/", ServicesAssert.class, Collections.singletonList(getJsonProvider()));
        assertService.clearEmailMessages();
        UserService service = getUserService(getAdminAuthzHeader());
        User u = new User();
        u.setFullName("the toto");
        u.setUserId("toto");
        u.setEmail("toto@toto.fr");
        u.setPassword("toto123");
        u.setConfirmPassword("toto123");
        String key = service.registerUser(u.getUserId(), new UserRegistrationRequest(u, "http://wine.fr/bordeaux")).getKey();
        assertNotEquals("-1", key);
        List<EmailMessage> emailMessages = assertService.getEmailMessageSended();
        assertEquals(1, emailMessages.size());
        assertEquals("toto@toto.fr", emailMessages.get(0).getTos().get(0));
        assertEquals("Welcome", emailMessages.get(0).getSubject());
        String messageContent = emailMessages.get(0).getText();
        log.info("messageContent: {}", messageContent);
        assertNotNull(messageContent);
        assertTrue(messageContent.contains("Use the following URL to validate your account."));
        assertTrue(messageContent.contains("http://wine.fr/bordeaux"));
        assertTrue(messageContent.contains("toto"));
        assertTrue(service.validateUserRegistration("toto", key).isSuccess());
        service = getUserService(getAdminAuthzHeader());
        UserInfo uInfo = service.getUser("toto");
        assertNotNull(uInfo);
        assertTrue(uInfo.isValidated());
        assertTrue(uInfo.isPasswordChangeRequired());
    // assertTrue( service.validateUserFromKey( key ).isSuccess( ) );
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        deleteUserQuietly("toto");
    }
}
Also used : EmailMessage(org.apache.archiva.redback.rest.services.mock.EmailMessage) User(org.apache.archiva.redback.rest.api.model.v2.User) UserService(org.apache.archiva.redback.rest.api.services.v2.UserService) ServicesAssert(org.apache.archiva.redback.rest.services.mock.ServicesAssert) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) UserRegistrationRequest(org.apache.archiva.redback.rest.api.model.v2.UserRegistrationRequest) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 23 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class UserServiceTest method resetPassword.

@Test
public void resetPassword() throws Exception {
    try {
        mockJavaMailSender.getSendedEmails().clear();
        ServicesAssert assertService = JAXRSClientFactory.create("http://localhost:" + getServerPort() + "/" + getRestServicesPath() + "/testsService/", ServicesAssert.class, Collections.singletonList(getJsonProvider()));
        assertService.clearEmailMessages();
        UserService service = getUserService(getAdminAuthzHeader());
        User u = new User();
        u.setFullName("the toto");
        u.setUserId("toto");
        u.setEmail("toto@toto.fr");
        u.setPassword("toto123");
        u.setConfirmPassword("toto123");
        String key = service.registerUser(u.getUserId(), new UserRegistrationRequest(u, "http://wine.fr/bordeaux")).getKey();
        assertNotEquals("-1", key);
        WebClient.client(assertService).accept(MediaType.APPLICATION_JSON_TYPE);
        WebClient.client(assertService).type(MediaType.APPLICATION_JSON_TYPE);
        List<EmailMessage> emailMessages = assertService.getEmailMessageSended();
        assertEquals(1, emailMessages.size());
        assertEquals("toto@toto.fr", emailMessages.get(0).getTos().get(0));
        assertEquals("Welcome", emailMessages.get(0).getSubject());
        assertTrue(emailMessages.get(0).getText().contains("Use the following URL to validate your account."));
        // assertTrue( service.validateUserFromKey( key ).isSuccess( ) );
        service = getUserService(getAdminAuthzHeader());
        UserInfo uInfo = service.getUser("toto");
        assertNotNull(uInfo);
        assertFalse(uInfo.isValidated());
        assertTrue(uInfo.isPasswordChangeRequired());
        // assertTrue( service.validateUserFromKey( key ).isSuccess( ) );
        assertEquals(200, service.resetPassword(u.getUserId()).getStatus());
        emailMessages = assertService.getEmailMessageSended();
        assertEquals(2, emailMessages.size());
        assertEquals("toto@toto.fr", emailMessages.get(1).getTos().get(0));
        String messageContent = emailMessages.get(1).getText();
        assertNotNull(messageContent);
        assertTrue(messageContent.contains("Password Reset"));
        assertTrue(messageContent.contains("Username: toto"));
        assertTrue(messageContent.contains("/security/login"));
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        deleteUserQuietly("toto");
    }
}
Also used : EmailMessage(org.apache.archiva.redback.rest.services.mock.EmailMessage) User(org.apache.archiva.redback.rest.api.model.v2.User) UserService(org.apache.archiva.redback.rest.api.services.v2.UserService) ServicesAssert(org.apache.archiva.redback.rest.services.mock.ServicesAssert) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) UserRegistrationRequest(org.apache.archiva.redback.rest.api.model.v2.UserRegistrationRequest) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 24 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class UserServiceTest method lockUnlockUser.

@Test
public void lockUnlockUser() throws Exception {
    try {
        // START SNIPPET: create-user
        User user = new User("toto", "toto the king", "toto@toto.fr", false, false);
        user.setPassword("foo123");
        user.setPasswordChangeRequired(false);
        user.setLocked(false);
        user.setValidated(true);
        UserService userService = getUserService(getAdminAuthzHeader());
        userService.createUser(user);
        // END SNIPPET: create-user
        UserInfo userInfo = userService.getUser("toto");
        assertNotNull(userInfo);
        assertEquals("toto the king", userInfo.getFullName());
        assertEquals("toto@toto.fr", userInfo.getEmail());
        TokenResponse result = getLoginServiceV2(null).logIn(new TokenRequest("toto", "foo123", GrantType.AUTHORIZATION_CODE));
        getLoginServiceV2("Bearer " + result.getAccessToken()).pingWithAutz();
        userService.lockUser("toto");
        assertTrue(userService.getUser("toto").isLocked());
        userService.unlockUser("toto");
        assertFalse(userService.getUser("toto").isLocked());
    } finally {
        getUserService(getAdminAuthzHeader()).deleteUser("toto");
        getUserService(getAdminAuthzHeader()).removeFromCache("toto");
        try {
            getUserService(getAdminAuthzHeader()).getUser("toto");
            assertTrue(false, "404 should be thrown for non existing resource");
        } catch (NotFoundException e) {
            assertEquals(404, e.getResponse().getStatus());
        }
    }
}
Also used : User(org.apache.archiva.redback.rest.api.model.v2.User) TokenResponse(org.apache.archiva.redback.rest.api.model.v2.TokenResponse) UserService(org.apache.archiva.redback.rest.api.services.v2.UserService) TokenRequest(org.apache.archiva.redback.rest.api.model.v2.TokenRequest) NotFoundException(javax.ws.rs.NotFoundException) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) Test(org.junit.jupiter.api.Test)

Example 25 with UserInfo

use of org.neo4j.ogm.domain.gh777.UserInfo in project archiva-redback-core by apache.

the class UserServiceTest method register.

@Test
public void register() throws Exception {
    try {
        mockJavaMailSender.getSendedEmails().clear();
        ServicesAssert assertService = JAXRSClientFactory.create("http://localhost:" + getServerPort() + "/" + getRestServicesPath() + "/testsService/", ServicesAssert.class, Collections.singletonList(getJsonProvider()));
        assertService.clearEmailMessages();
        UserService service = getUserService(getAdminAuthzHeader());
        User u = new User();
        u.setFullName("the toto");
        u.setUserId("toto");
        u.setEmail("toto@toto.fr");
        u.setPassword("toto123");
        u.setConfirmPassword("toto123");
        String key = service.registerUser(u.getUserId(), new UserRegistrationRequest(u, "http://wine.fr/bordeaux")).getKey();
        assertNotEquals("-1", key);
        List<EmailMessage> emailMessages = assertService.getEmailMessageSended();
        assertEquals(1, emailMessages.size());
        assertEquals("toto@toto.fr", emailMessages.get(0).getTos().get(0));
        assertEquals("Welcome", emailMessages.get(0).getSubject());
        String messageContent = emailMessages.get(0).getText();
        log.info("messageContent: {}", messageContent);
        assertNotNull(messageContent);
        assertTrue(messageContent.contains("Use the following URL to validate your account."));
        assertTrue(messageContent.contains("http://wine.fr/bordeaux"));
        assertTrue(messageContent.contains("toto"));
        // assertTrue( service.validateUserFromKey( key ).isSuccess( ) );
        service = getUserService(getAdminAuthzHeader());
        UserInfo uInfo = service.getUser("toto");
        assertNotNull(uInfo);
        assertFalse(uInfo.isValidated());
        assertTrue(uInfo.isPasswordChangeRequired());
    // assertTrue( service.validateUserFromKey( key ).isSuccess( ) );
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        deleteUserQuietly("toto");
    }
}
Also used : EmailMessage(org.apache.archiva.redback.rest.services.mock.EmailMessage) User(org.apache.archiva.redback.rest.api.model.v2.User) UserService(org.apache.archiva.redback.rest.api.services.v2.UserService) ServicesAssert(org.apache.archiva.redback.rest.services.mock.ServicesAssert) UserInfo(org.apache.archiva.redback.rest.api.model.v2.UserInfo) UserRegistrationRequest(org.apache.archiva.redback.rest.api.model.v2.UserRegistrationRequest) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Aggregations

UserInfo (org.apache.archiva.redback.rest.api.model.v2.UserInfo)19 Test (org.junit.jupiter.api.Test)15 Response (io.restassured.response.Response)8 HashMap (java.util.HashMap)8 UserInfo (edu.uiuc.ncsa.security.oauth_2_0.UserInfo)7 BaseUserInfo (org.apache.archiva.redback.rest.api.model.v2.BaseUserInfo)7 UserService (org.apache.archiva.redback.rest.api.services.v2.UserService)6 NotFoundException (javax.ws.rs.NotFoundException)5 User (org.apache.archiva.redback.rest.api.model.v2.User)5 ForbiddenException (javax.ws.rs.ForbiddenException)4 JSONObject (net.sf.json.JSONObject)4 RoleInfo (org.apache.archiva.redback.rest.api.model.v2.RoleInfo)4 List (java.util.List)3 Map (java.util.Map)3 PagedResult (org.apache.archiva.components.rest.model.PagedResult)3 RoleTemplate (org.apache.archiva.redback.rest.api.model.v2.RoleTemplate)3 UserRegistrationRequest (org.apache.archiva.redback.rest.api.model.v2.UserRegistrationRequest)3 RedbackServiceException (org.apache.archiva.redback.rest.api.services.RedbackServiceException)3 EmailMessage (org.apache.archiva.redback.rest.services.mock.EmailMessage)3 ServicesAssert (org.apache.archiva.redback.rest.services.mock.ServicesAssert)3