use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class UrlAccessRestrictionCheckingProcessorTest method testAllowedAccess.
@Test
public void testAllowedAccess() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", URL);
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
Profile profile = new Profile();
profile.setRoles(SetUtils.asSet(ADMIN_ROLE));
SecurityUtils.setAuthentication(request, new DefaultAuthentication(new ObjectId().toString(), profile));
processor.processRequest(context, chain);
verify(chain).processRequest(context);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileController method getAttachment.
@RequestMapping(value = URL_PROFILE_GET_ATTACHMENT, method = RequestMethod.GET)
@ApiOperation(value = "Gets the requested attachment of the given profile", notes = "If Attachment or profile does not exist will " + "throw error, content-type,content-legnth headers" + " are set")
public void getAttachment(@ApiParam("The profile's ID") @PathVariable(PATH_VAR_ID) String profileId, @ApiParam("Attachment Id to get") @PathVariable(PATH_VAR_ATTACHMENT) String attachmentId, HttpServletResponse response) throws ProfileException, IOException {
Profile profile = profileService.getProfile(profileId);
if (profile != null) {
InputStream input = null;
try {
input = profileService.getProfileAttachment(attachmentId, profile.getId().toString());
if (input != null) {
ProfileAttachment attachment = profileService.getProfileAttachmentInformation(profile.getId().toString(), attachmentId);
response.setContentType(attachment.getContentType());
response.setContentLength((int) attachment.getFileSizeBytes());
IOUtils.copy(input, response.getOutputStream());
}
} catch (ProfileException ex) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
response.setContentLength(0);
} finally {
if (input != null) {
input.close();
}
}
} else {
throw new NoSuchProfileException.ById(profileId);
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testGetProfileByUsername.
@Test
public void testGetProfileByUsername() throws Exception {
Profile profile = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME);
assertAdminProfile(profile);
// Try with unknown username
profile = profileService.getProfileByUsername(DEFAULT_TENANT, "unknown");
assertNull(profile);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testResetAndChangePassword.
@Test
public void testResetAndChangePassword() throws Exception {
GreenMail mailServer = new GreenMail(ServerSetupTest.SMTP);
mailServer.start();
Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1, AVASQUEZ_EMAIL1, true, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
try {
profile = profileService.resetPassword(profile.getId().toString(), RESET_PASSWORD_URL);
assertNotNull(profile);
// Wait a few seconds so that the email can be sent
Thread.sleep(3000);
String email = GreenMailUtil.getBody(mailServer.getReceivedMessages()[0]);
assertNotNull(email);
Pattern emailPattern = Pattern.compile(VERIFICATION_EMAIL_REGEX, Pattern.DOTALL);
Matcher emailMatcher = emailPattern.matcher(email);
assertTrue(emailMatcher.matches());
String resetTokenId = emailMatcher.group(1);
Profile profileAfterPswdReset = profileService.changePassword(resetTokenId, AVASQUEZ_PASSWORD2);
assertNotNull(profileAfterPswdReset);
assertEquals(profile.getId(), profileAfterPswdReset.getId());
assertNull(profileAfterPswdReset.getPassword());
} finally {
profileService.deleteProfile(profile.getId().toString());
mailServer.stop();
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testGetProfile.
@Test
public void testGetProfile() throws Exception {
ObjectId profileId = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME).getId();
Profile profile = profileService.getProfile(profileId.toString());
assertAdminProfile(profile);
// Try with unknown profile ID
profileId = ObjectId.get();
profile = profileService.getProfile(profileId.toString());
assertNull(profile);
}
Aggregations