File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
plugins/user-authenticators/saml2/src
main/java/org/apache/cloudstack/saml
test/java/org/apache/cloudstack Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 100100public class SAMLUtils {
101101 public static final Logger s_logger = Logger .getLogger (SAMLUtils .class );
102102
103+ static final String charset = "abcdefghijklmnopqrstuvwxyz" ;
104+
103105 public static String generateSecureRandomId () {
104- return new BigInteger (160 , new SecureRandom ()).toString (32 );
106+ return new BigInteger (160 , new SecureRandom ()).toString (32 ).replaceFirst ("^[0-9]" ,
107+ String .valueOf (charset .charAt (new SecureRandom ().nextInt (charset .length ()))));
105108 }
106109
107110 public static String getValueFromAttributeStatements (final List <AttributeStatement > attributeStatements , final String attributeKey ) {
Original file line number Diff line number Diff line change 2222import java .security .KeyPair ;
2323import java .security .PrivateKey ;
2424import java .security .PublicKey ;
25+ import java .util .regex .Pattern ;
2526
2627import org .apache .cloudstack .saml .SAMLUtils ;
2728import org .apache .cloudstack .utils .security .CertUtils ;
@@ -38,6 +39,15 @@ public void testGenerateSecureRandomId() throws Exception {
3839 assertTrue (SAMLUtils .generateSecureRandomId ().length () > 0 );
3940 }
4041
42+ @ Test
43+ public void testGenerateSecureRandomId2 () throws Exception {
44+ for (int i = 0 ; i < 20 ; i ++) {
45+ String randomId = SAMLUtils .generateSecureRandomId ();
46+ System .out .println ("randomId is " + randomId );
47+ assertTrue (Pattern .compile ("^[a-z]" ).matcher (randomId ).find ());
48+ }
49+ }
50+
4151 @ Test
4252 public void testBuildAuthnRequestObject () throws Exception {
4353 String consumerUrl = "http://someurl.com" ;
You can’t perform that action at this time.
0 commit comments