Commit 9e0d84c6 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

#3 Improved error messages

parent 271a2230
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -41,8 +41,8 @@ export default {
  mounted: function() {
  mounted: function() {
    var self = this;
    var self = this;
    document.addEventListener('apiError', function(event) {
    document.addEventListener('apiError', function(event) {
      self.$bvToast.toast(event.message, {
      self.$bvToast.toast(event.message.body, {
        title: "Error",
        title: event.message.title,
        variant: 'danger',
        variant: 'danger',
        solid: true
        solid: true
      });
      });
+4 −8
Original line number Original line Diff line number Diff line
@@ -26,15 +26,11 @@ function apiRequest(url, options, showLoading = true) {
}
}


function dispatchApiErrorEvent(error) {
function dispatchApiErrorEvent(error) {
  let message;
  if (error.message) {
    message = error.message;
  } else {
    message = 'Generic error';
  }

  let event = new CustomEvent('apiError');
  let event = new CustomEvent('apiError');
  event.message = message;
  event.message = {
    title: error.error || 'Error',
    body: error.message || 'Unknown error'
  };
  document.dispatchEvent(event);
  document.dispatchEvent(event);
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -5,7 +5,7 @@
    <parent>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <version>2.2.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    </parent>
    <groupId>it.inaf.ia2</groupId>
    <groupId>it.inaf.ia2</groupId>
+10 −2
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.provider.token.store.jwk.JwkTokenStore;
import org.springframework.security.oauth2.provider.token.store.jwk.JwkTokenStore;
import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.filter.CorsFilter;
@@ -45,14 +47,20 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    @Override
    public void configure(HttpSecurity http) throws Exception {
    public void configure(HttpSecurity http) throws Exception {


        super.configure(http);

        // CORS are necessary only for development (API access from npm server)
        // CORS are necessary only for development (API access from npm server)
        if (Arrays.asList(env.getActiveProfiles()).contains("dev")) {
        if (Arrays.asList(env.getActiveProfiles()).contains("dev")) {
            http.authorizeRequests()
            http.authorizeRequests()
                    .antMatchers(HttpMethod.OPTIONS, "/**").permitAll();
                    .antMatchers(HttpMethod.OPTIONS, "/**").permitAll();
        }
        }


        super.configure(http);

        // avoid displaying the annoying BasicAuth browser popup when the
        // session expires (this should happen mostly during development)
        // [401 WWW-Authenticate is converted to 403]
        http.exceptionHandling().defaultAuthenticationEntryPointFor(
                new Http403ForbiddenEntryPoint(), new AntPathRequestMatcher("/keepAlive"));

        http.csrf().disable();
        http.csrf().disable();
    }
    }


+1 −2
Original line number Original line Diff line number Diff line
@@ -34,7 +34,7 @@ public class HomePageController {
    private InvitedRegistrationManager invitedRegistrationManager;
    private InvitedRegistrationManager invitedRegistrationManager;


    @ResponseBody
    @ResponseBody
    @GetMapping(value = "/home", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "/home", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<HomePageResponse> getMainPage(@Valid GroupsRequest request) {
    public ResponseEntity<HomePageResponse> getMainPage(@Valid GroupsRequest request) {


        HomePageResponse response = new HomePageResponse();
        HomePageResponse response = new HomePageResponse();
@@ -56,7 +56,6 @@ public class HomePageController {
        if (optReg.isPresent()) {
        if (optReg.isPresent()) {
            request.setAttribute("invited-registration", optReg.get());
            request.setAttribute("invited-registration", optReg.get());
            return "/registration-completed";
            return "/registration-completed";
            //request.getRequestDispatcher("/registration-completed").forward(request, response);
        }
        }


        return "index.html";
        return "index.html";
Loading