Search in sources :

Example 1 with SecureRandomFactoryBean

use of org.springframework.security.core.token.SecureRandomFactoryBean in project spring-security by spring-projects.

the class SecureRandomFactoryBeanTests method testCreatesUsingDefaults.

@Test
public void testCreatesUsingDefaults() throws Exception {
    SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
    Object result = factory.getObject();
    assertThat(result).isInstanceOf(SecureRandom.class);
    int rnd = ((SecureRandom) result).nextInt();
    assertThat(rnd).isNotEqualTo(0);
}
Also used : SecureRandom(java.security.SecureRandom) SecureRandomFactoryBean(org.springframework.security.core.token.SecureRandomFactoryBean) Test(org.junit.Test)

Example 2 with SecureRandomFactoryBean

use of org.springframework.security.core.token.SecureRandomFactoryBean in project spring-security by spring-projects.

the class SecureRandomFactoryBeanTests method testCreatesUsingSeed.

@Test
public void testCreatesUsingSeed() throws Exception {
    SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
    Resource resource = new ClassPathResource("org/springframework/security/core/token/SecureRandomFactoryBeanTests.class");
    assertThat(resource).isNotNull();
    factory.setSeed(resource);
    Object result = factory.getObject();
    assertThat(result).isInstanceOf(SecureRandom.class);
    int rnd = ((SecureRandom) result).nextInt();
    assertThat(rnd).isNotEqualTo(0);
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SecureRandom(java.security.SecureRandom) ClassPathResource(org.springframework.core.io.ClassPathResource) SecureRandomFactoryBean(org.springframework.security.core.token.SecureRandomFactoryBean) Test(org.junit.Test)

Example 3 with SecureRandomFactoryBean

use of org.springframework.security.core.token.SecureRandomFactoryBean in project spring-security by spring-projects.

the class SecureRandomFactoryBeanTests method testObjectType.

@Test
public void testObjectType() {
    SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
    assertThat(factory.getObjectType()).isEqualTo(SecureRandom.class);
}
Also used : SecureRandomFactoryBean(org.springframework.security.core.token.SecureRandomFactoryBean) Test(org.junit.Test)

Example 4 with SecureRandomFactoryBean

use of org.springframework.security.core.token.SecureRandomFactoryBean in project spring-security by spring-projects.

the class KeyBasedPersistenceTokenServiceTests method getService.

private KeyBasedPersistenceTokenService getService() {
    SecureRandomFactoryBean fb = new SecureRandomFactoryBean();
    KeyBasedPersistenceTokenService service = new KeyBasedPersistenceTokenService();
    service.setServerSecret("MY:SECRET$$$#");
    service.setServerInteger(Integer.valueOf(454545));
    try {
        SecureRandom rnd = (SecureRandom) fb.getObject();
        service.setSecureRandom(rnd);
        service.afterPropertiesSet();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return service;
}
Also used : KeyBasedPersistenceTokenService(org.springframework.security.core.token.KeyBasedPersistenceTokenService) SecureRandom(java.security.SecureRandom) SecureRandomFactoryBean(org.springframework.security.core.token.SecureRandomFactoryBean)

Example 5 with SecureRandomFactoryBean

use of org.springframework.security.core.token.SecureRandomFactoryBean in project spring-security by spring-projects.

the class SecureRandomFactoryBeanTests method testIsSingleton.

@Test
public void testIsSingleton() {
    SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
    assertThat(factory.isSingleton()).isFalse();
}
Also used : SecureRandomFactoryBean(org.springframework.security.core.token.SecureRandomFactoryBean) Test(org.junit.Test)

Aggregations

SecureRandomFactoryBean (org.springframework.security.core.token.SecureRandomFactoryBean)5 Test (org.junit.Test)4 SecureRandom (java.security.SecureRandom)3 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 KeyBasedPersistenceTokenService (org.springframework.security.core.token.KeyBasedPersistenceTokenService)1