@@ -572,98 +572,150 @@ public static class SAMLAuthContext implements SecurityContext {
572572 private ExpiringSAMLAuth authorization ;
573573 private RenewerCallback renewer ;
574574
575- /**
576- * @return the X509TrustManagerused for authentication.
577- */
578- public X509TrustManager getTrustManager () {
579- return trustManager ;
580- }
581-
582- /**
583- * Replaces the token with new SAML authorization token.
584- */
575+ /**
576+ * Constructs a context for authorization using a SAML assertions token.
577+ * @param authorizationToken the token with the SAML assertions
578+ */
585579 public SAMLAuthContext (String authorizationToken ) {
586580 this .token = authorizationToken ;
587581 }
582+ /**
583+ * Constructs a context for authorization using an authorizer callback.
584+ * The authorizer must get a SAML assertions token from the IDP (Identity Provider)
585+ * for the first request and when the current SAML assertions token is expiring.
586+ * @param authorizer the callback returning the assertions token
587+ */
588588 public SAMLAuthContext (AuthorizerCallback authorizer ) {
589589 this .authorizer = authorizer ;
590590 }
591+ /**
592+ * Constructs a context for authorization using a SAML assertions token
593+ * and a renewer callback. The renewer callback must renew the SAML
594+ * assertions token with the IDP (Identity Provider) when the SAML assertions
595+ * token is expiring.
596+ * @param authorization the expiring object with the SAML assertions token and expiry
597+ * @param renewer the renewer callback
598+ */
591599 public SAMLAuthContext (ExpiringSAMLAuth authorization , RenewerCallback renewer ) {
592600 this .authorization = authorization ;
593601 this .renewer = renewer ;
594602 }
595-
596- /**
603+
604+ /** Gets the SAML authentication token
597605 * @return the SAML authentication token.
598606 */
599607 public String getToken () {
608+ if (token == null && authorization != null )
609+ return authorization .getAuthorizationToken ();
600610 return token ;
601611 }
612+
613+ /**
614+ * Gets the authorizer callback when specified during construction of the SAMLAuthContext.
615+ * @return the callback
616+ */
602617 public AuthorizerCallback getAuthorizer () {
603618 return authorizer ;
604619 }
620+ /**
621+ * Gets the renewer callback when specified during construction of the SAMLAuthContext.
622+ * @return the callback
623+ */
605624 public RenewerCallback getRenewer () {
606625 return renewer ;
607626 }
627+ /**
628+ * Gets the object with the SAML assertions token and expiration when specified during
629+ * construction of the SAMLAuthContext or renewed by the renewer callback.
630+ * @return the object with the assertions token and expiration
631+ */
608632 public ExpiringSAMLAuth getAuthorization () {
609633 return authorization ;
610634 }
611635
612636 /**
613- * ExpiringSAMLAuth is used by SAMLAuthContext for reauthorization .
637+ * ExpiringSAMLAuth is used by SAMLAuthContext when renewing a SAML assertions token .
614638 */
615639 public interface ExpiringSAMLAuth {
616640 /**
617- * @return a new SAML assertion token.
641+ * Gets the SAML assertions token
642+ * @return the token.
618643 */
619644 public String getAuthorizationToken ();
620-
621645 /**
622- * @return the expiration time stamp of the newly generated SAML assertion token.
646+ * Gets the expiration time stamp specified for the SAML assertions token
647+ * @return the expiration time stamp
623648 */
624649 public Instant getExpiry ();
625650 }
626651
627652 /**
628- * newExpiringSAMLAuth is used to provide a new token with a new expiration time stamp.
653+ * Constructs an ExpiringSAMLAuth with a SAML assertions token and the expiration time stamp
654+ * for the token.
629655 * @param authorizationToken refers to the new SAML token.
630656 * @param expiry refers to the expiration time stamp of authorizationToken.
631657 * @return an ExpiringSAMLAuth instance.
632658 */
633659 public static ExpiringSAMLAuth newExpiringSAMLAuth (final String authorizationToken , final Instant expiry ) {
634660 return new ExpiringSAMLAuth () {
635-
636661 @ Override
637662 public Instant getExpiry () {
638663 return expiry ;
639664 }
640-
641665 @ Override
642666 public String getAuthorizationToken () {
643667 return authorizationToken ;
644668 }
645669 };
646670 }
647-
648- @ FunctionalInterface
649- public interface AuthorizerCallback extends Function <ExpiringSAMLAuth , ExpiringSAMLAuth > { }
650-
651- @ FunctionalInterface
652- public interface RenewerCallback extends Function <ExpiringSAMLAuth , Instant > { }
653671
672+ /**
673+ * A callback for getting a SAML assertions token from the IDP (Identity Provider).
674+ */
675+ @ FunctionalInterface
676+ public interface AuthorizerCallback extends Function <ExpiringSAMLAuth , ExpiringSAMLAuth > { }
677+
678+ /**
679+ * A callback for renewing the SAML assertions token with the IDP (Identity Provider)
680+ * by extending the expiration time.
681+ */
682+ @ FunctionalInterface
683+ public interface RenewerCallback extends Function <ExpiringSAMLAuth , Instant > { }
684+
685+ /**
686+ * Configures the SSL context and trust manager for a SAML authorization context
687+ * @param context - the SSLContext object required for the SSL connection
688+ * @param trustManager - X509TrustManager with which we initialize the SSLContext
689+ * @return this SAML authorization context for chained configuration
690+ */
654691 @ Override
655692 public SAMLAuthContext withSSLContext (SSLContext context , X509TrustManager trustManager ) {
656693 this .sslContext = context ;
657694 this .trustManager = trustManager ;
658695 return this ;
659696 }
660-
697+ /**
698+ * Configures the SSL hostname verifier for a SAML authorization context
699+ * @param verifier the host verifier
700+ * @return this SAML authorization context for chained configuration
701+ */
661702 @ Override
662703 public SAMLAuthContext withSSLHostnameVerifier (SSLHostnameVerifier verifier ) {
663704 this .sslVerifier = verifier ;
664705 return this ;
665706 }
666707
708+ /**
709+ * Gets the trust manager when using SSL.
710+ * @return the X509TrustManager used for authentication
711+ */
712+ public X509TrustManager getTrustManager () {
713+ return trustManager ;
714+ }
715+ /**
716+ * Gets the SSL context when using SSL.
717+ * @return the SSLContext used for authentication
718+ */
667719 @ Override
668720 public SSLContext getSSLContext () {
669721 return sslContext ;
@@ -676,6 +728,10 @@ public void setSSLContext(SSLContext context) {
676728
677729 }
678730
731+ /**
732+ * Gets the hostname verifier when using SSL.
733+ * @return the hostname verifier used for authentication
734+ */
679735 @ Override
680736 public SSLHostnameVerifier getSSLHostnameVerifier () {
681737 return sslVerifier ;
0 commit comments