use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class SchemaRestClient method deletePlainSchema.
public PlainSchemaTO deletePlainSchema(final String name) {
PlainSchemaTO response = getService(SchemaService.class).read(SchemaType.PLAIN, name);
getService(SchemaService.class).delete(SchemaType.PLAIN, name);
return response;
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class UserSelfReadResource method newResourceResponse.
@Override
protected ResourceResponse newResourceResponse(final IResource.Attributes attributes) {
LOG.debug("Requested user self information");
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;
}
UserTO userTO = SerializationUtils.clone(SyncopeEnduserSession.get().getSelfTO());
// 1. Date -> millis conversion for PLAIN MEMBERSHIPS attributes of USER
for (PlainSchemaTO plainSchema : SyncopeEnduserSession.get().getDatePlainSchemas()) {
for (MembershipTO membership : userTO.getMemberships()) {
dateToMillis(membership.getPlainAttrs(), plainSchema);
}
}
// 2. membership attributes management
for (MembershipTO membership : userTO.getMemberships()) {
String groupName = membership.getGroupName();
membership.getPlainAttrs().stream().map(attr -> {
attr.setSchema(groupName.concat(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR).concat(attr.getSchema()));
return attr;
}).forEachOrdered(attr -> {
userTO.getPlainAttrs().add(attr);
});
membership.getPlainAttrs().clear();
membership.getDerAttrs().stream().map(attr -> {
attr.setSchema(groupName.concat(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR).concat(attr.getSchema()));
return attr;
}).forEachOrdered(attr -> {
userTO.getDerAttrs().add(attr);
});
membership.getDerAttrs().clear();
membership.getVirAttrs().stream().map((attr) -> {
attr.setSchema(groupName.concat(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR).concat(attr.getSchema()));
return attr;
}).forEachOrdered(attr -> {
userTO.getVirAttrs().add(attr);
});
membership.getVirAttrs().clear();
}
// USER from customization, if empty or null ignore it, use it to filter attributes otherwise
applyFromCustomization(userTO, SyncopeEnduserApplication.get().getCustomForm());
// 1.1 Date -> millis conversion for PLAIN attributes of USER
for (PlainSchemaTO plainSchema : SyncopeEnduserSession.get().getDatePlainSchemas()) {
dateToMillis(userTO.getPlainAttrs(), plainSchema);
}
final String selfTOJson = MAPPER.writeValueAsString(userTO);
response.setContentType(MediaType.APPLICATION_JSON);
response.setTextEncoding(StandardCharsets.UTF_8.name());
response.setWriteCallback(new WriteCallback() {
@Override
public void writeData(final Attributes attributes) throws IOException {
attributes.getResponse().write(selfTOJson);
}
});
response.setStatusCode(Response.Status.OK.getStatusCode());
} catch (Exception e) {
LOG.error("Error retrieving selfTO", 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.PlainSchemaTO in project syncope by apache.
the class BaseUserSelfResource method dateToMillis.
protected void dateToMillis(final Set<AttrTO> attrs, final PlainSchemaTO plainSchema) throws ParseException {
final FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern());
attrs.stream().filter(attr -> (attr.getSchema().equals(plainSchema.getKey()))).forEachOrdered(attr -> {
for (ListIterator<String> itor = attr.getValues().listIterator(); itor.hasNext(); ) {
String value = itor.next();
try {
itor.set(String.valueOf(fmt.parse(value).getTime()));
} catch (ParseException ex) {
LOG.error("Unable to parse date {}", value);
}
}
});
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class SchemaLogic method create.
@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_CREATE + "')")
@SuppressWarnings("unchecked")
public <T extends SchemaTO> T create(final SchemaType schemaType, final T schemaTO) {
if (StringUtils.isBlank(schemaTO.getKey())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
sce.getElements().add("Schema key");
throw sce;
}
if (doesSchemaExist(schemaType, schemaTO.getKey())) {
throw new DuplicateException(schemaType + "/" + schemaTO.getKey());
}
T created;
switch(schemaType) {
case VIRTUAL:
VirSchema virSchema = virSchemaDAO.save(binder.create((VirSchemaTO) schemaTO));
created = (T) binder.getVirSchemaTO(virSchema);
break;
case DERIVED:
DerSchema derSchema = derSchemaDAO.save(binder.create((DerSchemaTO) schemaTO));
created = (T) binder.getDerSchemaTO(derSchema);
break;
case PLAIN:
default:
PlainSchema plainSchema = plainSchemaDAO.save(binder.create((PlainSchemaTO) schemaTO));
created = (T) binder.getPlainSchemaTO(plainSchema);
}
return created;
}
Aggregations