前端请求后台错误码

401:表示没有权限,后台SecurityConfig中设置了,将.permitAll() //权限允许所有人放开,.authenticated()注释掉就可以了

package com.jsptpd.zhywserver.config.security;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint;
import org.springframework.context.annotation.Bean;
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;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;

/**
 * Created by LOG on 2017/3/6.
 */
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {


    //PermissionEvaluator


    //DAOAuthenticationProvide userDetailsService
    @Autowired
    private SpringUserDetailsService userDetailsService;


    //密码加密对象
    @Bean
    public PasswordEncoder passwordEncoder() {
//        return NoOpPasswordEncoder.getInstance();
        return new StandardPasswordEncoder();
    }


    @Autowired
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
                //.authenticationProvider(new SpringAuthenticationProvider())
                //.eraseCredentials(false)
                .userDetailsService(userDetailsService)
                //对password进行加密
                .passwordEncoder(passwordEncoder());
    }

    @Bean
    public Http401AuthenticationEntryPoint securityException401EntryPoint() {

        return new Http401AuthenticationEntryPoint("");
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .exceptionHandling().authenticationEntryPoint(securityException401EntryPoint())
                .and()
                .csrf()
                .disable()
                .headers()
                .frameOptions()
                .sameOrigin()
                .and()
                .authorizeRequests()
                .antMatchers("/user/loginByPwd").permitAll()
                .antMatchers("/user/loginByToken").permitAll()
                .antMatchers("/user/messageCode").permitAll()
                .antMatchers("/user/forgetPwd").permitAll()
                .antMatchers("/sell/ticketInfo").permitAll()
                .anyRequest()
//                .authenticated()
                .permitAll()  //权限允许所有人
                .and()
//                .formLogin().permitAll()
//                .and()
                .logout().addLogoutHandler(new SecurityContextLogoutHandler())
                //.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler()); //restful登出
                //.loginPage("/login").failureUrl("/login-error");
                .and()
                .sessionManagement()
//                .invalidSessionUrl("/login")
                .maximumSessions(5)


        ;


    }
}

405:安卓端post请求,后台是get

你可能感兴趣的:(前端请求后台错误码)