我有一个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/**");
}
使用内存身份验证登录后,我可以创建,读取和删除用户。我要做的是替换内存中的身份验证,并针对数据库中的现有用户进行身份验证。我在这里有什么选择?
您在这里有一些选择,这取决于您希望应用程序具有多大的专业性和安全性。
application.properties
上,而不是要在本地加载的本地/内存中,因此,每次加载应用程序时,您都将指向该数据库。DataSource
bean创建为load the environment variables设置.jar
文件的那一刻,您只需传递额外的参数即可为您的环境使用不同的配置请确保还有很多其他选项可以执行相同的操作,但是这些都是您可以使用的。希望我在问题问了很多时间后都对您有所帮助。