微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在客户端站点上使用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 ClassfigClasses() {
        return new Class[] {ApplicationConfig.class};
    }

    @Override
    protected ClassfigClasses() {
        return new Class[] {WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] {"/"};
    }
}

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

    Maphttpentityhttpentityhttpentityfig.getJsessionid());
        return new httpentity

我希望你能帮助我.

编辑:

好的我发现问题不在于JSESSIONID没有正确发送.但我的登录不正确,我的查询数据库获取用户.

正确的登录帖子

ClientHttpResponse response = restTemplate.execute(
            "http://localhost:8080/messenger-webapp/login",new RequestCallback() {

                @Override
                public void doWithRequest(ClientHttpRequest request) throws IOException {
                    request.getBody().write(("username=" + user + "&password=" + pw).getBytes());
                }
            },new ResponseExtractor

正确的查询

String authQuery = "select u.userid,r.role_name from user u,role r,user_role a where u.dbid = a.user_id and r.dbid = a.role_id and u.userid = ?";

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原理介绍,具有一定借鉴价值,需要的朋友可以参考下。下面就和我一起来看看吧。传统事务中回滚点的使...
今天小编给大家分享的是一文解析spring中事务的传播机制,相信很多人都不太了解,为了让大家更加了解,所以给大家总结了以下内容,一起往下看吧。一定会有所收获...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区别,具有一定借鉴价值,需要的朋友可以参考下。下面就和我一起来看看吧。Spring Cloud Netfli...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。第一步:整合pom文件,在S...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。List 坑列表 = new ArrayList(2);...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓存的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇...
本篇内容主要讲解“Spring中的@Autowired和@Resource注解怎么使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学...
今天小编给大家分享一下SpringSecurity怎么定义多个过滤器链的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家
这篇文章主要介绍“Spring的@Conditional注解怎么使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Spring的@Con...
这篇文章主要介绍了SpringCloudGateway的熔断限流怎么配置的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇SpringCloud&nb...