minor fixes

This commit is contained in:
anhefti 2019-06-05 13:58:35 +02:00
parent 652de887a5
commit b8ac41b066
25 changed files with 57 additions and 46 deletions

View file

@ -49,7 +49,7 @@ public class POSTMapper {
public String getString(final String name) { public String getString(final String name) {
final String first = this.params.getFirst(name); final String first = this.params.getFirst(name);
if (StringUtils.isNoneBlank(first)) { if (StringUtils.isNotBlank(first)) {
try { try {
return URLDecoder.decode(first, "UTF-8"); return URLDecoder.decode(first, "UTF-8");
} catch (final UnsupportedEncodingException e) { } catch (final UnsupportedEncodingException e) {

View file

@ -157,19 +157,19 @@ public final class Orientation implements Entity {
} }
public int xpos() { public int xpos() {
return this.xPosition != null ? this.xPosition.intValue() : -1; return this.xPosition != null ? this.xPosition.intValue() : 0;
} }
public int ypos() { public int ypos() {
return this.yPosition != null ? this.yPosition.intValue() : -1; return this.yPosition != null ? this.yPosition.intValue() : 0;
} }
public int width() { public int width() {
return this.width != null ? this.width.intValue() : -1; return this.width != null ? this.width.intValue() : 1;
} }
public int height() { public int height() {
return this.height != null ? this.height.intValue() : -1; return this.height != null ? this.height.intValue() : 1;
} }
@Override @Override

View file

@ -303,4 +303,14 @@ public final class Utils {
return builder.toString(); return builder.toString();
} }
public static String preventResponseSplittingAttack(final String string) {
final int xni = string.indexOf('\n');
final int xri = string.indexOf('\r');
if (xni >= 0 || xri >= 0) {
throw new IllegalArgumentException("Illegal argument: " + string);
}
return string;
}
} }

View file

@ -67,7 +67,7 @@ final class InstitutionalAuthenticationEntryPoint implements AuthenticationEntry
log.info("No default gui entrypoint requested: {}", requestURI); log.info("No default gui entrypoint requested: {}", requestURI);
final String logoImageBase64 = requestLogoImage(requestURI); final String logoImageBase64 = requestLogoImage(requestURI);
if (StringUtils.isNoneBlank(logoImageBase64)) { if (StringUtils.isNotBlank(logoImageBase64)) {
// forward // forward
request.getSession().setAttribute(API.PARAM_LOGO_IMAGE, logoImageBase64); request.getSession().setAttribute(API.PARAM_LOGO_IMAGE, logoImageBase64);
final RequestDispatcher dispatcher = request.getServletContext() final RequestDispatcher dispatcher = request.getServletContext()

View file

@ -329,11 +329,11 @@ public class LmsSetupForm implements TemplateComposer {
if (testResult.isOk()) { if (testResult.isOk()) {
return onOK.apply(action); return onOK.apply(action);
} else if (StringUtils.isNoneBlank(testResult.tokenRequestError)) { } else if (StringUtils.isNotBlank(testResult.tokenRequestError)) {
throw new PageMessageException( throw new PageMessageException(
new LocTextKey("sebserver.lmssetup.action.test.tokenRequestError", new LocTextKey("sebserver.lmssetup.action.test.tokenRequestError",
testResult.tokenRequestError)); testResult.tokenRequestError));
} else if (StringUtils.isNoneBlank(testResult.quizRequestError)) { } else if (StringUtils.isNotBlank(testResult.quizRequestError)) {
throw new PageMessageException( throw new PageMessageException(
new LocTextKey("sebserver.lmssetup.action.test.quizRequestError", testResult.quizRequestError)); new LocTextKey("sebserver.lmssetup.action.test.quizRequestError", testResult.quizRequestError));
} else { } else {

View file

@ -96,7 +96,7 @@ public final class Form implements FormBinding {
} }
public void putStatic(final String name, final String value) { public void putStatic(final String name, final String value) {
if (StringUtils.isNoneBlank(value)) { if (StringUtils.isNotBlank(value)) {
this.staticValues.put(name, value); this.staticValues.put(name, value);
} }
} }
@ -208,7 +208,7 @@ public final class Form implements FormBinding {
private void flush() { private void flush() {
for (final Map.Entry<String, String> entry : this.staticValues.entrySet()) { for (final Map.Entry<String, String> entry : this.staticValues.entrySet()) {
final String value = entry.getValue(); final String value = entry.getValue();
if (StringUtils.isNoneBlank(value)) { if (StringUtils.isNotBlank(value)) {
this.objectRoot.put(entry.getKey(), value); this.objectRoot.put(entry.getKey(), value);
} }
} }
@ -216,7 +216,7 @@ public final class Form implements FormBinding {
for (final Map.Entry<String, List<FormFieldAccessor>> entry : this.formFields.entrySet()) { for (final Map.Entry<String, List<FormFieldAccessor>> entry : this.formFields.entrySet()) {
entry.getValue() entry.getValue()
.stream() .stream()
.filter(ffa -> StringUtils.isNoneBlank(ffa.getStringValue())) .filter(ffa -> StringUtils.isNotBlank(ffa.getStringValue()))
.forEach(ffa -> ffa.putJsonValue(entry.getKey(), this.objectRoot)); .forEach(ffa -> ffa.putJsonValue(entry.getKey(), this.objectRoot));
} }
} }
@ -334,7 +334,7 @@ public final class Form implements FormBinding {
final Tuple<String> tuple, final Tuple<String> tuple,
final ObjectNode jsonNode) { final ObjectNode jsonNode) {
if (StringUtils.isNoneBlank(tuple._2)) { if (StringUtils.isNotBlank(tuple._2)) {
final ArrayNode arrayNode = jsonNode.putArray(tuple._1); final ArrayNode arrayNode = jsonNode.putArray(tuple._1);
final String[] split = StringUtils.split(tuple._2, Constants.LIST_SEPARATOR); final String[] split = StringUtils.split(tuple._2, Constants.LIST_SEPARATOR);
for (int i = 0; i < split.length; i++) { for (int i = 0; i < split.length; i++) {
@ -367,7 +367,7 @@ public final class Form implements FormBinding {
this.jsonValueAdapter = jsonValueAdapter; this.jsonValueAdapter = jsonValueAdapter;
} else { } else {
this.jsonValueAdapter = (tuple, jsonObject) -> { this.jsonValueAdapter = (tuple, jsonObject) -> {
if (StringUtils.isNoneBlank(tuple._2)) { if (StringUtils.isNotBlank(tuple._2)) {
jsonObject.put(tuple._1, tuple._2); jsonObject.put(tuple._1, tuple._2);
} }
}; };

View file

@ -164,7 +164,7 @@ public class FormBuilder {
template.build(this); template.build(this);
if (StringUtils.isNoneBlank(template.group)) { if (StringUtils.isNotBlank(template.group)) {
this.form.addToGroup(template.group, template.name); this.form.addToGroup(template.group, template.name);
} }
@ -255,7 +255,7 @@ public class FormBuilder {
Label valueLabel(final Composite parent, final String value, final int hspan) { Label valueLabel(final Composite parent, final String value, final int hspan) {
final Label label = new Label(parent, SWT.NONE); final Label label = new Label(parent, SWT.NONE);
label.setText((StringUtils.isNoneBlank(value)) ? value : Constants.EMPTY_NOTE); label.setText((StringUtils.isNotBlank(value)) ? value : Constants.EMPTY_NOTE);
final GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, hspan, 1); final GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, hspan, 1);
gridData.verticalIndent = 4; gridData.verticalIndent = 4;
label.setLayoutData(gridData); label.setLayoutData(gridData);

View file

@ -25,8 +25,8 @@ import org.springframework.stereotype.Service;
import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.model.Entity; import ch.ethz.seb.sebserver.gbl.model.Entity;
import ch.ethz.seb.sebserver.gbl.model.EntityName; import ch.ethz.seb.sebserver.gbl.model.EntityName;
import ch.ethz.seb.sebserver.gbl.model.exam.ExamConfigurationMap;
import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamType; import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamType;
import ch.ethz.seb.sebserver.gbl.model.exam.ExamConfigurationMap;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode;
@ -211,7 +211,7 @@ public class ResourceService {
return this.i18nSupport.supportedLanguages() return this.i18nSupport.supportedLanguages()
.stream() .stream()
.map(locale -> new Tuple<>(locale.toLanguageTag(), locale.getDisplayLanguage(currentLocale))) .map(locale -> new Tuple<>(locale.toLanguageTag(), locale.getDisplayLanguage(currentLocale)))
.filter(tuple -> StringUtils.isNoneBlank(tuple._2)) .filter(tuple -> StringUtils.isNotBlank(tuple._2))
.sorted((t1, t2) -> t1._2.compareTo(t2._2)) .sorted((t1, t2) -> t1._2.compareTo(t2._2))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View file

@ -67,11 +67,10 @@ public abstract class AbstractTableFieldBuilder implements InputFieldBuilder {
final GridData gridData = new GridData( final GridData gridData = new GridData(
SWT.FILL, SWT.FILL, SWT.FILL, SWT.FILL,
true, false, true, false,
(tableContext.orientation != null) ? tableContext.orientation.width() : 1, tableContext.orientation.width(),
(tableContext.orientation != null) ? tableContext.orientation.height() : 1); tableContext.orientation.height());
if (tableContext.orientation.height != null) {
gridData.heightHint = tableContext.orientation.height * 20 + 40; gridData.heightHint = tableContext.orientation.height() * 20 + 40;
}
table.setLayoutData(gridData); table.setLayoutData(gridData);
table.setHeaderVisible(true); table.setHeaderVisible(true);
table.addListener(SWT.Resize, event -> adaptColumnWidth(table, tableContext)); table.addListener(SWT.Resize, event -> adaptColumnWidth(table, tableContext));

View file

@ -178,7 +178,7 @@ public class CompositeTableFieldBuilder extends AbstractTableFieldBuilder {
for (final TableValue val : map.values()) { for (final TableValue val : map.values()) {
final Orientation orientation = this.tableContext.getOrientation(val.attributeId); final Orientation orientation = this.tableContext.getOrientation(val.attributeId);
final String groupId = orientation.getGroupId(); final String groupId = orientation.getGroupId();
if (StringUtils.isNoneBlank(groupId)) { if (StringUtils.isNotBlank(groupId)) {
final int cellIndex = this.columns.indexOf(groupId); final int cellIndex = this.columns.indexOf(groupId);
if (cellIndex >= 0) { if (cellIndex >= 0) {
setValueToCell( setValueToCell(

View file

@ -51,8 +51,8 @@ public class TableContext {
this.attribute = Objects.requireNonNull(attribute); this.attribute = Objects.requireNonNull(attribute);
this.viewContext = Objects.requireNonNull(viewContext); this.viewContext = Objects.requireNonNull(viewContext);
this.orientation = Objects.requireNonNull(viewContext this.orientation = Objects.requireNonNull(
.getOrientation(attribute.id)); viewContext.getOrientation(attribute.id));
this.rowAttributes = viewContext.getChildAttributes(attribute.id) this.rowAttributes = viewContext.getChildAttributes(attribute.id)
.stream() .stream()

View file

@ -18,6 +18,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.util.Utils;
public abstract class AbstractDownloadServiceHandler implements DownloadServiceHandler { public abstract class AbstractDownloadServiceHandler implements DownloadServiceHandler {
@ -59,9 +60,10 @@ public abstract class AbstractDownloadServiceHandler implements DownloadServiceH
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setContentLength(configFile.length); response.setContentLength(configFile.length);
response.setHeader(
HttpHeaders.CONTENT_DISPOSITION, final String header =
"attachment; filename=\"" + downloadFileName + "\""); "attachment; filename=\"" + Utils.preventResponseSplittingAttack(downloadFileName) + "\"";
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, header);
log.debug("Write the download data to response output"); log.debug("Write the download data to response output");

View file

@ -66,7 +66,7 @@ public final class ColorSelection extends Composite implements Selection {
final Label imageButton = widgetFactory.imageButton( final Label imageButton = widgetFactory.imageButton(
ImageIcon.COLOR, ImageIcon.COLOR,
this, this,
(StringUtils.isNoneBlank(tooltipKeyPrefix) (StringUtils.isNotBlank(tooltipKeyPrefix)
? new LocTextKey(tooltipKeyPrefix) ? new LocTextKey(tooltipKeyPrefix)
: DEFAULT_SELECT_TOOLTIP_KEY), : DEFAULT_SELECT_TOOLTIP_KEY),
this::addColorSelection); this::addColorSelection);

View file

@ -85,7 +85,7 @@ public final class MultiSelection extends Composite implements Selection {
}); });
this.labels.add(label); this.labels.add(label);
} }
if (StringUtils.isNoneBlank(selectionValue)) { if (StringUtils.isNotBlank(selectionValue)) {
select(selectionValue); select(selectionValue);
} }
} }

View file

@ -70,7 +70,7 @@ public final class MultiSelectionCheckbox extends Composite implements Selection
this.checkboxes.put(tuple._1, button); this.checkboxes.put(tuple._1, button);
} }
if (StringUtils.isNoneBlank(selectionValue)) { if (StringUtils.isNotBlank(selectionValue)) {
select(selectionValue); select(selectionValue);
} }
} }
@ -79,7 +79,7 @@ public final class MultiSelectionCheckbox extends Composite implements Selection
public void applyToolTipsForItems(final List<Tuple<String>> mapping) { public void applyToolTipsForItems(final List<Tuple<String>> mapping) {
mapping mapping
.stream() .stream()
.filter(tuple -> StringUtils.isNoneBlank(tuple._2)) .filter(tuple -> StringUtils.isNotBlank(tuple._2))
.forEach(tuple -> { .forEach(tuple -> {
final Button button = this.checkboxes.get(tuple._1); final Button button = this.checkboxes.get(tuple._1);
if (button != null) { if (button != null) {

View file

@ -67,7 +67,7 @@ public final class RadioSelection extends Composite implements Selection {
this.radioButtons.put(tuple._1, button); this.radioButtons.put(tuple._1, button);
} }
if (StringUtils.isNoneBlank(selectionValue)) { if (StringUtils.isNotBlank(selectionValue)) {
select(selectionValue); select(selectionValue);
} }
} }
@ -76,7 +76,7 @@ public final class RadioSelection extends Composite implements Selection {
public void applyToolTipsForItems(final List<Tuple<String>> mapping) { public void applyToolTipsForItems(final List<Tuple<String>> mapping) {
mapping mapping
.stream() .stream()
.filter(tuple -> StringUtils.isNoneBlank(tuple._2)) .filter(tuple -> StringUtils.isNotBlank(tuple._2))
.forEach(tuple -> { .forEach(tuple -> {
final Button button = this.radioButtons.get(tuple._1); final Button button = this.radioButtons.get(tuple._1);
if (button != null) { if (button != null) {

View file

@ -171,10 +171,10 @@ public class PaginationServiceImpl implements PaginationService {
final com.github.pagehelper.Page<Object> startPage = final com.github.pagehelper.Page<Object> startPage =
PageHelper.startPage(getPageNumber(pageNumber), getPageSize(pageSize), true, true, false); PageHelper.startPage(getPageNumber(pageNumber), getPageSize(pageSize), true, true, false);
if (table != null && StringUtils.isNoneBlank(sort)) { if (table != null && StringUtils.isNotBlank(sort)) {
final PageSortOrder sortOrder = PageSortOrder.getSortOrder(sort); final PageSortOrder sortOrder = PageSortOrder.getSortOrder(sort);
final String sortColumnName = verifySortColumnName(sort, table); final String sortColumnName = verifySortColumnName(sort, table);
if (StringUtils.isNoneBlank(sortColumnName)) { if (StringUtils.isNotBlank(sortColumnName)) {
switch (sortOrder) { switch (sortOrder) {
case DESCENDING: { case DESCENDING: {
PageHelper.orderBy(sortColumnName + " DESC"); PageHelper.orderBy(sortColumnName + " DESC");

View file

@ -106,7 +106,7 @@ public class ExamDAOImpl implements ExamDAO {
final String name = filterMap.getQuizName(); final String name = filterMap.getQuizName();
final DateTime from = filterMap.getExamFromTime(); final DateTime from = filterMap.getExamFromTime();
final Predicate<Exam> quizDataFilter = exam -> { final Predicate<Exam> quizDataFilter = exam -> {
if (StringUtils.isNoneBlank(name)) { if (StringUtils.isNotBlank(name)) {
if (!exam.name.contains(name)) { if (!exam.name.contains(name)) {
return false; return false;
} }
@ -396,7 +396,7 @@ public class ExamDAOImpl implements ExamDAO {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
final Collection<String> supporter = (StringUtils.isNoneBlank(record.getSupporter())) final Collection<String> supporter = (StringUtils.isNotBlank(record.getSupporter()))
? Arrays.asList(StringUtils.split(record.getSupporter(), Constants.LIST_SEPARATOR_CHAR)) ? Arrays.asList(StringUtils.split(record.getSupporter(), Constants.LIST_SEPARATOR_CHAR))
: null; : null;

View file

@ -244,7 +244,7 @@ final class OpenEdxLmsAPITemplate implements LmsAPITemplate {
EdXPage page = getEdxPage(pageURI).getBody(); EdXPage page = getEdxPage(pageURI).getBody();
if (page != null) { if (page != null) {
collector.addAll(page.results); collector.addAll(page.results);
while (StringUtils.isNoneBlank(page.next)) { while (StringUtils.isNotBlank(page.next)) {
page = getEdxPage(page.next).getBody(); page = getEdxPage(page.next).getBody();
collector.addAll(page.results); collector.addAll(page.results);
} }

View file

@ -96,13 +96,13 @@ public class SebClientConfigServiceImpl implements SebClientConfigService {
this.httpScheme = environment.getRequiredProperty(WEB_SERVICE_HTTP_SCHEME_KEY); this.httpScheme = environment.getRequiredProperty(WEB_SERVICE_HTTP_SCHEME_KEY);
this.serverAddress = environment.getRequiredProperty(WEB_SERVICE_SERVER_ADDRESS_KEY); this.serverAddress = environment.getRequiredProperty(WEB_SERVICE_SERVER_ADDRESS_KEY);
this.serverName = environment.getProperty(WEB_SERVICE_SERVER_NAME_KEY, (String) null); this.serverName = environment.getProperty(WEB_SERVICE_SERVER_NAME_KEY, "");
this.serverPort = environment.getRequiredProperty(WEB_SERVICE_SERVER_PORT_KEY); this.serverPort = environment.getRequiredProperty(WEB_SERVICE_SERVER_PORT_KEY);
this.discoveryEndpoint = environment.getRequiredProperty(WEB_SERVICE_EXAM_API_DISCOVERY_ENDPOINT_KEY); this.discoveryEndpoint = environment.getRequiredProperty(WEB_SERVICE_EXAM_API_DISCOVERY_ENDPOINT_KEY);
this.serverURLPrefix = UriComponentsBuilder.newInstance() this.serverURLPrefix = UriComponentsBuilder.newInstance()
.scheme(this.httpScheme) .scheme(this.httpScheme)
.host((StringUtils.isNoneBlank(this.serverName)) .host((StringUtils.isNotBlank(this.serverName))
? this.serverName ? this.serverName
: this.serverAddress) : this.serverAddress)
.port(this.serverPort) .port(this.serverPort)

View file

@ -66,7 +66,7 @@ public class SebExamConfigServiceImpl implements SebExamConfigService, XMLValueC
this.convertersByAttributeName = new HashMap<>(); this.convertersByAttributeName = new HashMap<>();
this.convertersByAttributeType = new HashMap<>(); this.convertersByAttributeType = new HashMap<>();
for (final XMLValueConverter converter : converters) { for (final XMLValueConverter converter : converters) {
if (StringUtils.isNoneBlank(converter.name())) { if (StringUtils.isNotBlank(converter.name())) {
this.convertersByAttributeName.put(converter.name(), converter); this.convertersByAttributeName.put(converter.name(), converter);
} }

View file

@ -62,7 +62,7 @@ public class ArrayOfStringConverter implements XMLValueConverter {
final XMLValueConverterService xmlValueConverterService) throws IOException { final XMLValueConverterService xmlValueConverterService) throws IOException {
final String val = (value.value != null) ? value.value : attribute.getDefaultValue(); final String val = (value.value != null) ? value.value : attribute.getDefaultValue();
if (StringUtils.isNoneBlank(val)) { if (StringUtils.isNotBlank(val)) {
final String[] values = StringUtils.split(val, Constants.LIST_SEPARATOR); final String[] values = StringUtils.split(val, Constants.LIST_SEPARATOR);
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(String.format(TEMPLATE, extractName(attribute))); sb.append(String.format(TEMPLATE, extractName(attribute)));

View file

@ -60,7 +60,7 @@ public class IntegerConverter implements XMLValueConverter {
final XMLValueConverterService xmlValueConverterService) throws IOException { final XMLValueConverterService xmlValueConverterService) throws IOException {
final String val = (value.value != null) ? value.value : attribute.getDefaultValue(); final String val = (value.value != null) ? value.value : attribute.getDefaultValue();
if (StringUtils.isNoneBlank(val)) { if (StringUtils.isNotBlank(val)) {
out.write(Utils.toByteArray(String.format(TEMPLATE, extractName(attribute), val))); out.write(Utils.toByteArray(String.format(TEMPLATE, extractName(attribute), val)));
} else { } else {
out.write(Utils.toByteArray(String.format(TEMPLATE_EMPTY, extractName(attribute)))); out.write(Utils.toByteArray(String.format(TEMPLATE_EMPTY, extractName(attribute))));

View file

@ -61,7 +61,7 @@ public class StringConverter implements XMLValueConverter {
final XMLValueConverterService xmlValueConverterService) throws IOException { final XMLValueConverterService xmlValueConverterService) throws IOException {
final String val = (value.value != null) ? value.value : attribute.getDefaultValue(); final String val = (value.value != null) ? value.value : attribute.getDefaultValue();
if (StringUtils.isNoneBlank(val)) { if (StringUtils.isNotBlank(val)) {
out.write(Utils.toByteArray(String.format(TEMPLATE, extractName(attribute), val))); out.write(Utils.toByteArray(String.format(TEMPLATE, extractName(attribute), val)));
} else { } else {
out.write(Utils.toByteArray(String.format(TEMPLATE_EMPTY, extractName(attribute)))); out.write(Utils.toByteArray(String.format(TEMPLATE_EMPTY, extractName(attribute))));

View file

@ -64,7 +64,7 @@ public class ConfigurationAttributeController extends EntityController<Configura
public List<ConfigurationAttribute> getForIds( public List<ConfigurationAttribute> getForIds(
@RequestParam(name = API.PARAM_MODEL_ID_LIST, required = false) final String modelIds) { @RequestParam(name = API.PARAM_MODEL_ID_LIST, required = false) final String modelIds) {
if (StringUtils.isNoneBlank(modelIds)) { if (StringUtils.isNotBlank(modelIds)) {
return super.getForIds(modelIds); return super.getForIds(modelIds);
} }