Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Security 4.2.2-使用密码解密代理密钥_Java_Spring_Encryption_Spring Security - Fatal编程技术网

Java Spring Security 4.2.2-使用密码解密代理密钥

Java Spring Security 4.2.2-使用密码解密代理密钥,java,spring,encryption,spring-security,Java,Spring,Encryption,Spring Security,祝贺你!长期读者,第一次投稿 我正在进行一个个人项目,该项目将允许登录用户向自己或家庭成员存储加密的笔记。经过大量研究,我决定实现一种代理密钥方法,即在创建帐户时为每个用户分配一个代理密钥 此代理密钥已加密并存储在数据库中。。。并在登录时使用用户密码进行解密。然后,生成的清除代理密钥将用于其配置文件中的所有加密活动 我的问题是,根据本教程,在使用Spring Security的实现时,在登录期间捕获用户的密码: 我的SecurityConfig类如下所示: /* * (non-Jav

祝贺你!长期读者,第一次投稿

我正在进行一个个人项目,该项目将允许登录用户向自己或家庭成员存储加密的笔记。经过大量研究,我决定实现一种代理密钥方法,即在创建帐户时为每个用户分配一个代理密钥

此代理密钥已加密并存储在数据库中。。。并在登录时使用用户密码进行解密。然后,生成的清除代理密钥将用于其配置文件中的所有加密活动

我的问题是,根据本教程,在使用Spring Security的实现时,在登录期间捕获用户的密码:

我的SecurityConfig类如下所示:

    /*
 * (non-Javadoc)
 * 
 * @see org.springframework.security.config.annotation.web.configuration.
 * WebSecurityConfigurerAdapter#configure(org.springframework.security.
 * config.annotation.web.builders.HttpSecurity)
 */
@Override
protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/login").permitAll()
            .antMatchers("/registration").permitAll().antMatchers("/accountverification/**").permitAll()
            .antMatchers("/secure/**").hasAuthority("MEMBER").anyRequest().authenticated().and().formLogin()
            .loginPage("/login").failureUrl("/login?error=true").defaultSuccessUrl("/secure/notes")
            .usernameParameter("email").passwordParameter("password").and().logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/").and()
            .exceptionHandling().accessDeniedPage("/access-denied");
}
我的login.html页面如下(重要部分):


如果我理解正确,login.html页面将发布到/login,这是在我的SecurityConfig类(上面)中定义的。登录本身工作得很好

但是,这会自动绕过流中解密代理密钥的部分。因此,我首先尝试向一个单独的控制器发帖,然后将该请求转发到/login。没有骰子

然后我尝试扩展,但发现此时的密码始终为空。这让我想到了这篇文章:

。。。但这让我觉得是哈奇

所以,最后,我仍然想知道,在登录屏幕发布期间,我如何获取密码,以便临时用于解密用户的代理密钥。。。然后当解密完成并登录完成时。。。摧毁它


感谢您的帮助

我知道这会发生。。。只要我在StackOverflow上发布一些有趣的问题,我就会想出来

我不确定这是不是最优雅的解决方案,但它确实有效。我当然愿意接受其他选择

我已将此方法添加到我的登录控制器:

/**
 * @return
 */
@RequestMapping(value = { "/loginProcessor" }, method = RequestMethod.POST)
public String loginProcessor(@ModelAttribute Login login) {
    System.out.println("PASSWORD: " + login.getPassword());
    return "forward:/login";
}
然后我将login.html调整为post to,而不是to/login:

<form th:action="@{/loginProcessor}" method="POST" class="form-signin">
Et,瞧!打印密码后,我登录并重定向到我的个人资料页面。有更好的办法吗

<form th:action="@{/loginProcessor}" method="POST" class="form-signin">
/*
 * (non-Javadoc)
 * 
 * @see org.springframework.security.config.annotation.web.configuration.
 * WebSecurityConfigurerAdapter#configure(org.springframework.security.
 * config.annotation.web.builders.HttpSecurity)
 */
@Override
protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/loginProcessor").permitAll()
            .antMatchers("/login").permitAll().antMatchers("/registration").permitAll()
            .antMatchers("/accountverification/**").permitAll().antMatchers("/secure/**").hasAuthority("MEMBER")
            .anyRequest().authenticated().and().formLogin().loginPage("/login").failureUrl("/login?error=true")
            .defaultSuccessUrl("/secure/notes").usernameParameter("email").passwordParameter("password").and()
            .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/").and()
            .exceptionHandling().accessDeniedPage("/access-denied");
}