嗨,我对弹簧靴和弹簧安全性非常新。我有两个在不同服务器上运行的休息Web服务相互通信。我想确保使用http basic auth保护两者之间的api调用。我在网上找到的大多数安全演示/示例都涉及用于身份验证的登录页面。有没有办法通过弹出的身份验证登录页面来执行此操作。任何指针都非常感谢。感谢。
答案 0 :(得分:0)
如果我正确理解您的问题,一个应用程序希望代表用户与另一个应用程序进行交互。
您需要第一个应用程序将身份验证令牌发送到第二个应用程序。
如果您正在使用Spring-Security,请检查CAS解决方案。这是一个与Spring Security开箱即用的SSO实现。您可能对代理票据工作流程感兴趣。 您可以在Spring Security for CAS页面找到其他详细信息。
我能想到的另一个解决方案是OAth。Here you can find some more details
决定取决于您的架构。
答案 1 :(得分:0)
这是我的代码如下。即使输入的用户名和密码错误,它仍然允许请求通过
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
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.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN");
}
}