加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 如何通过spring 4 resttemplate发送收到的jsessionid

发布时间:2020-12-15 01:29:08 所属栏目:大数据 来源:网络整理
导读:我正在客户端站点上使用JavaFX和Spring4编写信使,在服务器站点上编写Spring4.我用spring-security 3.2保护了服务器.现在我的问题:我在客户端上有一个登录页面,将登录信息发送到spring-security并接收JSESSIONID cookie.这工作正常,但当我尝试用我的请求发送

我正在客户端站点上使用JavaFX和Spring4编写信使,在服务器站点上编写Spring4.我用spring-security 3.2保护了服务器.现在我的问题:我在客户端上有一个登录页面,将登录信息发送到spring-security并接收JSESSIONID cookie.这工作正常,但当我尝试用我的请求发送JSESSIONID时,我变成了一个

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class org.messenger.rest.JSONConversationResult] and content type [text/html;charset=UTF-8]

服务器Inizializer

public class SpringMvcInitializer extends
    AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class

Server SecurityInizializer

public class SpringSecurityInitializer extends
    AbstractSecurityWebApplicationInitializer {
}

Server SecurityConfig

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private DriverManagerDataSource dataSource;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        String authQuery = "select userid,authority from user where userid = ?";
        String userQuery = "select userid,pw,enabled from user where userid = ?";

        auth.jdbcAuthentication().dataSource(dataSource)
            .passwordEncoder(passwordEncoder())
            .usersByUsernameQuery(userQuery)
            .authoritiesByUsernameQuery(authQuery);

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {


        http
            .authorizeRequests()
                .antMatchers("/register").permitAll()
                .antMatchers("/getconvs","/getcontacts").hasRole("USER")
                .and()
            .formLogin()
                .and()
            .csrf().disable();
    }

    @Bean
    public AuthenticationEntryPoint authenticationEntryPoint() {
        return new de.daschner.messenger.security.AuthenticationEntryPoint();
    }

    @Bean
    public SuccessHandler successHandler() {
        return new SuccessHandler();
    }

    @Bean
    public SimpleUrlAuthenticationFailureHandler failureHandler() {
        return new SimpleUrlAuthenticationFailureHandler();
    }

    @Bean
    public AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder(11);
    }
}

安全“页面”的服务器请求映射

@RequestMapping(value="/getconvs",method={RequestMethod.GET},produces={MediaType.APPLICATION_JSON_VALUE})
public @ResponseBody JSONConversationResult getConvsList(HttpServletRequest request,@RequestParam(value="uid") String uid){
    JSONConversationResult ret = new JSONConversationResult();
    Map

客户端发送登录并获取Cookie

    Map

我希望这会有助于其他人.如果有人有其他选择,请告诉我.

最佳答案
好的我发现问题不在于JSESSIONID没有正确发送.但我的登录不正确,请告诉我.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读