Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lh-lilahamel committed Nov 22, 2024
1 parent 54b401b commit bf598be
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 114 deletions.
44 changes: 35 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
<version>3.2.10</version>
<relativePath/>
</parent>

Expand All @@ -26,9 +26,9 @@
<jdk.version>11</jdk.version>

<atoti-server.version>6.1.2-SNAPSHOT</atoti-server.version>
<atoti-ui.version>5.1.13</atoti-ui.version>
<atoti-ui.version>5.2.0-beta</atoti-ui.version>

<tomcat.version>9.0.31</tomcat.version>
<tomcat.version>10.1.30</tomcat.version>

<spring.boot.mainclass>com.activeviam.mac.app.MacSpringBootApp</spring.boot.mainclass>

Expand All @@ -51,6 +51,11 @@
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
<version>3.2.10</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -94,6 +99,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.4.10.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
Expand All @@ -102,6 +108,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>6.4.10.Final</version>
</dependency>

<!-- Atoti UI dependency -->
Expand Down Expand Up @@ -169,11 +176,6 @@
<artifactId>guava</artifactId>
<version>32.1.3-jre</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.atoti</groupId>
<artifactId>directquery-bigquery</artifactId>
<version>${atoti-server.version}</version>
</dependency>
<dependency>
<groupId>com.activeviam.source</groupId>
Expand All @@ -188,7 +190,31 @@
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.2.0</version>
<version>${jakarta-persistence.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jakarta-ws-rs.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/activeviam/mac/app/MacSpringBootApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import com.activeviam.mac.cfg.impl.MacServerConfig;
import com.activeviam.tech.core.api.registry.Registry;
import javax.servlet.MultipartConfigElement;
import jakarta.servlet.MultipartConfigElement;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ protected void registerRedirections(final ResourceRegistry registry) {

protected void registerExtensions(final ResourceRegistry registry) {
registry.serve("/ui/extensions*.json").addResourceLocations("classpath:/static/activeui/");
registry
.serve("/ui/extensions/text-editor-extension/**/*.js")
.addResourceLocations("classpath:/static/activeui/extensions/text-editor-extension/");
// registry
// .serve("/ui/extensions/text-editor-extension/**/*.js")
// .addResourceLocations("classpath:/static/activeui/extensions/text-editor-extension/");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.activeviam.tools.bookmark.constant.impl.ContentServerConstants.Paths;
import com.activeviam.tools.bookmark.constant.impl.ContentServerConstants.Role;
import com.activeviam.tools.bookmark.impl.BookmarkTool;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
Expand All @@ -37,6 +38,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
* Spring configuration of the Content Service.
Expand Down Expand Up @@ -82,11 +85,13 @@ public class ContentServiceConfig implements IActivePivotContentServiceConfig {
* @return the Hibernate's configuration
*/
private static SessionFactory loadConfiguration(final Properties hibernateProperties)
throws HibernateException {
throws HibernateException, IOException {
hibernateProperties.put(
AvailableSettings.DATASOURCE, createTomcatJdbcDataSource(hibernateProperties));
final Resource entityMappingFile = new ClassPathResource("content-service-hibernate.xml");
return new org.hibernate.cfg.Configuration()
.addProperties(hibernateProperties)
.addInputStream(entityMappingFile.getInputStream())
.buildSessionFactory();
}

Expand Down Expand Up @@ -141,7 +146,7 @@ public IContentService contentService() {
try {
sessionFactory = loadConfiguration(contentServiceHibernateProperties());
return new HibernateContentService(sessionFactory);
} catch (HibernateException e) {
} catch (HibernateException | IOException e) {
throw new BeanInitializationException("Failed to initialize the Content Service", e);
}
}
Expand Down
54 changes: 0 additions & 54 deletions src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@

package com.activeviam.mac.cfg.impl;

import com.activeviam.activepivot.server.impl.private_.observability.DynamicActivePivotManagerMBean;
import com.activeviam.activepivot.server.impl.private_.observability.memory.MemoryAnalysisService;
import com.activeviam.activepivot.server.spring.api.config.IActivePivotConfig;
import com.activeviam.activepivot.server.spring.api.config.IActivePivotContentServiceConfig;
import com.activeviam.activepivot.server.spring.api.config.IDatastoreConfig;
import com.activeviam.activepivot.server.spring.private_.config.impl.ActivePivotServicesConfig;
import com.activeviam.activepivot.server.spring.private_.config.impl.ActiveViamRestServicesConfig;
import com.activeviam.activepivot.server.spring.private_.config.impl.ActiveViamWebSocketServicesConfig;
import com.activeviam.activepivot.server.spring.private_.pivot.content.impl.DynamicActivePivotContentServiceMBean;
import com.activeviam.mac.cfg.security.impl.SecurityConfig;
import com.activeviam.mac.cfg.security.impl.UserConfig;
import com.activeviam.tech.core.api.agent.AgentException;
import com.activeviam.web.spring.internal.JMXEnabler;
import com.activeviam.web.spring.internal.config.JwtConfig;
import com.activeviam.web.spring.internal.config.JwtRestServiceConfig;
import java.nio.file.Paths;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -134,28 +130,6 @@ public JMXEnabler jmxMonitoringConnectorEnabler() {
return new JMXEnabler("StatisticSource", this.sourceConfig);
}

/**
* Enable JMX Monitoring for the Datastore.
*
* @return the {@link JMXEnabler} attached to the datastore
*/
@Bean
public JMXEnabler jmxDatastoreEnabler() {
return new JMXEnabler(this.datastoreConfig.database());
}

/**
* Enable JMX Monitoring for ActivePivot Components.
*
* @return the {@link JMXEnabler} attached to the activePivotManager
*/
@Bean
public JMXEnabler jmxActivePivotEnabler() {
startManager();

return new JMXEnabler(new DynamicActivePivotManagerMBean(apConfig.activePivotManager()));
}

/**
* [Bean] JMX Bean to export bookmarks.
*
Expand All @@ -165,32 +139,4 @@ public JMXEnabler jmxActivePivotEnabler() {
public JMXEnabler jmxBookmarkEnabler() {
return new JMXEnabler("Bookmark", this.contentServiceConfig);
}

/**
* Enable JMX Monitoring for the ContentService.
*
* @return the {@link JMXEnabler} attached to the Content Service
*/
@Bean
public JMXEnabler jmxActivePivotContentServiceEnabler() {
// to allow operations from the JMX bean
return new JMXEnabler(
new DynamicActivePivotContentServiceMBean(
this.apContentServiceConfig.activePivotContentService(),
this.apConfig.activePivotManager()));
}

/**
* Enable Memory JMX Monitoring.
*
* @return the {@link JMXEnabler} attached to the memory analysis service.
*/
@Bean
public JMXEnabler jmxMemoryMonitoringServiceEnabler() {
return new JMXEnabler(
new MemoryAnalysisService(
this.datastoreConfig.database(),
this.apConfig.activePivotManager(),
Paths.get(System.getProperty("java.io.tmpdir"))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.activeviam.activepivot.server.spring.private_.pivot.security.impl.UserDetailsServiceWrapper;
import com.activeviam.tech.contentserver.storage.api.IContentService;
import com.activeviam.tech.core.api.security.IUserDetailsService;
import com.activeviam.web.spring.api.config.ICorsConfig;
import com.activeviam.web.spring.api.config.IJwtConfig;
import com.activeviam.web.spring.api.jwt.JwtAuthenticationProvider;
import com.activeviam.web.spring.internal.config.JwtRestServiceConfig;
Expand All @@ -21,11 +20,17 @@
import org.springframework.core.env.Environment;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
Expand All @@ -36,11 +41,9 @@
import org.springframework.security.web.authentication.switchuser.SwitchUserFilter;
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
import org.springframework.security.web.firewall.StrictHttpFirewall;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

/** Authentication Bean Name. */
Expand Down Expand Up @@ -81,8 +84,8 @@ public class SecurityConfig {
/** {@code true} to enable the logout URL. */
protected final WebConfiguration webConfiguration;

public SecurityConfig(final String cookieName) {
this.webConfiguration = new WebConfiguration(cookieName);
public SecurityConfig() {
this.webConfiguration = new WebConfiguration(COOKIE_NAME);
}

/**
Expand Down Expand Up @@ -118,6 +121,38 @@ public AuthenticationEntryPoint basicAuthenticationEntryPoint() {
return new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED);
}

/**
* Configures the authentication of the whole application.
*
* <p>This binds the defined user service to the authentication and sets the source for JWT
* tokens.
*
* @param inMemoryAuthenticationProvider the in-memory authentication provider
* @param jwtAuthenticationProvider is a provider which can perform authentication from the
* jwtService's tokens. Implementation from the {@link IJwtConfig} .
* @return the authentication manager
*/
@Bean
public AuthenticationManager authenticationManager(
final JwtAuthenticationProvider jwtAuthenticationProvider,
final AuthenticationProvider inMemoryAuthenticationProvider) {
final ProviderManager providerManager =
new ProviderManager(inMemoryAuthenticationProvider, jwtAuthenticationProvider);
providerManager.setEraseCredentialsAfterAuthentication(false);

return providerManager;
}

@Bean
public AuthenticationProvider inMemoryAuthenticationProvider(
final UserDetailsService userDetailsService, final PasswordEncoder passwordEncoder) {
final var authenticationProvider = new DaoAuthenticationProvider();
authenticationProvider.setPasswordEncoder(passwordEncoder);
authenticationProvider.setUserDetailsService(userDetailsService);

return authenticationProvider;
}

/**
* Configures the authentication of the whole application.
*
Expand All @@ -136,28 +171,6 @@ public void configureGlobal(
.authenticationProvider(jwtAuthenticationProvider);
}

/**
* [Bean] Spring standard way of configuring CORS.
*
* <p>This simply forwards the configuration of {@link ICorsConfig} to Spring security system.
*
* @return the configuration for the application.
*/
@Bean
public CorsConfigurationSource corsConfigurationSource(final ICorsConfig corsConfig) {
final CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(corsConfig.getAllowedOrigins());
configuration.setAllowedHeaders(corsConfig.getAllowedHeaders());
configuration.setExposedHeaders(corsConfig.getExposedHeaders());
configuration.setAllowedMethods(corsConfig.getAllowedMethods());
configuration.setAllowCredentials(true);

final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);

return source;
}

/**
* Returns the spring security bean user details service wrapper.
*
Expand Down Expand Up @@ -280,15 +293,21 @@ public SecurityFilterChain activePivotSecurity(
.permitAll()
.anyRequest()
.hasAnyAuthority(ROLE_USER))
// One has to be a user for all the other URLs
.securityMatcher("/**")
.authorizeHttpRequests(auth -> auth.anyRequest().hasAnyAuthority(ROLE_USER))
.httpBasic(Customizer.withDefaults())
// SwitchUserFilter is the last filter in the chain. See FilterComparator class.
.addFilterAfter(contextValueFilter, SwitchUserFilter.class);
return http.build();
}

// One has to be a user for all the other URLs
@Bean
@Order(5)
public SecurityFilterChain otherSecurity(final HttpSecurity http) throws Exception {
http.securityMatcher("/**")
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.httpBasic(Customizer.withDefaults());
return http.build();
}

public void configureWebSecurity(
HttpSecurity http, JwtFilter jwtFilter, WebConfiguration webConfig) throws Exception {
http
Expand Down
Loading

0 comments on commit bf598be

Please sign in to comment.