1919import java .util .Map ;
2020
2121@ SuppressWarnings ("unused" )
22- public class RedirectBinding extends Binding {
22+ public class RedirectBinding extends Binding {
2323
2424 private static final Logger logger = LogManager .getLogger (RedirectBinding .class );
2525
@@ -29,13 +29,11 @@ public class RedirectBinding extends Binding{
2929 // EXTERNAL OBJECT PUBLIC METHODS - BEGIN
3030
3131
32- public RedirectBinding ()
33- {
32+ public RedirectBinding () {
3433 logger .trace ("RedirectBinding constructor" );
3534 }
3635
37- public void init (String queryString )
38- {
36+ public void init (String queryString ) {
3937 logger .trace ("init" );
4038 logger .debug (MessageFormat .format ("init - queryString : {0}" , queryString ));
4139 this .redirectMessage = parseRedirect (queryString );
@@ -46,89 +44,75 @@ public void init(String queryString)
4644 }
4745
4846
49- public static String login (SamlParms parms , String relayState )
50- {
47+ public static String login (SamlParms parms , String relayState ) {
5148 Document request = SamlAssertionUtils .createLoginRequest (parms .getId (), parms .getDestination (), parms .getAcs (), parms .getIssuer (), parms .getPolicyFormat (), parms .getAuthnContext (), parms .getSPName (), parms .getForceAuthn ());
5249 return generateQuery (request , parms .getDestination (), parms .getCertPath (), parms .getCertPass (), parms .getCertAlias (), relayState );
5350 }
5451
55- public static String logout (SamlParms parms , String relayState )
56- {
52+ public static String logout (SamlParms parms , String relayState ) {
5753 Document request = SamlAssertionUtils .createLogoutRequest (parms .getId (), parms .getIssuer (), parms .getNameID (), parms .getSessionIndex (), parms .getDestination ());
5854 return generateQuery (request , parms .getDestination (), parms .getCertPath (), parms .getCertPass (), parms .getCertAlias (), relayState );
5955 }
6056
61- public boolean verifySignatures (SamlParms parms )
62- {
57+ public boolean verifySignatures (SamlParms parms ) {
6358 logger .debug ("verifySignatures" );
6459
65- try
66- {
60+ try {
6761 return DSig .validateSignatures (this .xmlDoc , parms .getTrustCertPath (), parms .getTrustCertAlias (), parms .getTrustCertPass ());
68- }catch (Exception e )
69- {
62+ } catch (Exception e ) {
7063 logger .error ("verifySignature" , e );
7164 return false ;
7265 }
7366 }
7467
75- public String getLogoutAssertions ()
76- {
68+ public String getLogoutAssertions () {
7769 logger .trace ("getLogoutAssertions" );
7870 return SamlAssertionUtils .getLogoutInfo (this .xmlDoc );
7971 }
8072
81- public String getRelayState ()
82- {
73+ public String getRelayState () {
8374 logger .trace ("getRelayState" );
8475 try {
8576 return this .redirectMessage .get ("RelayState" ) == null ? "" : URLDecoder .decode (this .redirectMessage .get ("RelayState" ), StandardCharsets .UTF_8 .name ());
86- }catch (Exception e )
87- {
77+ } catch (Exception e ) {
8878 logger .error ("getRelayState" , e );
8979 return "" ;
9080 }
9181 }
9282
93- public String getLoginAssertions ()
94- {
83+ public String getLoginAssertions () {
9584 //Getting user's data by URL parms (GET) is deemed insecure so we are not implementing this method for redirect binding
9685 logger .error ("getLoginAssertions - NOT IMPLEMENTED insecure SAML implementation" );
9786 return "" ;
9887 }
9988
100- public String getRoles (String name )
101- {
89+ public String getRoles (String name ) {
10290 //Getting user's data by URL parms (GET) is deemed insecure so we are not implementing this method for redirect binding
10391 logger .error ("getRoles - NOT IMPLEMENTED insecure SAML implementation" );
10492 return "" ;
10593 }
10694
107- public String getLoginAttribute (String name )
108- {
95+ public String getLoginAttribute (String name ) {
10996 //Getting user's data by URL parms (GET) is deemed insecure so we are not implementing this method for redirect binding
11097 logger .error ("getLoginAttribute - NOT IMPLEMENTED insecure SAML implementation" );
11198 return "" ;
11299 }
113100
114101 // EXTERNAL OBJECT PUBLIC METHODS - END
115102
116- private static Map <String , String > parseRedirect (String request )
117- {
103+ private static Map <String , String > parseRedirect (String request ) {
118104 logger .trace ("parseRedirect" );
119- Map <String ,String > result = new HashMap <>();
105+ Map <String , String > result = new HashMap <>();
120106 String [] redirect = request .split ("&" );
121107
122- for (String s : redirect )
123- {
108+ for (String s : redirect ) {
124109 String [] res = s .split ("=" );
125110 result .put (res [0 ], res [1 ]);
126111 }
127112 return result ;
128113 }
129114
130- private static String generateQuery (Document request , String destination , String certPath , String certPass , String alias , String relayState )
131- {
115+ private static String generateQuery (Document request , String destination , String certPath , String certPass , String alias , String relayState ) {
132116 logger .trace ("generateQuery" );
133117 try {
134118 String samlRequestParameter = Encoding .delfateAndEncodeXmlParameter (Encoding .documentToString (request ));
@@ -143,25 +127,22 @@ private static String generateQuery(Document request, String destination, String
143127
144128 logger .debug (MessageFormat .format ("generateQuery - query: {0}" , query ));
145129 return MessageFormat .format ("{0}?{1}" , destination , query );
146- }catch (Exception e )
147- {
130+ } catch (Exception e ) {
148131 logger .error ("generateQuery" , e );
149132 return "" ;
150133 }
151134
152135 }
153136
154- private static String signRequest_RedirectBinding (String query , String path , String password , Hash hash , String alias )
155- {
137+ private static String signRequest_RedirectBinding (String query , String path , String password , Hash hash , String alias ) {
156138 logger .trace ("signRequest_RedirectBinding" );
157- RSADigestSigner signer = new RSADigestSigner (Hash .getDigest (hash ));
139+ RSADigestSigner signer = new RSADigestSigner (Hash .getDigest (hash ));
158140 byte [] inputText = query .getBytes (StandardCharsets .UTF_8 );
159141 try (InputStream inputStream = new ByteArrayInputStream (inputText )) {
160142 setUpSigner (signer , inputStream , Keys .loadPrivateKey (path , alias , password ), true );
161143 byte [] outputBytes = signer .generateSignature ();
162144 return Base64 .toBase64String (outputBytes );
163- }catch (Exception e )
164- {
145+ } catch (Exception e ) {
165146 logger .error ("signRequest_RedirectBinding" , e );
166147 return "" ;
167148 }
0 commit comments