IdP クライアント・ファサードを使用してトークンを生成してサービス・プロバイダーに渡す

ユーザーが認証された後に別の SP のサービスにアクセスする場合は、SP 側で次のコードを呼び出します。

このタスクについて

このコードはフェデレーテッド・トークンを生成します。

// One time properties to initialize the IdP client.
Properties properties = new Properties();
properties.put(IdPClient.IDP_SERVER_URL, "URL");
properties.put(IdPClient.IDP_CLIENT_CERTIFICATE_ISSUER, "URL");
properties.put(IdPClient.IDP_CLIENT_KEYSTORE_PATH, "JKS file path");
properties.put(IdPClient.IDP_CLIENT_KEYSTORE_PASSKEY, "JKS passkey");
properties.put(IdPClient.IDP_CLIENT_KEYSTORE_ALIAS, "Certificate alias");
// Get the IdP client factory singleton instance 
//with the specified parameters.
IdPClientFactory clientFactory = IdPClientFactory.getInstance(properties);
// Get the partition specific client facade to do the assertion.
IdPClientFacade clientFacade = clientFactory.getIdPClientFacade(partition);
// Establish SSO Login with the IdP server 
IdPClientToken token = clientFacade.doIdPLogin(clientId, forUserId, spId);

トークンが取得されたら、ターゲット SP に渡して、マップされたユーザーの役割と権限に基づいてターゲット SP のリソースにアクセスすることができます。

// Security token is validated at Service Provider side.
IdPClientAssertion assertion = spFacade.assertIdPToken(clientId, forUserId, spId, 
token.getTokenId());
// Retrieve the principal from the assertion, if there is no exception.
String principal = assertion.getMappedUser();

クライアント・ファサードはマルチテナント対応なので、これを使用して各パーティションを別々に構成することができます。この機能を使用する場合は、各プロパティー名にクライアント ID を付加します。以下に例を示します。

properties.put(IdPClient.IDP_CLIENT_KEYSTORE_PATH + 
".partition1", "JKS file path"); 
properties.put(IdPClient.IDP_CLIENT_KEYSTORE_PASSKEY + 
".partition1", "JKS passkey"); 
properties.put(IdPClient.IDP_CLIENT_KEYSTORE_ALIAS + 
".partition1", "Certificate alias");