具有spring security和Neo4j的用户身份验证

问题描述 投票:1回答:1

我有一个sprig引导应用程序和neo4J数据库。我的application.properties文件如下所示:

spring.data.neo4j.uri = http://127.0.0.1:7474
spring.data.neo4j.username = neo4j
spring.data.neo4j.password = neo4jpass

该应用程序具有基本用户:

@NodeEntity
public class User {

  @GraphId
  private Long id;

  @Property (name="username")
  private String username;

  @Property (name="password")
  private String password;

  @Property (name="name")
  private String name;

  @Property (name="role")
  private String role;
}

一个简单的用户存储库:

public interface UserRepository extends GraphRepository<User>{
}

我当前的spring安全配置是:

@Configuration
@EnableWebSecurity
public class SpringSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .antMatchers("/","/index").permitAll()
            .anyRequest().authenticated()
        .and()
            .authorizeRequests()
            .antMatchers("/css/**”)
            .permitAll()
        .and()
            .authorizeRequests()
            .antMatchers("/resources/**")
            .permitAll();

        http
            .formLogin()
            .loginPage("/login")
            .defaultSuccessUrl("/home")
            .permitAll()
        .and()
            .logout()
            .permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }


    @Override
    public void configure(final WebSecurity web) throws Exception {
        web.ignoring()
                .antMatchers("/vendors/**", "/local/**");
    }

使用内存身份验证登录后,我可以创建,读取和删除用户。我要做的是替换内存中的身份验证,并针对数据库中的现有用户进行身份验证。我在这里有什么选择?

spring-boot spring-security neo4j graph-databases spring-data-neo4j-4
1个回答
0
投票

您在这里有一些选择,这取决于您希望应用程序具有多大的专业性和安全性。

  1. 您可以简单地将实际数据库信息放在您的application.properties上,而不是要在本地加载的本地/内存中,因此,每次加载应用程序时,您都将指向该数据库。
  2. 如果您要讨论的是在许多环境(开发,生产,等等)中部署应用程序,则应在部署时刻将这些配置外部化并作为环境变量加载(您可以通过多种方法来实现,这取决于您将托管您的主机)。应用)。使用这种情况,您将执行@Afridi在评论中所说的:在部署时刻将DataSource bean创建为load the environment variables设置
  3. 您可以使用external configuration files,因此在运行生成的.jar文件的那一刻,您只需传递额外的参数即可为您的环境使用不同的配置

请确保还有很多其他选项可以执行相同的操作,但是这些都是您可以使用的。希望我在问题问了很多时间后都对您有所帮助。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.