小编fl4*_*l4l的帖子

Spring安全性和JSON身份验证

我在spring/spring-mvc中有一个完全使用JSON通信的应用程序.现在我需要通过JSON使用spring security 3(使用LdapAuthenticationProvider)对我的应用程序进行身份验证.

默认的spring seurity提交表单需要这样的POST:

POST /myapp/j_spring_security_check HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
Host: 127.0.0.1:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

j_username=myUsername&j_password=myPass
Run Code Online (Sandbox Code Playgroud)

但我想传递一个像这样的JSON对象:

{"j_username":"myUsername","j_password":"myPass"}
Run Code Online (Sandbox Code Playgroud)

我看了很多帖子喜欢这样,这样其他的这一个没有运气,在所有的Ajax的情况下完成一个POST像上面.

有任何想法吗?

spring json spring-mvc spring-security

29
推荐指数
5
解决办法
4万
查看次数

Hibernate Native SQL 查询在连接中检索多个实体

参考这个相关线程的答案,ehrhardt 发布的技巧效果很好。

但是,如果我必须加入多个实体,我该怎么办?例如:

List<Person> peopleWithBooks = session.createSQLQuery(
    "select {p.*}, {b.*}, {m.*} from person p, book b, magazine m where <complicated join>")
        .addEntity("p", Person.class)
        .addJoin("b", "p.books")
        .addJoin("m", "p.magazines")
        .addEntity("p", Person.class)
        .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
        .list();
Run Code Online (Sandbox Code Playgroud)

Hibernate 聚合第一个连接,但不聚合第二个(杂志实体未分组)。

有什么技巧或者有限制只能加入一个相关实体吗?如果我必须加入具有子实体的实体?(我的目标是仅使用一个自定义查询来检索所有选定的数据)

java hibernate native-sql

5
推荐指数
0
解决办法
2390
查看次数

避免在"for"语句中出现空指针异常

在我的代码NullPointerException中,当a List为null 时,我通常使用这种方法来避免s in语句:

if (myList != null && myList.size() > 0) {
    for ( MyObj obj : myList ) {
        System.out.println("MyObjStr: "+obj);
    }
}
Run Code Online (Sandbox Code Playgroud)

是否有其他方法可以在不写"if"语句的情况下执行相同操作,但使用相同的"for"语句?

java collections arraylist

4
推荐指数
3
解决办法
7888
查看次数

如何在Spring中运行JUnit Test注入JBOSS JNDI数据源

我在春天有一个应用程序,在JBOSS 7.1上运行数据库oracle.我想测试我的服务层bean只是运行junit测试.在我的spring上下文中,我使用了像这样的jndi数据源:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jboss/datasources/myDatasource" />
    <property name="resourceRef" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

当我运行加载spring上下文测试的junit测试时,我收到一个异常,例如:

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [context.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
Run Code Online (Sandbox Code Playgroud)

如何在我的测试中注入JNDI数据源而不更改jboss中的上下文?

java junit jboss spring jndi

3
推荐指数
1
解决办法
6235
查看次数