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());
}
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 + "'");
}
}
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 + "'");
}
}
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));
}
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);
}
Aggregations