This is the error message you are giving;
I'mhavingahardtimemakingmyFrontEndAPIhavepermissiontoaccessmyBack-EndAPIwhichisaSpringBootproject,I'msuremyproblemisnotmyFron-EndAPI,theproblemisintheconfigurationoftheCORSregardingaccesspermission.
I'llleavemyCORSconfigurationrightbelow
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import br.com.mdw.config.MdwApiProperty;
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CorsFilter implements Filter {
@Autowired
private MdwApiProperty mdwApiProperty;
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
response.setHeader("Access-Control-Allow-Origin", mdwApiProperty.getOriginPermitida());
response.setHeader("Access-Control-Allow-Credentials", "true");
if ("OPTIONS".equals(request.getMethod()) && mdwApiProperty.getOriginPermitida().equals(request.getHeader("Origin"))) {
response.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, PUT, OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type, Accept");
response.setHeader("Access-Control-Max-Age", "3600");
response.setStatus(HttpServletResponse.SC_OK);
} else {
chain.doFilter(req, resp);
}
}
@Override
public void destroy() {
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
And here where I set up access:
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("mdw")
public class MdwApiProperty {
private String originPermitida = "http://localhost:8000";
private final Seguranca seguranca = new Seguranca();
public Seguranca getSeguranca() {
return seguranca;
}
public String getOriginPermitida() {
return originPermitida;
}
public void setOriginPermitida(String originPermitida) {
this.originPermitida = originPermitida;
}
public static class Seguranca {
private boolean enableHttps;
public boolean isEnableHttps() {
return enableHttps;
}
public void setEnableHttps(boolean enableHttps) {
this.enableHttps = enableHttps;
}
}
}
A class called MdwApiProperty
Where the following annotation was placed:
@ConfigurationProperties("mdw")
And because of this annotation, that's why the application-prod.properties file accepted this line of code.
mdw.seguranca.enable-https=true
If this is true if I happen to modify the MdwApiProperty class annotation for
@ConfigurationProperties("habilitando-producao")
Iria looks like this in the application-prod.properties file.
habilitando-producao.seguranca.enable-https=true
And in these files where the nickname for project access is enabled
package br.com.mdw;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import br.com.mdw.config.MdwApiProperty;
@SpringBootApplication
@EnableConfigurationProperties(MdwApiProperty.class)
public class MdwApplication {
public static void main(String[] args) {
SpringApplication.run(MdwApplication.class, args);
}
}
This is where the annotation is
mdw.seguranca.enable-https=true
spring.datasource.url={JDBC_DATABASE_URL}
spring.datasource.username={JDBC_DATABASE_USERNAME}
spring.datasource.password={JDBC_DATABASE_PASSWORD}
mdw.origin-permitida=https://mdw-arm-wladimir.herokuapp.com
For some reason he is not accepting access, I need help.