code cleanup
This commit is contained in:
parent
cd8ba371cc
commit
1e7b6f807f
23 changed files with 211 additions and 207 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
package ch.ethz.seb.sebserver;
|
package ch.ethz.seb.sebserver;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
@ -22,6 +23,8 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.ssl.SSLContextBuilder;
|
import org.apache.http.ssl.SSLContextBuilder;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -57,6 +60,8 @@ import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||||
@Order(6)
|
@Order(6)
|
||||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter implements ErrorController {
|
public class WebSecurityConfig extends WebSecurityConfigurerAdapter implements ErrorController {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(WebSecurityConfig.class);
|
||||||
|
|
||||||
@Value("${sebserver.webservice.api.admin.endpoint}")
|
@Value("${sebserver.webservice.api.admin.endpoint}")
|
||||||
private String adminEndpoint;
|
private String adminEndpoint;
|
||||||
@Value("${sebserver.webservice.api.redirect.unauthorized}")
|
@Value("${sebserver.webservice.api.redirect.unauthorized}")
|
||||||
|
@ -106,16 +111,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter implements E
|
||||||
@DevGuiProfile
|
@DevGuiProfile
|
||||||
@DevWebServiceProfile
|
@DevWebServiceProfile
|
||||||
public ClientHttpRequestFactory clientHttpRequestFactory() {
|
public ClientHttpRequestFactory clientHttpRequestFactory() {
|
||||||
// TODO set connection and read timeout!? configurable!?
|
log.info("Initialize with insecure ClientHttpRequestFactory for development");
|
||||||
return new SimpleClientHttpRequestFactory() {
|
return new DevClientHttpRequestFactory();
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void prepareConnection(final HttpURLConnection connection, final String httpMethod)
|
|
||||||
throws IOException {
|
|
||||||
super.prepareConnection(connection, httpMethod);
|
|
||||||
connection.setInstanceFollowRedirects(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A ClientHttpRequestFactory used in production with TSL SSL configuration.
|
/** A ClientHttpRequestFactory used in production with TSL SSL configuration.
|
||||||
|
@ -139,15 +136,22 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter implements E
|
||||||
public ClientHttpRequestFactory clientHttpRequestFactoryTLS(final Environment env) throws KeyManagementException,
|
public ClientHttpRequestFactory clientHttpRequestFactoryTLS(final Environment env) throws KeyManagementException,
|
||||||
NoSuchAlgorithmException, KeyStoreException, CertificateException, FileNotFoundException, IOException {
|
NoSuchAlgorithmException, KeyStoreException, CertificateException, FileNotFoundException, IOException {
|
||||||
|
|
||||||
|
log.info("Initialize with secure ClientHttpRequestFactory for production");
|
||||||
|
|
||||||
final char[] password = env
|
final char[] password = env
|
||||||
.getProperty("sebserver.gui.truststore.pwd")
|
.getProperty("sebserver.gui.truststore.pwd", "")
|
||||||
.toCharArray();
|
.toCharArray();
|
||||||
|
|
||||||
|
if (password.length < 3) {
|
||||||
|
log.error("Missing or incorrect trust-store password: " + String.valueOf(password));
|
||||||
|
throw new IllegalArgumentException("Missing or incorrect trust-store password");
|
||||||
|
}
|
||||||
|
|
||||||
|
final File trustStoreFile = ResourceUtils.getFile("classpath:truststore.jks");
|
||||||
|
|
||||||
final SSLContext sslContext = SSLContextBuilder
|
final SSLContext sslContext = SSLContextBuilder
|
||||||
.create()
|
.create()
|
||||||
.loadTrustMaterial(ResourceUtils.getFile(
|
.loadTrustMaterial(trustStoreFile, password)
|
||||||
"classpath:truststore.jks"),
|
|
||||||
password)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final HttpClient client = HttpClients.custom()
|
final HttpClient client = HttpClients.custom()
|
||||||
|
@ -158,4 +162,17 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter implements E
|
||||||
return new HttpComponentsClientHttpRequestFactory(client);
|
return new HttpComponentsClientHttpRequestFactory(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO set connection and read timeout!? configurable!?
|
||||||
|
private static class DevClientHttpRequestFactory extends SimpleClientHttpRequestFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void prepareConnection(
|
||||||
|
final HttpURLConnection connection,
|
||||||
|
final String httpMethod) throws IOException {
|
||||||
|
|
||||||
|
super.prepareConnection(connection, httpMethod);
|
||||||
|
connection.setInstanceFollowRedirects(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
package ch.ethz.seb.sebserver.gbl.model;
|
package ch.ethz.seb.sebserver.gbl.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
@ -15,7 +17,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||||
|
|
||||||
public class EntityKey {
|
public class EntityKey implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2368065921846821061L;
|
||||||
|
|
||||||
@JsonProperty(value = "modelId", required = true)
|
@JsonProperty(value = "modelId", required = true)
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class ExamineeAccountDetails {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUserName() {
|
||||||
return this.username;
|
return this.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class RAPConfiguration implements ApplicationConfiguration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(final Application application) {
|
public void configure(final Application application) {
|
||||||
|
try {
|
||||||
final Map<String, String> properties = new HashMap<>();
|
final Map<String, String> properties = new HashMap<>();
|
||||||
properties.put(WebClient.PAGE_TITLE, "SEB Server");
|
properties.put(WebClient.PAGE_TITLE, "SEB Server");
|
||||||
properties.put(WebClient.BODY_HTML, "<big>Loading Application<big>");
|
properties.put(WebClient.BODY_HTML, "<big>Loading Application<big>");
|
||||||
|
@ -43,9 +44,11 @@ public class RAPConfiguration implements ApplicationConfiguration {
|
||||||
|
|
||||||
application.addEntryPoint("/gui", RAPSpringEntryPointFactory, properties);
|
application.addEntryPoint("/gui", RAPSpringEntryPointFactory, properties);
|
||||||
|
|
||||||
try {
|
|
||||||
// TODO get file path from properties
|
// TODO get file path from properties
|
||||||
application.addStyleSheet(RWT.DEFAULT_THEME_ID, "static/css/sebserver.css");
|
application.addStyleSheet(RWT.DEFAULT_THEME_ID, "static/css/sebserver.css");
|
||||||
|
|
||||||
|
} catch (final RuntimeException re) {
|
||||||
|
throw re;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
log.error("Error during CSS parsing. Please check the custom CSS files for errors.", e);
|
log.error("Error during CSS parsing. Please check the custom CSS files for errors.", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,15 +32,7 @@ public class RAPSpringConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ServletContextInitializer initializer() {
|
public ServletContextInitializer initializer() {
|
||||||
return new ServletContextInitializer() {
|
return new RAPServletContextInitializer();
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartup(final ServletContext servletContext) throws ServletException {
|
|
||||||
servletContext.setInitParameter(
|
|
||||||
"org.eclipse.rap.applicationConfiguration",
|
|
||||||
RAPConfiguration.class.getName());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -56,4 +48,13 @@ public class RAPSpringConfig {
|
||||||
return new ServletRegistrationBean<>(new RWTServlet(), this.entrypoint + "/*");
|
return new ServletRegistrationBean<>(new RWTServlet(), this.entrypoint + "/*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class RAPServletContextInitializer implements ServletContextInitializer {
|
||||||
|
@Override
|
||||||
|
public void onStartup(final ServletContext servletContext) throws ServletException {
|
||||||
|
servletContext.setInitParameter(
|
||||||
|
"org.eclipse.rap.applicationConfiguration",
|
||||||
|
RAPConfiguration.class.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,8 +87,7 @@ public class InstitutionForm implements TemplateComposer {
|
||||||
final boolean isReadonly = pageContext.isReadonly();
|
final boolean isReadonly = pageContext.isReadonly();
|
||||||
|
|
||||||
// new PageContext with actual EntityKey
|
// new PageContext with actual EntityKey
|
||||||
final PageContext formContext = pageContext;
|
final PageContext formContext = pageContext.withEntityKey(institution.getEntityKey());
|
||||||
pageContext.withEntityKey(institution.getEntityKey());
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Institution Form for Institution {}", institution.name);
|
log.debug("Institution Form for Institution {}", institution.name);
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
package ch.ethz.seb.sebserver.gui.content;
|
package ch.ethz.seb.sebserver.gui.content;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.eclipse.rap.rwt.RWT;
|
import org.eclipse.rap.rwt.RWT;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.custom.SashForm;
|
import org.eclipse.swt.custom.SashForm;
|
||||||
|
@ -118,40 +120,22 @@ public class MainPage implements TemplateComposer {
|
||||||
contentObjectslayout.marginHeight = 0;
|
contentObjectslayout.marginHeight = 0;
|
||||||
contentObjectslayout.marginWidth = 0;
|
contentObjectslayout.marginWidth = 0;
|
||||||
contentObjects.setLayout(contentObjectslayout);
|
contentObjects.setLayout(contentObjectslayout);
|
||||||
contentObjects.setData(PageEventListener.LISTENER_ATTRIBUTE_KEY,
|
contentObjects.setData(
|
||||||
new ActionEventListener() {
|
PageEventListener.LISTENER_ATTRIBUTE_KEY,
|
||||||
@Override
|
new ContentActionEventListener(event -> pageContext.composerService().compose(
|
||||||
public int priority() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notify(final ActionEvent event) {
|
|
||||||
pageContext.composerService().compose(
|
|
||||||
event.action.definition.contentPaneComposer,
|
event.action.definition.contentPaneComposer,
|
||||||
event.action.pageContext().copyOf(contentObjects));
|
event.action.pageContext().copyOf(contentObjects)), 2));
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final Composite actionPane = new Composite(mainSash, SWT.NONE);
|
final Composite actionPane = new Composite(mainSash, SWT.NONE);
|
||||||
actionPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
actionPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||||
final GridLayout actionPaneGrid = new GridLayout();
|
final GridLayout actionPaneGrid = new GridLayout();
|
||||||
actionPane.setLayout(actionPaneGrid);
|
actionPane.setLayout(actionPaneGrid);
|
||||||
actionPane.setData(RWT.CUSTOM_VARIANT, "actionPane");
|
actionPane.setData(RWT.CUSTOM_VARIANT, "actionPane");
|
||||||
actionPane.setData(PageEventListener.LISTENER_ATTRIBUTE_KEY,
|
actionPane.setData(
|
||||||
new ActionEventListener() {
|
PageEventListener.LISTENER_ATTRIBUTE_KEY,
|
||||||
@Override
|
new ContentActionEventListener(event -> pageContext.composerService().compose(
|
||||||
public int priority() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notify(final ActionEvent event) {
|
|
||||||
pageContext.composerService().compose(
|
|
||||||
event.action.definition.actionPaneComposer,
|
event.action.definition.actionPaneComposer,
|
||||||
event.action.pageContext().copyOf(actionPane));
|
event.action.pageContext().copyOf(actionPane)), 1));
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
pageContext.composerService().compose(
|
pageContext.composerService().compose(
|
||||||
ActivitiesPane.class,
|
ActivitiesPane.class,
|
||||||
|
@ -160,4 +144,25 @@ public class MainPage implements TemplateComposer {
|
||||||
mainSash.setWeights(DEFAULT_SASH_WEIGHTS);
|
mainSash.setWeights(DEFAULT_SASH_WEIGHTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class ContentActionEventListener implements ActionEventListener {
|
||||||
|
|
||||||
|
private final int priority;
|
||||||
|
private final Consumer<ActionEvent> apply;
|
||||||
|
|
||||||
|
protected ContentActionEventListener(final Consumer<ActionEvent> apply, final int priority) {
|
||||||
|
this.apply = apply;
|
||||||
|
this.priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int priority() {
|
||||||
|
return this.priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notify(final ActionEvent event) {
|
||||||
|
this.apply.accept(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,8 +112,7 @@ public class UserAccountForm implements TemplateComposer {
|
||||||
.getOr(false);
|
.getOr(false);
|
||||||
|
|
||||||
// new PageContext with actual EntityKey
|
// new PageContext with actual EntityKey
|
||||||
final PageContext formContext = pageContext;
|
final PageContext formContext = pageContext.withEntityKey(userAccount.getEntityKey());
|
||||||
pageContext.withEntityKey(userAccount.getEntityKey());
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("UserAccount Form for user {}", userAccount.getName());
|
log.debug("UserAccount Form for user {}", userAccount.getName());
|
||||||
|
|
|
@ -120,24 +120,7 @@ public class ActivitiesPane implements TemplateComposer {
|
||||||
navigation.addListener(SWT.Selection, event -> handleSelection(pageContext, event));
|
navigation.addListener(SWT.Selection, event -> handleSelection(pageContext, event));
|
||||||
navigation.setData(
|
navigation.setData(
|
||||||
PageEventListener.LISTENER_ATTRIBUTE_KEY,
|
PageEventListener.LISTENER_ATTRIBUTE_KEY,
|
||||||
new ActionEventListener() {
|
new ActivitiesActionEventListener(navigation));
|
||||||
@Override
|
|
||||||
public void notify(final ActionEvent event) {
|
|
||||||
final MainPageState mainPageState = MainPageState.get();
|
|
||||||
mainPageState.action = event.action;
|
|
||||||
if (!event.activity) {
|
|
||||||
final EntityKey entityKey = event.action.getEntityKey();
|
|
||||||
final String modelId = (entityKey != null) ? entityKey.modelId : null;
|
|
||||||
final TreeItem item = findItemByActionDefinition(
|
|
||||||
navigation.getItems(),
|
|
||||||
event.action.definition,
|
|
||||||
modelId);
|
|
||||||
if (item != null) {
|
|
||||||
navigation.select(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// page-selection on (re)load
|
// page-selection on (re)load
|
||||||
final MainPageState mainPageState = MainPageState.get();
|
final MainPageState mainPageState = MainPageState.get();
|
||||||
|
@ -175,9 +158,12 @@ public class ActivitiesPane implements TemplateComposer {
|
||||||
|
|
||||||
for (final TreeItem item : items) {
|
for (final TreeItem item : items) {
|
||||||
final Action action = getActivitySelection(item);
|
final Action action = getActivitySelection(item);
|
||||||
|
if (action == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
final EntityKey entityKey = action.getEntityKey();
|
final EntityKey entityKey = action.getEntityKey();
|
||||||
if (action != null
|
if ((action.definition == actionDefinition || action.definition == actionDefinition.activityAlias) &&
|
||||||
&& (action.definition == actionDefinition || action.definition == actionDefinition.activityAlias) &&
|
|
||||||
(entityKey == null || (modelId != null && modelId.equals(entityKey.modelId)))) {
|
(entityKey == null || (modelId != null && modelId.equals(entityKey.modelId)))) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
@ -212,4 +198,29 @@ public class ActivitiesPane implements TemplateComposer {
|
||||||
item.setData(ATTR_ACTIVITY_SELECTION, action);
|
item.setData(ATTR_ACTIVITY_SELECTION, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final class ActivitiesActionEventListener implements ActionEventListener {
|
||||||
|
private final Tree navigation;
|
||||||
|
|
||||||
|
private ActivitiesActionEventListener(final Tree navigation) {
|
||||||
|
this.navigation = navigation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notify(final ActionEvent event) {
|
||||||
|
final MainPageState mainPageState = MainPageState.get();
|
||||||
|
mainPageState.action = event.action;
|
||||||
|
if (!event.activity) {
|
||||||
|
final EntityKey entityKey = event.action.getEntityKey();
|
||||||
|
final String modelId = (entityKey != null) ? entityKey.modelId : null;
|
||||||
|
final TreeItem item = findItemByActionDefinition(
|
||||||
|
this.navigation.getItems(),
|
||||||
|
event.action.definition,
|
||||||
|
modelId);
|
||||||
|
if (item != null) {
|
||||||
|
this.navigation.select(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,9 @@ public final class SelectionFieldBuilder extends FieldBuilder {
|
||||||
((Control) selection).setLayoutData(gridData);
|
((Control) selection).setLayoutData(gridData);
|
||||||
selection.select(this.value);
|
selection.select(this.value);
|
||||||
if (this.multi) {
|
if (this.multi) {
|
||||||
builder.form.putField(this.name, lab, (MultiSelection) selection);
|
builder.form.putField(this.name, lab, selection.<MultiSelection> getTypeInstance());
|
||||||
} else {
|
} else {
|
||||||
builder.form.putField(this.name, lab, (SingleSelection) selection);
|
builder.form.putField(this.name, lab, selection.<SingleSelection> getTypeInstance());
|
||||||
}
|
}
|
||||||
if (this.selectionListener != null) {
|
if (this.selectionListener != null) {
|
||||||
((Control) selection).addListener(SWT.Selection, e -> {
|
((Control) selection).addListener(SWT.Selection, e -> {
|
||||||
|
|
|
@ -15,52 +15,4 @@ public interface ActionEventListener extends PageEventListener<ActionEvent> {
|
||||||
return type == ActionEvent.class;
|
return type == ActionEvent.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static ActionEventListener of(final Consumer<ActionEvent> eventConsumer) {
|
|
||||||
// return new ActionEventListener() {
|
|
||||||
// @Override
|
|
||||||
// public void notify(final ActionEvent event) {
|
|
||||||
// eventConsumer.accept(event);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
// static ActionEventListener of(
|
|
||||||
// final Predicate<ActionEvent> predicate,
|
|
||||||
// final Consumer<ActionEvent> eventConsumer) {
|
|
||||||
//
|
|
||||||
// return new ActionEventListener() {
|
|
||||||
// @Override
|
|
||||||
// public void notify(final ActionEvent event) {
|
|
||||||
// if (predicate.test(event)) {
|
|
||||||
// eventConsumer.accept(event);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static ActionEventListener of(
|
|
||||||
// final ActionDefinition actionDefinition,
|
|
||||||
// final Consumer<ActionEvent> eventConsumer) {
|
|
||||||
//
|
|
||||||
// return new ActionEventListener() {
|
|
||||||
// @Override
|
|
||||||
// public void notify(final ActionEvent event) {
|
|
||||||
// if (event.actionDefinition == actionDefinition) {
|
|
||||||
// eventConsumer.accept(event);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static void injectListener(
|
|
||||||
// final Widget widget,
|
|
||||||
// final ActionDefinition actionDefinition,
|
|
||||||
// final Consumer<ActionEvent> eventConsumer) {
|
|
||||||
//
|
|
||||||
// widget.setData(
|
|
||||||
// PageEventListener.LISTENER_ATTRIBUTE_KEY,
|
|
||||||
// of(actionDefinition, eventConsumer));
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public final class MainPageState {
|
||||||
|
|
||||||
public static MainPageState get() {
|
public static MainPageState get() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final HttpSession httpSession = RWT
|
final HttpSession httpSession = RWT
|
||||||
.getUISession()
|
.getUISession()
|
||||||
.getHttpSession();
|
.getHttpSession();
|
||||||
|
@ -39,6 +40,9 @@ public final class MainPageState {
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainPageState;
|
return mainPageState;
|
||||||
|
|
||||||
|
} catch (final RuntimeException re) {
|
||||||
|
throw re;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
log.error("Unexpected error while trying to get MainPageState from user-session");
|
log.error("Unexpected error while trying to get MainPageState from user-session");
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,27 +138,6 @@ public class PageContextImpl implements PageContext {
|
||||||
attrs);
|
attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public PageContext withSelection(final ActivitySelection selection, final boolean clearAttributes) {
|
|
||||||
// if (selection == null) {
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// final Map<String, String> attrs = new HashMap<>();
|
|
||||||
// if (!clearAttributes) {
|
|
||||||
// attrs.putAll(this.attributes);
|
|
||||||
// }
|
|
||||||
// attrs.putAll(selection.getAttributes());
|
|
||||||
//
|
|
||||||
// return new PageContextImpl(
|
|
||||||
// this.restService,
|
|
||||||
// this.i18nSupport,
|
|
||||||
// this.composerService,
|
|
||||||
// this.root,
|
|
||||||
// this.parent,
|
|
||||||
// attrs);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAttribute(final String name) {
|
public String getAttribute(final String name) {
|
||||||
return this.attributes.get(name);
|
return this.attributes.get(name);
|
||||||
|
@ -268,7 +247,6 @@ public class PageContextImpl implements PageContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public void applyConfirmDialog(final LocTextKey confirmMessage, final Runnable onOK) {
|
public void applyConfirmDialog(final LocTextKey confirmMessage, final Runnable onOK) {
|
||||||
final Message messageBox = new Message(
|
final Message messageBox = new Message(
|
||||||
this.root.getShell(),
|
this.root.getShell(),
|
||||||
|
@ -276,29 +254,8 @@ public class PageContextImpl implements PageContext {
|
||||||
this.i18nSupport.getText(confirmMessage),
|
this.i18nSupport.getText(confirmMessage),
|
||||||
SWT.OK | SWT.CANCEL);
|
SWT.OK | SWT.CANCEL);
|
||||||
messageBox.setMarkupEnabled(true);
|
messageBox.setMarkupEnabled(true);
|
||||||
messageBox.open(new DialogCallback() {
|
messageBox.open(new ConfirmDialogCallback(onOK));
|
||||||
@Override
|
|
||||||
public void dialogClosed(final int returnCode) {
|
|
||||||
if (returnCode == SWT.OK) {
|
|
||||||
try {
|
|
||||||
onOK.run();
|
|
||||||
} catch (final Throwable t) {
|
|
||||||
log.error(
|
|
||||||
"Unexpected on confirm callback execution. This should not happen, plase secure the given onOK Runnable",
|
|
||||||
t);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// public void applyValidationErrorDialog(final Collection<FieldValidationError> validationErrors) {
|
|
||||||
// final Message messageBox = new Message(
|
|
||||||
// this.root.getShell(),
|
|
||||||
// this.i18nSupport.getText("org.sebserver.dialog.validationErrors.title"),
|
|
||||||
// this.i18nSupport.getText(confirmMessage),
|
|
||||||
// SWT.OK);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forwardToPage(
|
public void forwardToPage(
|
||||||
|
@ -391,6 +348,28 @@ public class PageContextImpl implements PageContext {
|
||||||
+ "]";
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final class ConfirmDialogCallback implements DialogCallback {
|
||||||
|
private static final long serialVersionUID = 1491270214433492441L;
|
||||||
|
private final Runnable onOK;
|
||||||
|
|
||||||
|
private ConfirmDialogCallback(final Runnable onOK) {
|
||||||
|
this.onOK = onOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dialogClosed(final int returnCode) {
|
||||||
|
if (returnCode == SWT.OK) {
|
||||||
|
try {
|
||||||
|
this.onOK.run();
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
log.error(
|
||||||
|
"Unexpected on confirm callback execution. This should not happen, plase secure the given onOK Runnable",
|
||||||
|
t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final class ListenerComparator implements Comparator<PageEventListener<?>> {
|
private static final class ListenerComparator implements Comparator<PageEventListener<?>> {
|
||||||
@Override
|
@Override
|
||||||
public int compare(final PageEventListener<?> o1, final PageEventListener<?> o2) {
|
public int compare(final PageEventListener<?> o1, final PageEventListener<?> o2) {
|
||||||
|
|
|
@ -91,6 +91,7 @@ public abstract class RestCall<T> {
|
||||||
|
|
||||||
final RestCallError restCallError =
|
final RestCallError restCallError =
|
||||||
new RestCallError("Response Entity: " + responseEntity.toString());
|
new RestCallError("Response Entity: " + responseEntity.toString());
|
||||||
|
|
||||||
restCallError.errors.addAll(RestCall.this.jsonMapper.readValue(
|
restCallError.errors.addAll(RestCall.this.jsonMapper.readValue(
|
||||||
responseEntity.getBody(),
|
responseEntity.getBody(),
|
||||||
new TypeReference<List<APIMessage>>() {
|
new TypeReference<List<APIMessage>>() {
|
||||||
|
@ -106,14 +107,25 @@ public abstract class RestCall<T> {
|
||||||
} catch (final Throwable t) {
|
} catch (final Throwable t) {
|
||||||
final RestCallError restCallError = new RestCallError("Unexpected error while rest call", t);
|
final RestCallError restCallError = new RestCallError("Unexpected error while rest call", t);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final String responseBody = ((RestClientResponseException) t).getResponseBodyAsString();
|
final String responseBody = ((RestClientResponseException) t).getResponseBodyAsString();
|
||||||
|
|
||||||
restCallError.errors.addAll(RestCall.this.jsonMapper.readValue(
|
restCallError.errors.addAll(RestCall.this.jsonMapper.readValue(
|
||||||
responseBody,
|
responseBody,
|
||||||
new TypeReference<List<APIMessage>>() {
|
new TypeReference<List<APIMessage>>() {
|
||||||
}));
|
}));
|
||||||
} catch (final Exception e) {
|
|
||||||
log.error("Unexpected error-response while webservice API call for: {}", builder, e);
|
} catch (final ClassCastException cce) {
|
||||||
|
log.error("Unexpected error-response while webservice API call for: {}", builder, cce);
|
||||||
log.error("Unexpected error-response cause: ", t);
|
log.error("Unexpected error-response cause: ", t);
|
||||||
|
restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(cce));
|
||||||
|
} catch (final RuntimeException re) {
|
||||||
|
log.error("Unexpected runtime error while webservice API call for: {}", builder, re);
|
||||||
|
log.error("Unexpected runtime error cause: ", t);
|
||||||
|
restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(re));
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log.error("Unexpected error while webservice API call for: {}", builder, e);
|
||||||
|
log.error("Unexpected error cause: ", t);
|
||||||
restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(e));
|
restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,14 +170,7 @@ public class OAuth2AuthorizationContextHolder implements AuthorizationContextHol
|
||||||
|
|
||||||
this.restTemplate = new DisposableOAuth2RestTemplate(this.resource);
|
this.restTemplate = new DisposableOAuth2RestTemplate(this.resource);
|
||||||
this.restTemplate.setRequestFactory(clientHttpRequestFactory);
|
this.restTemplate.setRequestFactory(clientHttpRequestFactory);
|
||||||
this.restTemplate.setErrorHandler(new OAuth2ErrorHandler(this.resource) {
|
this.restTemplate.setErrorHandler(new ErrorHandler(this.resource));
|
||||||
@Override
|
|
||||||
public boolean hasError(final ClientHttpResponse response) throws IOException {
|
|
||||||
final HttpStatus statusCode = HttpStatus.resolve(response.getRawStatusCode());
|
|
||||||
return (statusCode != null && statusCode.series() == HttpStatus.Series.SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
this.revokeTokenURI = webserviceURIService.getOAuthRevokeTokenURI();
|
this.revokeTokenURI = webserviceURIService.getOAuthRevokeTokenURI();
|
||||||
this.currentUserURI = webserviceURIService.getCurrentUserRequestURI();
|
this.currentUserURI = webserviceURIService.getCurrentUserRequestURI();
|
||||||
|
@ -297,5 +290,17 @@ public class OAuth2AuthorizationContextHolder implements AuthorizationContextHol
|
||||||
.contains(role.name());
|
.contains(role.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final class ErrorHandler extends OAuth2ErrorHandler {
|
||||||
|
private ErrorHandler(final OAuth2ProtectedResourceDetails resource) {
|
||||||
|
super(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasError(final ClientHttpResponse response) throws IOException {
|
||||||
|
final HttpStatus statusCode = HttpStatus.resolve(response.getRawStatusCode());
|
||||||
|
return (statusCode != null && statusCode.series() == HttpStatus.Series.SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,9 @@ import ch.ethz.seb.sebserver.gui.widget.WidgetFactory;
|
||||||
|
|
||||||
public class TableNavigator {
|
public class TableNavigator {
|
||||||
|
|
||||||
|
private final static int PAGE_NAV_SIZE = 3;
|
||||||
|
|
||||||
private final Composite composite;
|
private final Composite composite;
|
||||||
private final int pageNavSize = 3;
|
|
||||||
private final EntityTable<?> entityTable;
|
private final EntityTable<?> entityTable;
|
||||||
|
|
||||||
TableNavigator(final EntityTable<?> entityTable) {
|
TableNavigator(final EntityTable<?> entityTable) {
|
||||||
|
@ -56,7 +57,7 @@ public class TableNavigator {
|
||||||
createRewardLabel(pageNumber, numNav);
|
createRewardLabel(pageNumber, numNav);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = pageNumber - this.pageNavSize; i < pageNumber + this.pageNavSize; i++) {
|
for (int i = pageNumber - PAGE_NAV_SIZE; i < pageNumber + PAGE_NAV_SIZE; i++) {
|
||||||
if (i >= 1 && i <= numberOfPages) {
|
if (i >= 1 && i <= numberOfPages) {
|
||||||
createPageNumberLabel(i, i != pageNumber, numNav);
|
createPageNumberLabel(i, i != pageNumber, numNav);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ImageUpload extends Composite {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(ImageUpload.class);
|
private static final Logger log = LoggerFactory.getLogger(ImageUpload.class);
|
||||||
|
|
||||||
private final ServerPushService serverPushService;
|
private transient final ServerPushService serverPushService;
|
||||||
|
|
||||||
private final Composite imageCanvas;
|
private final Composite imageCanvas;
|
||||||
private final FileUpload fileUpload;
|
private final FileUpload fileUpload;
|
||||||
|
@ -136,8 +136,10 @@ public class ImageUpload extends Composite {
|
||||||
private static final void wait(final ServerPushContext context) {
|
private static final void wait(final ServerPushContext context) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
} catch (final Exception e) {
|
} catch (final InterruptedException e) {
|
||||||
|
log.info("InterruptedException while wait for image uplaod. Just ignore it");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void update(final ServerPushContext context) {
|
private static final void update(final ServerPushContext context) {
|
||||||
|
@ -145,6 +147,7 @@ public class ImageUpload extends Composite {
|
||||||
if (imageUpload.imageBase64 != null
|
if (imageUpload.imageBase64 != null
|
||||||
&& imageUpload.loadNewImage
|
&& imageUpload.loadNewImage
|
||||||
&& imageUpload.imageLoaded) {
|
&& imageUpload.imageLoaded) {
|
||||||
|
|
||||||
final Base64InputStream input = new Base64InputStream(
|
final Base64InputStream input = new Base64InputStream(
|
||||||
new ByteArrayInputStream(
|
new ByteArrayInputStream(
|
||||||
imageUpload.imageBase64.getBytes(StandardCharsets.UTF_8)),
|
imageUpload.imageBase64.getBytes(StandardCharsets.UTF_8)),
|
||||||
|
|
|
@ -133,4 +133,10 @@ public class MultiSelection extends Composite implements Selection {
|
||||||
deselectAll();
|
deselectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public MultiSelection getTypeInstance() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,6 @@ public interface Selection {
|
||||||
|
|
||||||
void setVisible(boolean visible);
|
void setVisible(boolean visible);
|
||||||
|
|
||||||
|
<T extends Selection> T getTypeInstance();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,4 +72,10 @@ public class SingleSelection extends Combo implements Selection {
|
||||||
super.setItems(this.valueMapping.toArray(new String[this.valueMapping.size()]));
|
super.setItems(this.valueMapping.toArray(new String[this.valueMapping.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public SingleSelection getTypeInstance() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,6 +255,12 @@ public class PaginationService {
|
||||||
examTableMap.put(
|
examTableMap.put(
|
||||||
Domain.EXAM.ATTR_STATUS,
|
Domain.EXAM.ATTR_STATUS,
|
||||||
ExamRecordDynamicSqlSupport.status.name());
|
ExamRecordDynamicSqlSupport.status.name());
|
||||||
|
this.sortColumnMapping.put(
|
||||||
|
ExamRecordDynamicSqlSupport.examRecord.name(),
|
||||||
|
examTableMap);
|
||||||
|
this.defaultSortColumn.put(
|
||||||
|
ExamRecordDynamicSqlSupport.examRecord.name(),
|
||||||
|
Domain.EXAM.ATTR_ID);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ public class PermissionDeniedException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 5333137812363042580L;
|
private static final long serialVersionUID = 5333137812363042580L;
|
||||||
|
|
||||||
public final EntityType entityType;
|
public final EntityType entityType;
|
||||||
public final GrantEntity entity;
|
public final PrivilegeType privilegeType;
|
||||||
public final PrivilegeType grantType;
|
|
||||||
public final String userId;
|
public final String userId;
|
||||||
|
|
||||||
public PermissionDeniedException(
|
public PermissionDeniedException(
|
||||||
|
@ -27,8 +26,7 @@ public class PermissionDeniedException extends RuntimeException {
|
||||||
|
|
||||||
super("No grant: " + grantType + " on type: " + entityType + " for user: " + userId);
|
super("No grant: " + grantType + " on type: " + entityType + " for user: " + userId);
|
||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
this.entity = null;
|
this.privilegeType = grantType;
|
||||||
this.grantType = grantType;
|
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +41,7 @@ public class PermissionDeniedException extends RuntimeException {
|
||||||
" entity owner: " + entity.getOwnerId() +
|
" entity owner: " + entity.getOwnerId() +
|
||||||
" for user: " + userId);
|
" for user: " + userId);
|
||||||
this.entityType = entity.entityType();
|
this.entityType = entity.entityType();
|
||||||
this.entity = entity;
|
this.privilegeType = grantType;
|
||||||
this.grantType = grantType;
|
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,22 +156,14 @@ public class BulkActionService {
|
||||||
this.supporter.get(EntityType.INDICATOR),
|
this.supporter.get(EntityType.INDICATOR),
|
||||||
this.supporter.get(EntityType.CLIENT_CONNECTION),
|
this.supporter.get(EntityType.CLIENT_CONNECTION),
|
||||||
this.supporter.get(EntityType.CONFIGURATION_NODE));
|
this.supporter.get(EntityType.CONFIGURATION_NODE));
|
||||||
case LMS_SETUP:
|
|
||||||
return Arrays.asList(
|
|
||||||
this.supporter.get(EntityType.EXAM),
|
|
||||||
this.supporter.get(EntityType.INDICATOR),
|
|
||||||
this.supporter.get(EntityType.CLIENT_CONNECTION));
|
|
||||||
case USER:
|
case USER:
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
this.supporter.get(EntityType.EXAM),
|
this.supporter.get(EntityType.EXAM),
|
||||||
this.supporter.get(EntityType.INDICATOR),
|
this.supporter.get(EntityType.INDICATOR),
|
||||||
this.supporter.get(EntityType.CLIENT_CONNECTION),
|
this.supporter.get(EntityType.CLIENT_CONNECTION),
|
||||||
this.supporter.get(EntityType.CONFIGURATION_NODE));
|
this.supporter.get(EntityType.CONFIGURATION_NODE));
|
||||||
|
case LMS_SETUP:
|
||||||
case EXAM:
|
case EXAM:
|
||||||
return Arrays.asList(
|
|
||||||
this.supporter.get(EntityType.EXAM),
|
|
||||||
this.supporter.get(EntityType.INDICATOR),
|
|
||||||
this.supporter.get(EntityType.CLIENT_CONNECTION));
|
|
||||||
case CONFIGURATION:
|
case CONFIGURATION:
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
this.supporter.get(EntityType.EXAM),
|
this.supporter.get(EntityType.EXAM),
|
||||||
|
|
Loading…
Reference in a new issue