use of org.apache.syncope.common.lib.to.SecurityQuestionTO in project syncope by apache.
the class SecurityQuestionsResource method newResourceResponse.
@Override
protected AbstractResource.ResourceResponse newResourceResponse(final IResource.Attributes attributes) {
LOG.debug("List available security questions");
AbstractResource.ResourceResponse response = new AbstractResource.ResourceResponse();
response.setContentType(MediaType.APPLICATION_JSON);
try {
HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
if (!xsrfCheck(request)) {
LOG.error("XSRF TOKEN does not match");
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN does not match");
return response;
}
final List<SecurityQuestionTO> securityQuestionTOs = SyncopeEnduserSession.get().getService(SecurityQuestionService.class).list();
response.setWriteCallback(new AbstractResource.WriteCallback() {
@Override
public void writeData(final IResource.Attributes attributes) throws IOException {
attributes.getResponse().write(MAPPER.writeValueAsString(securityQuestionTOs));
}
});
response.setTextEncoding(StandardCharsets.UTF_8.name());
response.setStatusCode(Response.Status.OK.getStatusCode());
} catch (Exception e) {
LOG.error("Error retrieving security questions", e);
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), new StringBuilder().append("ErrorMessage{{ ").append(e.getMessage()).append(" }}").toString());
}
return response;
}
use of org.apache.syncope.common.lib.to.SecurityQuestionTO in project syncope by apache.
the class SecurityQuestionITCase method create.
@Test
public void create() {
SecurityQuestionTO securityQuestionTO = new SecurityQuestionTO();
securityQuestionTO.setContent("What is your favorite pet's name?");
Response response = securityQuestionService.create(securityQuestionTO);
SecurityQuestionTO actual = getObject(response.getLocation(), SecurityQuestionService.class, SecurityQuestionTO.class);
assertNotNull(actual);
assertNotNull(actual.getKey());
securityQuestionTO.setKey(actual.getKey());
assertEquals(actual, securityQuestionTO);
}
use of org.apache.syncope.common.lib.to.SecurityQuestionTO in project syncope by apache.
the class SecurityQuestionByUsernameResource method newResourceResponse.
@Override
protected AbstractResource.ResourceResponse newResourceResponse(final IResource.Attributes attributes) {
LOG.debug("List available security questions");
ResourceResponse response = new AbstractResource.ResourceResponse();
response.setContentType(MediaType.APPLICATION_JSON);
try {
HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
if (!xsrfCheck(request)) {
LOG.error("XSRF TOKEN does not match");
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN does not match");
return response;
}
PageParameters parameters = attributes.getParameters();
StringValue username = parameters.get("username");
if (!username.isEmpty()) {
final SecurityQuestionTO securityQuestionTO = SyncopeEnduserSession.get().getService(SecurityQuestionService.class).readByUser(username.toString());
response.setWriteCallback(new AbstractResource.WriteCallback() {
@Override
public void writeData(final IResource.Attributes attributes) throws IOException {
attributes.getResponse().write(MAPPER.writeValueAsString(securityQuestionTO));
}
});
}
response.setContentType(MediaType.APPLICATION_JSON);
response.setTextEncoding(StandardCharsets.UTF_8.name());
response.setStatusCode(Response.Status.OK.getStatusCode());
} catch (Exception e) {
LOG.error("Error retrieving security questions", e);
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), new StringBuilder().append("ErrorMessage{{ ").append(e.getMessage()).append(" }}").toString());
}
return response;
}
use of org.apache.syncope.common.lib.to.SecurityQuestionTO in project syncope by apache.
the class SecurityQuestionDataBinderImpl method getSecurityQuestionTO.
@Override
public SecurityQuestionTO getSecurityQuestionTO(final SecurityQuestion securityQuestion) {
SecurityQuestionTO securityQuestionTO = new SecurityQuestionTO();
BeanUtils.copyProperties(securityQuestion, securityQuestionTO);
return securityQuestionTO;
}
use of org.apache.syncope.common.lib.to.SecurityQuestionTO in project syncope by apache.
the class SecurityQuestionITCase method delete.
@Test
public void delete() {
SecurityQuestionTO securityQuestion = new SecurityQuestionTO();
securityQuestion.setContent("What is your first pet's name?");
Response response = securityQuestionService.create(securityQuestion);
securityQuestion = getObject(response.getLocation(), SecurityQuestionService.class, SecurityQuestionTO.class);
securityQuestionService.delete(securityQuestion.getKey());
try {
securityQuestionService.read(securityQuestion.getKey());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
}
Aggregations