小编Jon*_*run的帖子

为什么我收到MockMvc和JUnit的错误403?

我有一个带弹簧安全性的弹簧mvc(3.2.5)应用程序(3.2).

我使用此方法配置了SecurityConfig.class:

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

    http.authorizeRequests().antMatchers("/*").permitAll().and()
            .formLogin().successHandler(successHandler)
            .defaultSuccessUrl("/")
            .failureHandler(failureHandler).failureUrl("/login?error=true")
            .permitAll().and().logout()
            .permitAll();

    http.authorizeRequests().antMatchers("/resources/**").permitAll();

    http.authorizeRequests().antMatchers("/welcome").permitAll();

    http.authorizeRequests().antMatchers("/secure/*").authenticated();
    http.authorizeRequests().antMatchers("/admin/**").hasRole("ADMIN").anyRequest().authenticated();
} 
Run Code Online (Sandbox Code Playgroud)

使用Spring security(3.2),我启用了CSRF.我认为启用它是个好主意.

我的控制器SignInController包含两个带params的方法:

编辑:添加action=参数

@RequestMapping(value = "/signup")
    public ModelAndView signup() {

        boolean auth = SecurityContextHolder.getContext().getAuthentication() == null ? false
                : SecurityContextHolder.getContext().getAuthentication()
                        .isAuthenticated()
                        && (SecurityContextHolder.getContext()
                                .getAuthentication().getPrincipal() instanceof User);

        ModelAndView result = null;

        if (auth) {
            result = new ModelAndView("redirect:" + "/");
        } else {
            UserForm user = new UserForm();
            result = new ModelAndView("registration", "userForm", user);
        }
        return …
Run Code Online (Sandbox Code Playgroud)

junit spring mocking spring-mvc spring-security

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

如何实现Spring Bootstrap和Aspect?

我尝试配置日志记录方面,但我不明白它是如何工作的.

我有一个spring web mvc应用程序.考虑一下:

一个包含LoggingConfiguration的配置类包:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import my.package.aspects.LoggingAspect;
import my.package.web.controller.MemberController;

@Configuration
@EnableAspectJAutoProxy
public class LoggingConfiguration {
    @Bean
    public LoggingAspect loggingAspect() {
        return new LoggingAspect();
    }

    @Bean 
    MemberController memberController(){
        return new MemberController();
    }
}
Run Code Online (Sandbox Code Playgroud)

一个方面:

@Aspect
@Component
public class LoggingAspect {
    static Logger log = LoggerFactory.getLogger(LoggingAspect.class);

    @Before("execution(* my.package..*.*(..) )")
    public void logBefore(JoinPoint joinPoint) {
        log.debug("logBefore() is running!");
        log.debug(joinPoint.getSignature().getName());

    }
}
Run Code Online (Sandbox Code Playgroud)

log4j.xml(定义了appender)

<logger name="my.package" additivity="false">
    <appender-ref ref="consoleAppender" />
    <appender-ref ref="fileControllerAppender" />
</logger>
Run Code Online (Sandbox Code Playgroud)

为什么配置不起作用?

谢谢

编辑

web.xml是

    <?xml …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc aspect

6
推荐指数
1
解决办法
728
查看次数

如何在grails 1.3.7中记录sql

我尝试在数据源(测试环境)中使用logSql = true配置grails中的sql日志,但测试输出中没有显示任何内容.

我读过这篇文章,但它不起作用.

如何在Grails中记录SQL语句

谢谢

grails grails-orm

5
推荐指数
1
解决办法
2318
查看次数

为什么在 MacO 上启动 Eclipse 时出现此错误消息

我尝试在 MacOS 10.5.8 上使用 Eclipse Java EE,但是当我启动 IDE 时,收到此错误:

The JVM shared library "/System/Library/Frameworks/JavaVM.framework"
does not contain the JNI_CreateJavaVM symbol.
Run Code Online (Sandbox Code Playgroud)

在控制台模式下,如果我运行 java -version,结果是:

java version "1.5.0_28"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_28-b04-382-9M3326)
Java HotSpot(TM) Client VM (build 1.5.0_28-157, mixed mode, sharing)
Run Code Online (Sandbox Code Playgroud)

你有好主意吗?

eclipse osx-leopard

5
推荐指数
1
解决办法
1029
查看次数

Spring Security,Rest Authentication和CSRF

我想在我的应用程序中使用身份验证.我有一个Spring MVC应用程序和Spring Security应用程序.对浏览器,它工作正常.这意味着,我向我的应用程序验证用户并使用网页.

现在,我想用休息.我添加了不安全的控制器方法@ResponseBody,我在json中收到响应.但是如何使用RestTemplate用户和密码连接到我的应用程序?

我在RestClient中的代码是(用于测试):

public void unsecureProfileTest() {

    String url = articleServiceUrl + "unsecure/profile/test.json";
    url = articleServiceUrl + "secure/profile/wiew.json";
    HttpEntity<Object> entity = new HttpEntity<Object>(getHeaders("user:userpassword"));
    Object s = restTemplate.exchange(url, HttpMethod.GET, entity, Object.class);

}

static HttpHeaders getHeaders(String auth) {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON,
            MediaType.TEXT_HTML));

    byte[] encodedAuthorisation = Base64.encode(auth.getBytes());
    headers.add("Authorization", "Basic "
            + new String(encodedAuthorisation));

    return headers;
}
Run Code Online (Sandbox Code Playgroud)

我的安全配置:

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

    http.csrf().disable();

    http.authorizeRequests().antMatchers("/*").permitAll().and()
            .formLogin().successHandler(successHandler)
            .defaultSuccessUrl("/").failureHandler(failureHandler)
            .failureUrl("/login?error=true").permitAll().and().logout()
            .permitAll();

    http.authorizeRequests().antMatchers("/resources/**").permitAll();
    http.authorizeRequests().antMatchers("/welcome").permitAll();
    http.authorizeRequests().antMatchers("/unsecure/**").permitAll();

    http.authorizeRequests().antMatchers("/secure/*").authenticated();
    http.authorizeRequests().antMatchers("/admin/**").hasRole("ADMIN")
            .anyRequest().authenticated(); …
Run Code Online (Sandbox Code Playgroud)

java rest spring spring-security

5
推荐指数
1
解决办法
8231
查看次数

Grails groupProperty和订单.这个怎么运作?

我有这个域名:

class Participation {
   ParticipationStatus status
}
class ParticipationStatus{
   String name
   Date creationDate
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个查询:

Participation.createCriteria().list{
   createAlias("status","statusAlias")
   order "statusAlias.creationDate"
   projections{
     groupProperty "id"    
   }
}
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误:引起:java.sql.SQLException:ORA-00979:N'est pas une expression GROUP BY

我2天前在这个查询grrrr上工作了!;-)

非常感谢

grails grails-orm ora-00979

4
推荐指数
1
解决办法
5586
查看次数

(自定义)RestAuthenticationProcessingFilter排序的异常

我尝试通过令牌将Rest身份验证添加到我的应用程序.我创建了一个简单的过滤器,其他任何东西都不打印消

public class RestAuthenticationProcessingFilter extends GenericFilterBean {

@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
        FilterChain arg2) throws IOException, ServletException {
    System.out.println(arg0);
            // EDIT 25/02/2014
            arg2.doFilter(arg0,arg1);
}

}
Run Code Online (Sandbox Code Playgroud)

我正在使用Spring 4.0和Spring Security 3.2与JavaConfig.

我在我的适配器中添加了这个:

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

            /*
             * @RemarqueDev Différence entre permitAll et anonymous : permitAll
             * contient anonymous. Anonymous uniquement pour non connecté
             */
            http.addFilter(new RestAuthenticationProcessingFilter());
            http.csrf().disable().headers().disable();
            http.exceptionHandling().authenticationEntryPoint(new RestAuthenticationEntryPoint());
Run Code Online (Sandbox Code Playgroud)

当我运行jetty服务器时,我收到此消息:

Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration: Instantiation of …
Run Code Online (Sandbox Code Playgroud)

java rest spring spring-security

4
推荐指数
1
解决办法
9127
查看次数

Eclipse Maven:使用spring profile运行测试

我想用不同的配置文件运行maven但它似乎不起作用.我为我的JPAConfiguration创建了2个不同的java类:

JPAConfiguration.class和JPAConfigurationTest.class

@Configuration 
@Profile({"dev"}) 
@EnableTransactionManagement(proxyTargetClass = true) 
@EnableJpaRepositories(basePackages = { "com.jle.athleges.model.repository", "com.jle.athleges.security.repository" }) 
@ComponentScan(basePackages = { "com.jle.athleges.model.services", "com.jle.athleges.security.services" }) 
public class JpaConfiguration { 

    @Bean 
    public DataSource dataSource() throws SQLException { 
        System.out.println("use dev"); 
        EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); 
        builder.setName("dev"); 
        return builder.setType(EmbeddedDatabaseType.H2).build(); 
    } 

    @Bean 
    public EntityManagerFactory entityManagerFactory() throws SQLException { 

        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); 
        vendorAdapter.setGenerateDdl(true); 

        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); 
        factory.setJpaVendorAdapter(vendorAdapter); 
        factory.setPackagesToScan("com.jle.athleges.model.entity", "com.jle.athleges.security.entity"); 
        factory.setDataSource(dataSource()); 
        factory.afterPropertiesSet(); 
        return factory.getObject(); 

    } 

    @Bean 
    public EntityManager entityManager(EntityManagerFactory entityManagerFactory) { 
        return entityManagerFactory.createEntityManager(); 
    } 

    @Bean 
    public PlatformTransactionManager transactionManager() …
Run Code Online (Sandbox Code Playgroud)

java spring m2eclipse maven m2e

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

如何在Tomcat上使用Grails在我的网络应用程序(上传相册)中创建一个新文件夹?

我想创建一个相册.但我想在服务器上组织相册,所以我想创建新的文件夹:

/ myapp/myapp/albums/myapp/albums/1/myapp/albums/2 ...

我怎么能用Grails在tomcat上做到这一点?它在tomcat/bin中创建所有新文件夹而不是tomcat/webapps/myapp /

java grails tomcat

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

如何在grails中使用disciminator实现tablePerHierarchy?

我有一个课堂hirarchy:

class Item {}
class Participation extends Item{}
class Contribution extends Participation{}
class Question extends Participation{}
Run Code Online (Sandbox Code Playgroud)

我希望每个类都有一个表,所以我在Item中添加了tablePerHierarchy false

我需要一个discrimator来实现一个查询:where class ="Contribution"

我尝试了很多实现,但它不起作用.

怎么做 ?

谢谢

grails grails-orm

2
推荐指数
1
解决办法
2826
查看次数