Search in sources :

Example 76 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class RestLoginSuccessHandlerTest method testHandle.

@Test
public void testHandle() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/login.json");
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response, null);
    String ticket = UUID.randomUUID().toString();
    ObjectId profileId = new ObjectId();
    Profile profile = new Profile();
    profile.setId(profileId);
    profile.setUsername("jdoe");
    profile.setPassword("1234");
    profile.setEmail("jdoe@craftercms.org");
    Authentication auth = new DefaultAuthentication(ticket.toString(), profile);
    handler.handle(context, auth);
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    assertEquals("{\"ticket\":\"" + ticket + "\",\"profile\":{\"username\":\"jdoe\"," + "\"password\":\"1234\",\"email\":\"jdoe@craftercms.org\",\"verified\":false," + "\"enabled\":false,\"createdOn\":null,\"lastModified\":null,\"tenant\":null,\"roles\":[]," + "\"attributes\":{},\"failedLoginAttempts\":0,\"lastFailedLogin\":null,\"id\":\"" + profileId.toString() + "\"},\"remembered\":false}", response.getContentAsString());
}
Also used : ObjectId(org.bson.types.ObjectId) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Authentication(org.craftercms.security.authentication.Authentication) RequestContext(org.craftercms.commons.http.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 77 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileController method updateProfile.

@RequestMapping(value = URL_UPDATE_PROFILE, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateProfile(@RequestBody Profile profile) throws ProfileException {
    String id = profile.getId().toString();
    Profile currentProfile = profileService.getProfile(id);
    if (currentProfile != null) {
        checkIfAllowed(currentProfile, Action.UPDATE_PROFILE);
        profileService.updateProfile(id, profile.getUsername(), profile.getPassword(), profile.getEmail(), profile.isEnabled(), profile.getRoles(), profile.getAttributes(), ProfileConstants.NO_ATTRIBUTE);
        return Collections.singletonMap(MODEL_MESSAGE, String.format(MSG_PROFILE_UPDATED_FORMAT, id));
    } else {
        throw new ResourceNotFoundException("No profile found for ID '" + id + "'");
    }
}
Also used : ResourceNotFoundException(org.craftercms.profile.management.exceptions.ResourceNotFoundException) Profile(org.craftercms.profile.api.Profile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 78 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileController method deleteProfile.

@RequestMapping(value = URL_DELETE_PROFILE, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> deleteProfile(@PathVariable(PATH_VAR_ID) String id) throws ProfileException {
    Profile profile = profileService.getProfile(id);
    if (profile != null) {
        checkIfAllowed(profile, Action.DELETE_PROFILE);
        profileService.deleteProfile(id);
        return Collections.singletonMap(MODEL_MESSAGE, String.format(MSG_PROFILE_DELETED_FORMAT, id));
    } else {
        throw new ResourceNotFoundException("No profile found for ID '" + id + "'");
    }
}
Also used : ResourceNotFoundException(org.craftercms.profile.management.exceptions.ResourceNotFoundException) Profile(org.craftercms.profile.api.Profile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 79 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileControllerTest method testGetProfileList.

@Test
public void testGetProfileList() throws Exception {
    Profile currentUser = getProfile(TENANT_NAME1, PROFILE_ID1, USERNAME1, PROFILE_ADMIN_ROLE);
    setCurrentUser(currentUser);
    List<Profile> profiles = controller.getProfileList(TENANT_NAME1, USERNAME1, null, null, null, null);
    assertNotNull(profiles);
    assertEquals(1, profiles.size());
    assertProfiles(currentUser, profiles.get(0));
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 80 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileControllerTest method testGetProfile.

@Test
public void testGetProfile() throws Exception {
    Profile currentUser = getProfile(TENANT_NAME1, PROFILE_ID1, USERNAME1, PROFILE_ADMIN_ROLE);
    setCurrentUser(currentUser);
    Profile profile = controller.getProfile(PROFILE_ID1.toString());
    assertNotNull(profile);
    assertProfiles(currentUser, profile);
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Aggregations

Profile (org.craftercms.profile.api.Profile)111 Test (org.junit.Test)54 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)19 MongoDataException (org.craftercms.commons.mongo.MongoDataException)15 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)15 LinkedHashMap (java.util.LinkedHashMap)13 VerificationToken (org.craftercms.profile.api.VerificationToken)13 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)12 Date (java.util.Date)11 Map (java.util.Map)11 ObjectId (org.bson.types.ObjectId)10 RequestContext (org.craftercms.commons.http.RequestContext)9 Authentication (org.craftercms.security.authentication.Authentication)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 Mockito.anyString (org.mockito.Mockito.anyString)9 RequestSecurityProcessorChain (org.craftercms.security.processors.RequestSecurityProcessorChain)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 Tenant (org.craftercms.profile.api.Tenant)6 HashMap (java.util.HashMap)4