You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+55-27
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ The toolkit is hosted on github. You can download it from:
93
93
The toolkit is hosted at [Sonatype OSSRH (OSS Repository Hosting)](http://central.sonatype.org/pages/ossrh-guide.html) that is synced to the Central Repository.
94
94
95
95
Install it as a maven dependency:
96
-
```
96
+
```xml
97
97
<dependency>
98
98
<groupId>com.onelogin</groupId>
99
99
<artifactId>java-saml</artifactId>
@@ -444,7 +444,7 @@ If you want to use anything different than javax.servlet.http, you will need to
444
444
445
445
#### Initiate SSO
446
446
In order to send an AuthNRequest to the IdP:
447
-
```
447
+
```java
448
448
Auth auth =newAuth(request, response);
449
449
auth.login();
450
450
```
@@ -453,16 +453,18 @@ The AuthNRequest will be sent signed or unsigned based on the security settings
453
453
The IdP will then return the SAML Response to the user's client. The client is then forwarded to the Attribute Consumer Service of the SP with this information.
454
454
455
455
We can set a 'RelayState' parameter containing a return url to the login function:
456
-
```
456
+
```java
457
457
String returnUrl ='https://example.com';
458
458
auth.login(relayState=returnUrl)
459
459
```
460
-
The login method can receive 6 more optional parameters:
461
-
-*forceAuthn* When true the AuthNRequest will have the 'ForceAuthn' attribute set to 'true'
462
-
-*isPassive* When true the AuthNRequest will have the 'Ispassive' attribute set to 'true'
463
-
-*setNameIdPolicy* When true the AuthNRequest will set a nameIdPolicy element.
460
+
The login method can receive 3 more optional parameters:
461
+
-*authnRequestParams* which in turn allows to shape the AuthNRequest with the following properties:
462
+
-*forceAuthn* When true the AuthNRequest will have the `ForceAuthn` attribute set to `true`
463
+
-*isPassive* When true the AuthNRequest will have the `IsPassive` attribute set to `true`
464
+
-*setNameIdPolicy* When true the AuthNRequest will set a `NameIdPolicy` element
465
+
-*allowCreate* When true, and *setNameIdPolicy* is also true, the AuthNRequest will have the `AllowCreate` attribute set to `true` on the `NameIdPolicy` element
466
+
-*nameIdValueReq* Indicates to the IdP the subject that should be authenticated
464
467
-*stay* Set to true to stay (returns the url string), otherwise set to false to execute a redirection to that url (IdP SSO URL)
465
-
-*nameIdValueReq* Indicates to the IdP the subject that should be authenticated
466
468
-*parameters* Use it to send extra parameters in addition to the AuthNRequest
467
469
468
470
By default, the login method initiates a redirect to the SAML Identity Provider. You can use the *stay* parameter, to prevent that, and execute the redirection manually. We need to use that if a match on the future SAMLResponse ID and the AuthNRequest ID to be sent is required. That AuthNRequest ID must be extracted and stored for future validation, so we can't execute the redirection on the login. Instead, set *stay* to true, then get that ID by
@@ -477,7 +479,7 @@ Related to the SP there are 3 important endpoints: The metadata view, the ACS vi
477
479
478
480
##### SP Metadata
479
481
This code will provide the XML metadata file of our SP, based on the info that we provided in the settings files.
480
-
```
482
+
```java
481
483
Auth auth =newAuth();
482
484
Saml2Settings settings = auth.getSettings();
483
485
String metadata = settings.getSPMetadata();
@@ -497,7 +499,7 @@ Before the XML metadata is exposed, a check takes place to ensure that the info
497
499
498
500
##### Attribute Consumer Service(ACS)
499
501
This code handles the SAML response that the IdP forwards to the SP through the user's client.
500
-
```
502
+
```java
501
503
Auth auth =newAuth(request, response);
502
504
auth.processResponse();
503
505
if (!auth.isAuthenticated()) {
@@ -575,7 +577,7 @@ Before trying to get an attribute, check that the user is authenticated. If the
575
577
576
578
##### Single Logout Service (SLS)
577
579
This code handles the Logout Request and the Logout Responses.
578
-
```
580
+
```java
579
581
Auth auth =newAuth(request, response);
580
582
auth.processSLO();
581
583
List<String> errors = auth.getErrors();
@@ -595,7 +597,7 @@ If we don't want that processSLO to destroy the session, pass the keepLocalSessi
595
597
596
598
#### Initiate SLO
597
599
In order to send a Logout Request to the IdP:
598
-
```
600
+
```java
599
601
Auth auth =newAuth(request, response);
600
602
601
603
String nameId =null;
@@ -618,36 +620,62 @@ String sessionIndex = null;
618
620
if (session.getAttribute("sessionIndex") !=null) {
TheLogoutRequest will be sent signed or unsigned based on the security settings 'onelogin.saml2.security.logoutrequest_signed'
624
626
625
627
TheIdP will return the LogoutResponse through the user's client to the Single Logout Service of the SP.
626
628
627
629
We can set a 'RelayState' parameter containing a return url to the login function:
628
-
```
630
+
```java
629
631
String returnUrl = 'https://example.com';
630
632
auth.logout(relayState=returnUrl)
631
633
```
632
634
633
-
Also there are 7 optional parameters that can be set:
634
-
-nameId. That will be used to build the LogoutRequest. If not name_id parameter is set and the auth object processed a SAML Response with a NameId, then this NameId will be used.
635
-
-sessionIndex. Identifies the session of the user.
636
-
If a match on the LogoutResponse ID and the LogoutRequest ID to be sent is required, that LogoutRequest ID must to be extracted and stored for future validation, we can get that ID by
637
-
- stay. True if we want to stay (returns the url string) False to execute a redirection to that url (IdP SLS URL)
638
-
- nameidFormat. The NameID Format that will be set in the LogoutRequest
639
-
- nameIdNameQualifier. The NameID NameQualifier that will be set in the LogoutRequest
640
-
-nameIdSPNameQualifier. The NameID SP Name Qualifier that will be set in the LogoutRequest
641
-
- parameters. Use it to send extra parameters in addition to the LogoutRequest
642
-
643
-
By default the logout method initiates a redirect to the SAML Identity Provider. You can use the stay parameter, to prevent that, and execute the redirection manually. We need to use that
635
+
Also there are other 3 optional parameters that can be set:
636
+
-*logoutRequestParams* which in turn allows to shape the LogoutRequest with the following properties:
637
+
-*sessionIndex* Identifies the session of the user
638
+
-*nameId* That will be used to build the LogoutRequest. If no *nameId* parameter is set and the auth object processed a SAML Response with a `NameID`, then this `NameID` will be used
639
+
-*nameidFormat* The `NameID``Format` that will be set on the LogoutRequest
640
+
-*nameIdNameQualifier* The `NameID``NameQualifier` that will be set on the LogoutRequest
641
+
-*nameIdSPNameQualifier* The `NameID``SPNameQualifier` that will be set on the LogoutRequest
642
+
-*stay* True if we want to stay (returns the url string) False to execute a redirection to that url (IdP SLS URL)
643
+
-*parameters* Use it to send extra parameters in addition to the LogoutRequest
644
+
645
+
By default the logout method initiates a redirect to the SAML Identity Provider. You can use the *stay* parameter, to prevent that, and execute the redirection manually. We need to use that
644
646
if a match on the future LogoutResponse ID and the LogoutRequest ID to be sent is required, that LogoutRequest ID must be extracted and stored for future validation so we can't execute the redirection on the logout, instead set stay to true, then get that ID by
645
647
646
-
```
648
+
```java
647
649
auth.getLastRequestId()
648
650
```
649
651
and later executing the redirection manually.
650
652
653
+
### Extending the provided implementation
654
+
655
+
All the provided SAML message classes (`AuthnRequest`, `SamlResponse`, `LogoutRequest`, `LogoutResponse`) can be extended to add or change the processing behavior.
656
+
657
+
In particular, the classes used to produce outgoing messages (`AuthnRequest`, `LogoutRequest`, and `LogoutResponse`) also provide a `postProcessXml` method that can be overridden to customise the generation of the corresponding SAML message XML, along with the ability to pass in proper extensions of the input parameter classes (`AuthnRequestParams`, `LogoutRequestParams`, and `LogoutResponseParams` respectively).
658
+
659
+
Once you have prepared your extension classes, in order to make the `Auth` class use them, an appropriate `SamlMessageFactory` implementation can be specified. As an example, assuming you've created two extension classes `AuthnRequestEx` and `SamlResponseEx` to customise the creation of AuthnRequest SAML messages and the validation of SAML responses respectively, as well as an extended `AuthnRequestParamsEx` input parameter class to drive the AuthnRequest generation post-processing, you can do the following:
0 commit comments