Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
Spring security 405 with disabled csrf

I have a project in which I've implemented spring security. Whenever I try to use the login page, I get a 405 response 'Request method 'POST' not supported'. I've searched for a solution over the web, and as far as i saw the only solution is to disable csrf. I've disabled csrf, but i still receiving the same 405 response.

SecurityConfig.java

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{

@Autowired
private BCryptPasswordEncoder encoder;
@Autowired
private DataSource dataSource;

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {

  auth.jdbcAuthentication().dataSource(dataSource())
    .usersByUsernameQuery(
        "select username, password, enabled from user where username=?")
    .authoritiesByUsernameQuery(
        "select user_username, role from user_roles where user_username=?").passwordEncoder(encoder);
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
    .authorizeRequests()
        .antMatchers("/resources/**").permitAll()
        .anyRequest().authenticated()
        .and()
    .formLogin()
        .loginPage("/login.html").usernameParameter("username").passwordParameter("password")
        .loginProcessingUrl("/mylogin")
        .successForwardUrl("/test.html")
        .permitAll()
        .and()
        .csrf().disable();
}}

login.html

    <form action="/mylogin" method="post" name="login" id="login">

<div>
    <span>username</span>
    <input type="text"  placeholder="Username" name="username">
</div>
<br/>
<div>
    <span >password</span>
    <input type="password"  placeholder="Password" name="password">
</div>
<br/>       
<div>
    <input type="submit" value="send">
</div>

Am i missing something?

MySystemApplication

@SpringBootApplication
@EntityScan("com.myapp")
@EnableJpaRepositories("com.myapp")
@ComponentScan({"com.myapp"})
public class MySystemApplication {


public static void main(String[] args) {
    SpringApplication.run(MySystemApplication.class, args);
}


}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Please I must advise you enable your csrf. Never you disable it except you want to try out something on development environment. Remember to enable it immediately after testing whatever else your site will be prone to cross site request forgery attack.

So enable csrf and add

<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>

to your form in login.jsp

OR

Preferably, always use spring tag

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="f"%>

for your form

<f:form></f:form>

so you won't have to worry about remembering to add that csrf token tag to your forms as spring will do that automatically by default. That's the best practice.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda