use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class ConfigurationUpdate method update.
public void update() {
if (input.parameterNumber() >= 1) {
List<AttrTO> attrList = new ArrayList<>();
boolean failed = false;
for (String parameter : input.getParameters()) {
Pair<String, String> pairParameter = Input.toPairParameter(parameter);
try {
AttrTO attrTO = configurationSyncopeOperations.get(pairParameter.getKey());
attrTO.getValues().clear();
attrTO.getValues().add(pairParameter.getValue());
configurationSyncopeOperations.set(attrTO);
attrList.add(attrTO);
} catch (IllegalArgumentException ex) {
LOG.error("Error updating configuration", ex);
configurationResultManager.genericError(ex.getMessage());
configurationResultManager.genericError(UPDATE_HELP_MESSAGE);
failed = true;
break;
} catch (SyncopeClientException | WebServiceException ex) {
LOG.error("Error updating configuration", ex);
if (ex.getMessage().startsWith("NotFound")) {
configurationResultManager.notFoundError("Configuration", pairParameter.getKey());
} else if (ex.getMessage().startsWith("InvalidValues")) {
configurationResultManager.genericError(pairParameter.getValue() + " is not a valid value for " + pairParameter.getKey());
} else {
configurationResultManager.genericError(ex.getMessage());
}
failed = true;
break;
}
}
if (!failed) {
configurationResultManager.fromUpdate(attrList);
}
} else {
configurationResultManager.commandOptionError(UPDATE_HELP_MESSAGE);
}
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class UserResultManager method printAttributes.
private void printAttributes(final Set<AttrTO> derAttrTOs) {
for (final AttrTO attrTO : derAttrTOs) {
final StringBuilder attributeSentence = new StringBuilder();
attributeSentence.append(" ").append(attrTO.getSchema()).append(": ").append(attrTO.getValues());
System.out.println(attributeSentence);
}
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class ParametersDirectoryPanel method getColumns.
@Override
protected List<IColumn<AttrTO, String>> getColumns() {
final List<IColumn<AttrTO, String>> columns = new ArrayList<>();
columns.add(new PropertyColumn<>(new ResourceModel("schema"), "schema"));
columns.add(new PropertyColumn<AttrTO, String>(new ResourceModel("values"), "values") {
private static final long serialVersionUID = -1822504503325964706L;
@Override
public void populateItem(final Item<ICellPopulator<AttrTO>> item, final String componentId, final IModel<AttrTO> rowModel) {
PlainSchemaTO modelSchemaTO = (PlainSchemaTO) rowModel.getObject().getSchemaInfo();
AttrSchemaType type = modelSchemaTO.getType();
if (type == AttrSchemaType.Binary || type == AttrSchemaType.Encrypted) {
item.add(new Label(componentId, type.name()).add(new AttributeModifier("style", "font-style:italic")));
} else {
super.populateItem(item, componentId, rowModel);
}
}
});
return columns;
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class UserSelfCreateResource method newResourceResponse.
@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
ResourceResponse response = new ResourceResponse();
response.setContentType(MediaType.TEXT_PLAIN);
try {
HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
if (!xsrfCheck(request)) {
LOG.error("XSRF TOKEN is not matching");
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN is not matching");
return response;
}
String jsonString = request.getReader().readLine();
final UserTO userTO = MAPPER.readValue(jsonString, UserTO.class);
if (!captchaCheck(request.getHeader("captcha"), request.getSession().getAttribute(SyncopeEnduserConstants.CAPTCHA_SESSION_KEY))) {
throw new IllegalArgumentException("Entered captcha is not matching");
}
if (isSelfRegistrationAllowed() && userTO != null) {
LOG.debug("User self registration request for [{}]", userTO.getUsername());
LOG.trace("Request is [{}]", userTO);
// check if request is compliant with customization form rules
if (UserRequestValidator.compliant(userTO, SyncopeEnduserApplication.get().getCustomForm(), true)) {
// 1. membership attributes management
Set<AttrTO> membAttrs = new HashSet<>();
userTO.getPlainAttrs().stream().filter(attr -> (attr.getSchema().contains(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR))).forEachOrdered(attr -> {
String[] simpleAttrs = attr.getSchema().split(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR);
MembershipTO membership = userTO.getMemberships().stream().filter(memb -> simpleAttrs[0].equals(memb.getGroupName())).findFirst().orElse(null);
if (membership == null) {
membership = new MembershipTO.Builder().group(null, simpleAttrs[0]).build();
userTO.getMemberships().add(membership);
}
AttrTO clone = SerializationUtils.clone(attr);
clone.setSchema(simpleAttrs[1]);
membership.getPlainAttrs().add(clone);
membAttrs.add(attr);
});
userTO.getPlainAttrs().removeAll(membAttrs);
// 2. millis -> Date conversion for PLAIN attributes of USER and its MEMBERSHIPS
SyncopeEnduserSession.get().getDatePlainSchemas().stream().map(plainSchema -> {
millisToDate(userTO.getPlainAttrs(), plainSchema);
return plainSchema;
}).forEachOrdered(plainSchema -> {
userTO.getMemberships().forEach(membership -> {
millisToDate(membership.getPlainAttrs(), plainSchema);
});
});
membAttrs.clear();
userTO.getDerAttrs().stream().filter(attr -> (attr.getSchema().contains(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR))).forEachOrdered(attr -> {
String[] simpleAttrs = attr.getSchema().split(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR);
MembershipTO membership = userTO.getMemberships().stream().filter(memb -> simpleAttrs[0].equals(memb.getGroupName())).findFirst().orElse(null);
if (membership == null) {
membership = new MembershipTO.Builder().group(null, simpleAttrs[0]).build();
userTO.getMemberships().add(membership);
}
AttrTO clone = SerializationUtils.clone(attr);
clone.setSchema(simpleAttrs[1]);
membership.getDerAttrs().add(clone);
membAttrs.add(attr);
});
userTO.getDerAttrs().removeAll(membAttrs);
membAttrs.clear();
userTO.getVirAttrs().stream().filter(attr -> (attr.getSchema().contains(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR))).forEachOrdered(attr -> {
String[] simpleAttrs = attr.getSchema().split(SyncopeEnduserConstants.MEMBERSHIP_ATTR_SEPARATOR);
MembershipTO membership = userTO.getMemberships().stream().filter(memb -> simpleAttrs[0].equals(memb.getGroupName())).findFirst().orElse(null);
if (membership == null) {
membership = new MembershipTO.Builder().group(null, simpleAttrs[0]).build();
userTO.getMemberships().add(membership);
}
AttrTO clone = SerializationUtils.clone(attr);
clone.setSchema(simpleAttrs[1]);
membership.getVirAttrs().add(clone);
membAttrs.add(attr);
});
userTO.getVirAttrs().removeAll(membAttrs);
LOG.debug("Received user self registration request for user: [{}]", userTO.getUsername());
LOG.trace("Received user self registration request is: [{}]", userTO);
// adapt request and create user
final Response res = SyncopeEnduserSession.get().getService(UserSelfService.class).create(userTO, true);
buildResponse(response, res.getStatus(), Response.Status.Family.SUCCESSFUL.equals(res.getStatusInfo().getFamily()) ? "User[ " + userTO.getUsername() + "] successfully created" : "ErrorMessage{{ " + res.getStatusInfo().getReasonPhrase() + " }}");
} else {
LOG.warn("Incoming create request [{}] is not compliant with form customization rules. " + "Create NOT allowed", userTO.getUsername());
buildResponse(response, Response.Status.OK.getStatusCode(), "User: " + userTO.getUsername() + " successfully created");
}
} else {
response.setError(Response.Status.FORBIDDEN.getStatusCode(), new StringBuilder().append("ErrorMessage{{").append(userTO == null ? "Request received is not valid }}" : "Self registration not allowed }}").toString());
}
} catch (Exception e) {
LOG.error("Unable to create userTO", 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.AttrTO 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);
}
}
});
}
Aggregations