Création de jetons SPNEGO pour les clients de service Web J2EE, .NET, Java™, pour les requêtes HTTP.
Vous pouvez créer un jeton SPNEGO (Simple and Protected GSS-API Negotiation) pour vos applications et l'insérer dans les en-têtes HTTP en vue de l'authentification auprès de WebSphere Application Server.
Procédure
- Création des justificatifs client. Choisissez l'une des 4 options ci-dessous :
- Création d'un justificatif GSS pour la mémoire tampon des justificatifs Kerberos Par
exemple :
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); Oid krb5MechOid = new Oid("1.2.840.113554.1.2.2"); Oid spnegoMechOid = new Oid("1.3.6.1.5.5.2"); GSSManager manager = GSSManager.getInstance(); GSSName gssUserName = manager.createName(userName, GSSName.NT_USER_NAME, krb5MechOid); clientGssCreds = manager.createCredential(gssUserName.canonicalize(krb5MechOid), GSSCredential.INDEFINITE_LIFETIME, krb5MechOid, GSSCredential.INITIATE_ONLY); clientGssCreds.add (gssUserName, GSSCredential.INDEFINITE_LIFETIME, GSSCredential.INDEFINITE_LIFETIME, spnegoMechOid, GSSCredential.INITIATE_ONLY);
- Création d'un justificatif GSS à partir d'un sujet auquel sont associés des tickets Kerberos. Par
exemple :
Oid krb5MechOid = new Oid("1.2.840.113554.1.2.2"); Oid spnegoMechOid = new Oid("1.3.6.1.5.5.2"); GSSManager manager = GSSManager.getInstance(); clientGssCreds = (GSSCredential) Subject.doAs(subject, new PrivilegedExceptionAction() { public Object run() throws GSSException, Exception { try { gssName = manager.createName( userName, GSSName.NT_USER_NAME, getKrb5MechOid()); GSSCredential gssCred = manager.createCredential( gssName.canonicalize(krb5MechOid), GSSCredential.DEFAULT_LIFETIME, krb5MechOid, GSSCredential.INITIATE_ONLY); gssCred.add (gssUserName, GSSCredential.INDEFINITE_LIFETIME, GSSCredential.INDEFINITE_LIFETIME, spnegoMechOid, GSSCredential.INITIATE_ONLY); return gssCred; } catch (GSSException gsse) { } catch (Exception e) { } return null; } });
- Création d'un justificatif GSS après l'appel du module de connexion WSKRB5Login. Par
exemple :
Oid krb5MechOid = new Oid("1.2.840.113554.1.2.2"); Oid spnegoMechOid = new Oid("1.3.6.1.5.5.2"); System.setProperty("javax.security.auth.useSubjectCredsOnly", "true"); GSSManager manager = GSSManager.getInstance(); GSSName gssUserName = manager.createName(userName, GSSName.NT_USER_NAME, krb5MechOid); clientGssCreds = manager.createCredential(gssUserName.canonicalize(krb5MechOid), GSSCredential.INDEFINITE_LIFETIME, krb5MechOid, GSSCredential.INITIATE_ONLY); clientGssCreds.add (gssUserName, GSSCredential.INDEFINITE_LIFETIME, GSSCredential.INDEFINITE_LIFETIME, spnegoMechOid, GSSCredential.INITIATE_ONLY);
- Créez un justificatif GSS à l'aide de la mémoire cache des justificatifs Kerberos natifs Microsoft. Par
exemple :
Oid krb5MechOid = new Oid("1.2.840.113554.1.2.2"); Oid spnegoMechOid = new Oid("1.3.6.1.5.5.2"); System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); GSSManager manager = GSSManager.getInstance(); clientGssCreds = manager.createCredential(null, GSSCredential.INDEFINITE_LIFETIME, krb5MechOid, GSSCredential.INITIATE_ONLY); clientGssCreds.add(null, GSSCredential.INDEFINITE_LIFETIME, GSSCredential.INDEFINITE_LIFETIME, spnegoMechOid, GSSCredential.INITIATE_ONLY);
Remarque : L'antémémoire de données d'identification MSLSA: repose sur la possibilité d'extraire le ticket Kerberos complet, y compris la clé de session, du LSA Kerberos. Dans le but d'améliorer la sécurité, Microsoft a commencé à implémenter une fonction qui permet de ne plus exporter les clés de session pour les tickets Ticket Getting, ce qui peut les rendre inutiles pour IBM® JGSS lors des tentatives de demandes de ticket de service supplémentaires. Cette nouvelle fonction peut se voir dans Windows 2003 Server et Windows XP SP2 Beta. Microsoft a fourni la clé de registre suivante pour désactiver cette nouvelle fonction :HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters AllowTGTSessionKey = 0x01 (DWORD)
Dans Windows XP SP2 Beta 1, la clé est spécifiée ainsi :HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos AllowTGTSessionKey = 0x01 (DWORD)
- Création d'un justificatif GSS pour la mémoire tampon des justificatifs Kerberos Par
exemple :
- Après avoir créé un justificatif GSS client vous pouvez créer le jeton SPNEGO et l'insérer dans l'en-tête HTTP comme dans l'exemple
suivant :
// create target server SPN GSSName gssServerName = manager.createName(targetServerSpn, GSSName.NT_USER_NAME); GSSContext clientContext = manager.createContext(gssServerName.canonicalize(spnegoMechOid), spnegoMechOid, clientGssCreds, GSSContext.DEFAULT_LIFETIME); // optional enable GSS credential delegation clientContext.requestCredDeleg(true); byte[] spnegoToken = new byte[0]; // create a SPNEGO token for the target server spnegoToken = clientContext.initSecContext(spnegoToken, 0, spnegoToken.length); URL url = new URL(targetUrl); HttpURLConnection con= (HttpURLConnection) url.openConnection(); try { // insert SPNEGO token in the HTTP header con.setRequestProperty("Authorization", "Negotiate " + Base64.encode(spnegoToken)); con.getResponseCode(); } catch (IOException e) { } catch (Exception ex) { }
Résultats
Il se peut que votre application nécessite un fichier de configuration Kerberos (krb5.ini ou krb5.conf). Pour plus d'informations, voir Création d'un fichier de configuration Kerberos.
Tâches associées:
Référence associée:


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tsec_SPNEGO_token
Nom du fichier : tsec_SPNEGO_token.html