Java 在spring项目中列出一个ip白名单

Java 在spring项目中列出一个ip白名单,java,spring,spring-security,whitelist,Java,Spring,Spring Security,Whitelist,我有一个带有登录的简单java应用程序。它有一个扩展WebSecurityConfigureAdapter的SecurityConfig类。我在那里实现了两种方法 void configure(WebSecurity web) void configure(HttpSecurity http) 在configure(websecurityweb)方法中,我忽略了某些URL的身份验证 public void configure(WebSecurity web) throws Exception

我有一个带有登录的简单java应用程序。它有一个扩展WebSecurityConfigureAdapter的SecurityConfig类。我在那里实现了两种方法

void configure(WebSecurity web)
void configure(HttpSecurity http)
在configure(websecurityweb)方法中,我忽略了某些URL的身份验证

public void configure(WebSecurity web) throws Exception {
    web
    .ignoring()
            .antMatchers(HttpMethod.POST, "/examplePattern");
}
我在这个项目中有一些服务端点,现在我需要列出一个特定的ip(我有一个字符串数组),它应该只能访问一个特定的端点。这是因为对端点的所有调用都要经过用户登录身份验证

基本上,我需要的是,如果从特定IP调用某个端点,那么请求应该到达控制器,而无需进行身份验证

我对这个领域很陌生,所以如果你有这个问题的解决方案,请让我知道


提前感谢

您需要基于IP地址的身份验证提供商,如下所示:

@Service 
public class IPAddressBasedAuthenticationProvider implements AuthenticationProvider {


     @Autowired
     private HttpServletRequest request;

     @Override
     public Authentication authenticate(Authentication authentication) throws AuthenticationException {

         String ipAddress = request.getRemoteAddr();
         // Check against your array.
         //return created authentication object (if user provided valid credentials)
    }
}

我希望这有帮助

我正在寻找一种方法,如果ipaddress匹配,我不应该进行身份验证,但该请求应该通过。通过什么?请求应该在没有身份验证的情况下到达控制器。基本上,我需要的是,如果从特定IP调用某个端点,那么请求应该到达控制器,而无需进行身份验证。如果您只是在JSP中调用控制器映射,它将到达。我仍然不明白你想要什么,也许其他用户可以提供帮助。所有对控制器的调用都将通过安全机制,我们将验证用户是否已登录。我想要的是,如果它来自一个特定的IP试图到达一个特定的端点,而不检查身份验证。