Skip to content

Commit 6f02f69

Browse files
committed
Align Code with Javadoc
Fixes: gh-6734
1 parent 14c4ac7 commit 6f02f69

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

core/src/main/java/org/springframework/security/core/token/SecureRandomFactoryBean.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,16 +37,15 @@ public class SecureRandomFactoryBean implements FactoryBean<SecureRandom> {
3737
public SecureRandom getObject() throws Exception {
3838
SecureRandom rnd = SecureRandom.getInstance(algorithm);
3939

40+
// Request the next bytes, thus eagerly incurring the expense of default
41+
// seeding and to prevent the see from replacing the entire state
42+
rnd.nextBytes(new byte[1]);
43+
4044
if (seed != null) {
4145
// Seed specified, so use it
4246
byte[] seedBytes = FileCopyUtils.copyToByteArray(seed.getInputStream());
4347
rnd.setSeed(seedBytes);
4448
}
45-
else {
46-
// Request the next bytes, thus eagerly incurring the expense of default
47-
// seeding
48-
rnd.nextBytes(new byte[1]);
49-
}
5049

5150
return rnd;
5251
}

core/src/test/java/org/springframework/security/core/token/SecureRandomFactoryBeanTests.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,14 +15,14 @@
1515
*/
1616
package org.springframework.security.core.token;
1717

18-
import static org.assertj.core.api.Assertions.*;
19-
2018
import java.security.SecureRandom;
2119

2220
import org.junit.Test;
21+
2322
import org.springframework.core.io.ClassPathResource;
2423
import org.springframework.core.io.Resource;
25-
import org.springframework.security.core.token.SecureRandomFactoryBean;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
2626

2727
/**
2828
* Tests {@link SecureRandomFactoryBean}.
@@ -59,10 +59,11 @@ public void testCreatesUsingSeed() throws Exception {
5959
"org/springframework/security/core/token/SecureRandomFactoryBeanTests.class");
6060
assertThat(resource).isNotNull();
6161
factory.setSeed(resource);
62-
Object result = factory.getObject();
63-
assertThat(result).isInstanceOf(SecureRandom.class);
64-
int rnd = ((SecureRandom) result).nextInt();
65-
assertThat(rnd).isNotEqualTo(0);
62+
SecureRandom first = factory.getObject();
63+
SecureRandom second = factory.getObject();
64+
assertThat(first.nextInt())
65+
.isNotEqualTo(0)
66+
.isNotEqualTo(second.nextInt());
6667
}
6768

6869
}

0 commit comments

Comments
 (0)