@Bean
  public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    Config config = new Config();
    config.setInstanceName("soesmses");
    config.getNetworkConfig().setPort(5701);
    config.getNetworkConfig().setPortAutoIncrement(true);

    // In development, remove multicast auto-configuration
    if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
      System.setProperty("hazelcast.local.localAddress", "127.0.0.1");

      config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
      config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
      config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
    }

    config.getMapConfigs().put("default", initializeDefaultMapConfig());
    config
        .getMapConfigs()
        .put("com.soesoft.soesmses.domain.*", initializeDomainMapConfig(jHipsterProperties));
    config
        .getMapConfigs()
        .put("clustered-http-sessions", initializeClusteredSession(jHipsterProperties));

    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config);

    return hazelcastInstance;
  }
  @Bean
  public SpringLiquibase liquibase(
      DataSource dataSource,
      DataSourceProperties dataSourceProperties,
      LiquibaseProperties liquibaseProperties) {

    // Use liquibase.integration.spring.SpringLiquibase if you don't want Liquibase to start
    // asynchronously
    SpringLiquibase liquibase = new AsyncSpringLiquibase();
    liquibase.setDataSource(dataSource);
    liquibase.setChangeLog("classpath:config/liquibase/master.xml");
    liquibase.setContexts(liquibaseProperties.getContexts());
    liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema());
    liquibase.setDropFirst(liquibaseProperties.isDropFirst());
    liquibase.setShouldRun(liquibaseProperties.isEnabled());
    if (env.acceptsProfiles(Constants.SPRING_PROFILE_FAST)) {
      if ("org.h2.jdbcx.JdbcDataSource".equals(dataSourceProperties.getDriverClassName())) {
        liquibase.setShouldRun(true);
        log.warn(
            "Using '{}' profile with H2 database in memory is not optimal, you should consider switching to"
                + " MySQL or Postgresql to avoid rebuilding your database upon each start.",
            Constants.SPRING_PROFILE_FAST);
      } else {
        liquibase.setShouldRun(false);
      }
    } else {
      log.debug("Configuring Liquibase");
    }
    return liquibase;
  }
Esempio n. 3
0
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    log.info(
        "Web application configuration, using profiles: {}",
        Arrays.toString(env.getActiveProfiles()));
    EnumSet<DispatcherType> disps =
        EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);

    if (env.acceptsProfiles(Constants.SPRING_PROFILE_PRODUCTION)) {
      initCachingHttpHeadersFilter(servletContext, disps);
    }
    if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
      // add dev config here
    }
    log.info("Web application fully configured");
  }
 @Override
 public void registerStompEndpoints(StompEndpointRegistry registry) {
   StompWebSocketEndpointRegistration reg = registry.addEndpoint("/api/ws/notificacoes");
   if (env.acceptsProfiles(Profiles.DESENVOLVIMENTO)) {
     reg.setAllowedOrigins("*");
   }
   reg.withSockJS();
 }
 @PostConstruct
 public void settingEnv() {
   if (env.acceptsProfiles("prod")) {
     orcidApiType = OrcidApiType.LIVE;
   } else {
     orcidApiType = OrcidApiType.SANDBOX;
   }
 }
Esempio n. 6
0
 @Bean(name = "messageSource")
 public MessageSource messageSource() {
   ReloadableResourceBundleMessageSource messageSource =
       new ReloadableResourceBundleMessageSource();
   messageSource.setBasename("classpath:/messages/message");
   messageSource.setDefaultEncoding("UTF-8");
   if (environment.acceptsProfiles("dev")) {
     messageSource.setCacheSeconds(0);
   }
   return messageSource;
 }
 private void setLocationForStaticAssets(ConfigurableEmbeddedServletContainer container) {
   File root;
   String prefixPath = resolvePathPrefix();
   if (env.acceptsProfiles(Constants.SPRING_PROFILE_PRODUCTION)) {
     root = new File(prefixPath + "target/www/");
   } else {
     root = new File(prefixPath + "src/main/webapp/");
   }
   if (root.exists() && root.isDirectory()) {
     container.setDocumentRoot(root);
   }
 }
Esempio n. 8
0
 @Override
 protected void configure(HttpSecurity http) throws Exception {
   CsrfConfigurer<HttpSecurity> configurer =
       http.exceptionHandling()
           .accessDeniedPage("/session-expired")
           .defaultAuthenticationEntryPointFor(
               (request, response, ex) ->
                   response.sendError(HttpServletResponse.SC_UNAUTHORIZED),
               new RequestHeaderRequestMatcher("X-Requested-With", "XMLHttpRequest"))
           .and()
           .headers()
           .cacheControl()
           .disable()
           .csrf();
   if (environment.acceptsProfiles(Initializer.PROFILE_DEBUG_CSP)) {
     Pattern whiteList = Pattern.compile("^(GET|HEAD|TRACE|OPTIONS)$");
     configurer.requireCsrfProtectionMatcher(
         new NegatedRequestMatcher(
             (r) ->
                 whiteList.matcher(r.getMethod()).matches()
                     || r.getRequestURI().equals("/report-csp-violation")));
   }
   configurer
       .csrfTokenRepository(getCsrfTokenRepository())
       .and()
       .authorizeRequests()
       .antMatchers(ADMIN_API + "/configuration/organizations/**")
       .hasAnyRole(ADMIN, OWNER)
       .antMatchers(
           ADMIN_API + "/organizations/new",
           ADMIN_API + "/users/**",
           ADMIN_API + "/configuration/**")
       .hasRole(ADMIN)
       .antMatchers(ADMIN_API + "/check-in/**")
       .hasAnyRole(ADMIN, OWNER, OPERATOR)
       .antMatchers(HttpMethod.GET, ADMIN_API + "/**")
       .hasAnyRole(ADMIN, OWNER, OPERATOR)
       .antMatchers(ADMIN_API + "/**")
       .hasAnyRole(ADMIN, OWNER)
       .antMatchers("/admin/**/export/**")
       .hasAnyRole(ADMIN, OWNER)
       .antMatchers("/admin/**")
       .hasAnyRole(ADMIN, OWNER, OPERATOR)
       .antMatchers("/**")
       .permitAll()
       .and()
       .formLogin()
       .loginPage("/authentication")
       .loginProcessingUrl("/authentication")
       .failureUrl("/authentication?failed");
 }
Esempio n. 9
0
 private static String createI18nScript(Environment environment, Locale locale) {
   String i18nScript;
   if (environment.acceptsProfiles("development")) {
     i18nScript = "<script src=\"i18n.js\"></script>";
   } else {
     i18nScript =
         "<script src=\"i18n-"
             + locale
             + "_"
             + environment.getProperty("application.version")
             + ".js\"></script>";
   }
   return i18nScript;
 }
 @AfterThrowing(pointcut = "loggingPointcut()", throwing = "e")
 public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
   if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
     log.error(
         "Exception in {}.{}() with cause = {}",
         joinPoint.getSignature().getDeclaringTypeName(),
         joinPoint.getSignature().getName(),
         e.getCause(),
         e);
   } else {
     log.error(
         "Exception in {}.{}() with cause = {}",
         joinPoint.getSignature().getDeclaringTypeName(),
         joinPoint.getSignature().getName(),
         e.getCause());
   }
 }
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        // NOTE: If you add other static resources to src/main/resources, they must be
        // listed here to avoid security checks
        .antMatchers("/docs/**")
        .permitAll()
        .anyRequest()
        .authenticated()
        .and()
        .httpBasic()
        .and()
        .csrf()
        .disable();

    if (env.acceptsProfiles("ssl")) {
      http.requiresChannel().anyRequest().requiresSecure();
    }
  }
 @Override
 public void afterPropertiesSet() throws LiquibaseException {
   if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
     taskExecutor.execute(
         new Runnable() {
           @Override
           public void run() {
             try {
               log.warn(
                   "Starting Liquibase asynchronously, your database might not be ready at startup!");
               initDb();
             } catch (LiquibaseException e) {
               e.printStackTrace();
             }
           }
         });
   } else {
     log.debug("Starting Liquibase synchronously");
     initDb();
   }
 }
 @Override
 public void afterPropertiesSet() throws LiquibaseException {
   if (env.acceptsProfiles(
       Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_HEROKU)) {
     taskExecutor.execute(
         () -> {
           try {
             log.warn(
                 "Starting Liquibase asynchronously, your database might not be ready at startup!");
             initDb();
           } catch (LiquibaseException e) {
             log.error(
                 "Liquibase could not start correctly, your database is NOT ready: {}",
                 e.getMessage(),
                 e);
           }
         });
   } else {
     log.debug("Starting Liquibase synchronously");
     initDb();
   }
 }
Esempio n. 14
0
 @Bean
 public SpringLiquibase liquibase(DataSource dataSource) {
   SpringLiquibase liquibase = new SpringLiquibase();
   liquibase.setDataSource(dataSource);
   liquibase.setChangeLog("classpath:config/liquibase/master.xml");
   liquibase.setContexts(liquiBasePropertyResolver.getProperty("context"));
   if (env.acceptsProfiles(Constants.SPRING_PROFILE_FAST)) {
     if ("org.h2.jdbcx.JdbcDataSource"
         .equals(dataSourcePropertyResolver.getProperty("dataSourceClassName"))) {
       liquibase.setShouldRun(true);
       log.warn(
           "Using '{}' profile with H2 database in memory is not optimal, you should consider switching to"
               + " MySQL or Postgresql to avoid rebuilding your database upon each start.",
           Constants.SPRING_PROFILE_FAST);
     } else {
       liquibase.setShouldRun(false);
     }
   } else {
     log.debug("Configuring Liquibase");
   }
   return liquibase;
 }