私はこの問題に悩まされています...私はSpringブートアプリケーションをS2S通信と併用しています。私は@RestController
POST要求を受け入れる必要がありますメソッドがあります。スプリングブート - POSTメソッドが許可されていません
これは私がリクエストが有効になっているCSFRフィルターによってブロックされたことがわかった私は405エラーを取得し、このリンクをヒットした場合、前記第一の時点で
を許可されていないコントローラ
@RestController
public class PaymentRestController {
@PostMapping("/util/paymentResponse")
public void savePaymentResponse(@RequestParam boolean transaction_status, @RequestParam String usedToken,
@RequestParam String transaction_message, @RequestParam String authCode,
@RequestParam String transactionCode, @RequestParam String orderId, HttpServletRequest request) {
//business logic
}
}
ですWebアプリケーション上で、私はこのように
@Configuration
@ComponentScan("it.besmart")
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Autowired
@Qualifier("customUserDetailsService")
UserDetailsService userDetailsService;
@Autowired
CustomSuccessHandler customSuccessHandler;
@Autowired
CustomAuthenticationFailureHandler customAuthenticationFailureHandler;
@Autowired
DataSource dataSource;
private final static Logger logger = LoggerFactory.getLogger(SecurityConfiguration.class);
@Autowired
public void configureGlobalService(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public SwitchUserFilter switchUserFilter() {
SwitchUserFilter filter = new SwitchUserFilter();
filter.setUserDetailsService(userDetailsService);
filter.setSuccessHandler(customSuccessHandler);
filter.setFailureHandler(customAuthenticationFailureHandler);
return filter;
}
protected void configure(HttpSecurity http) throws Exception {
logger.debug("Webapp security configured");
http
.authorizeRequests()
.antMatchers("/", "/home", "/contacts", "/faq", "/privacy", "/register", "/registrationConfirm", "/util/**", "/resendRegistrationToken","/park**", "/oauth/authorize", "/error")
.permitAll()
.antMatchers("/profile**", "/edit**","/payment**", "/plate**","/notification**", "/addPaymentMethod**", "/logout/impersonate**")
.access("hasRole('USER') or hasRole('NOPAYMENT')")
.antMatchers("/book**", "/manage**")
.access("hasRole('USER')")
.antMatchers("/admin**", "/login/impersonate**").access("hasRole('ADMIN')")
.antMatchers("/updatePassword").hasAuthority("CHANGE_PASSWORD_PRIVILEGE")
.and().formLogin().loginPage("/?login=login").loginProcessingUrl("/") .successHandler(customSuccessHandler).failureHandler(customAuthenticationFailureHandler).usernameParameter("email").passwordParameter("password").and().rememberMe().rememberMeParameter("remember-me").tokenRepository(persistentTokenRepository()).tokenValiditySeconds(86400).and().exceptionHandling().accessDeniedPage("/accessDenied")
.and().csrf().ignoringAntMatchers("/util**")
.and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/?logout=true").permitAll()
.and().addFilterAfter(switchUserFilter(), FilterSecurityInterceptor.class);
}
このように私のセキュリティを設定している私はCSRFトークン例外を取得し、それでも405エラーを取得していませんよ。 これはPOSTの問題でもないので、私はGETにリクエストとマッピングを変更すると、まだ405エラーが発生します...そして、POSTを送信しようとすると、ヘッダ応答にAllowedメソッドがPOST 、私はGETでそれを送信する場合、私は問題は、パラメータの一つがnullだったということでした
セキュリティに関連する問題を除外するには、application.propertiesにmanagement.security.enabled = falseプロパティを追加して、そのように機能するかどうかを試してみてください。 – marco
何も変更されていません...問題はまだそこにあります... – besmart
セキュリティ上の問題はありません...どのようにPOSTリクエストしますか?また、すべてのRequestParamにrequired = falseを追加し、アプリケーションをデバッグし、コントローラの最初の行にブレークポイントを設定してみてください。 – marco