Skip to content

Commit

Permalink
Refactor security a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
OPeyrusse committed Dec 5, 2024
1 parent e86ed5a commit 5365931
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 163 deletions.
72 changes: 28 additions & 44 deletions src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.activeviam.activepivot.server.spring.api.config.IActivePivotContentServiceConfig;
import com.activeviam.activepivot.server.spring.api.config.IDatastoreConfig;
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;
Expand All @@ -28,71 +27,56 @@
* Spring configuration of the ActivePivot Sandbox application.
*
* <p>We use {@link PropertySource} annotation(s) to define some .properties file(s), whose content
* will be loaded into the Spring {@link Environment}, allowing some externally-driven configuration of the
* application. Parameters can be quickly changed by modifying the {@code sandbox.properties} file.
* will be loaded into the Spring {@link Environment}, allowing some externally-driven configuration
* of the application. Parameters can be quickly changed by modifying the {@code sandbox.properties}
* file.
*
* <p>We use {@link Import} annotation(s) to reference additional Spring {@link Configuration}
* classes, so that we can manage the application configuration in a modular way (split by domain/feature, re-use
* of core config, override of core config, customized config, etc...).
* classes, so that we can manage the application configuration in a modular way (split by
* domain/feature, re-use of core config, override of core config, customized config, etc...).
*
* <p>Spring best practices recommends not to have arguments in bean methods if possible. One should
* rather autowire the appropriate spring configurations (and not beans directly unless necessary), and use the
* beans from there.
* rather autowire the appropriate spring configurations (and not beans directly unless necessary),
* and use the beans from there.
*
* @author ActiveViam
*/
@Configuration
@Import(
value = {
JwtConfig.class,
ManagerDescriptionConfig.class,
JwtConfig.class,
ManagerDescriptionConfig.class,

// Pivot
ActivePivotWithDatastoreConfig.class,
// Pivot
ActivePivotWithDatastoreConfig.class,

// Content server
ContentServiceConfig.class,
// Content server
ContentServiceConfig.class,

// Specific to monitoring server
SecurityConfig.class,
UserConfig.class,
SourceConfig.class,
// Specific to monitoring server
SecurityConfig.class,
SourceConfig.class,
})
public class MacServerConfig {

/**
* Datastore spring configuration.
*/
@Autowired
protected IDatastoreConfig datastoreConfig;
/** Datastore spring configuration. */
@Autowired protected IDatastoreConfig datastoreConfig;

/**
* ActivePivot spring configuration.
*/
@Autowired
protected IActivePivotConfig apConfig;
/** ActivePivot spring configuration. */
@Autowired protected IActivePivotConfig apConfig;

/**
* ActivePivot content service spring configuration.
*/
@Autowired
protected IActivePivotContentServiceConfig apContentServiceConfig;
/** ActivePivot content service spring configuration. */
@Autowired protected IActivePivotContentServiceConfig apContentServiceConfig;

/**
* Content Service configuration.
*/
@Autowired
protected ContentServiceConfig contentServiceConfig;
/** Content Service configuration. */
@Autowired protected ContentServiceConfig contentServiceConfig;

/**
* Spring configuration of the source files of the Memory Analysis Cube application.
*/
@Autowired
protected SourceConfig sourceConfig;
/** Spring configuration of the source files of the Memory Analysis Cube application. */
@Autowired protected SourceConfig sourceConfig;

/**
* Initialize and start the ActivePivot Manager, after performing all the injections into the ActivePivot
* plug-ins.
* Initialize and start the ActivePivot Manager, after performing all the injections into the
* ActivePivot plug-ins.
*
* @return void
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.activeviam.mac.cfg.security.impl;

import com.activeviam.tech.contentserver.storage.api.IContentService;
import com.activeviam.web.spring.api.config.IJwtConfig;
import com.activeviam.web.spring.api.jwt.JwtAuthenticationProvider;
import lombok.RequiredArgsConstructor;
Expand All @@ -12,11 +13,14 @@
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.User.UserBuilder;
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;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
import org.springframework.security.web.firewall.StrictHttpFirewall;
Expand All @@ -35,6 +39,24 @@ public class SecurityConfig {
/** Name of the Cookies of the MAC application. */
public static final String COOKIE_NAME = "MEMORY_ANALYSIS_CUBE";

/**
* [Bean] Create the users that can access the application.
*
* @return {@link UserDetailsService user data}
*/
@Bean
public UserDetailsService userDetailsService(final PasswordEncoder passwordEncoder) {
final UserBuilder builder = User.builder().passwordEncoder(passwordEncoder::encode);
final InMemoryUserDetailsManager service = new InMemoryUserDetailsManager();
service.createUser(
builder
.username("admin")
.password("admin")
.authorities(ROLE_USER, ROLE_ADMIN, IContentService.ROLE_ROOT)
.build());
return service;
}

/**
* As of Spring Security 5.0, the way the passwords are encoded must be specified. When logging,
* the input password will be encoded and compared with the stored encoded password. To determine
Expand Down
53 changes: 0 additions & 53 deletions src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java

This file was deleted.

This file was deleted.

0 comments on commit 5365931

Please sign in to comment.