From dev-return-57169-archive-asf-public=cust-asf.ponee.io@directory.apache.org Fri Feb 9 08:15:12 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 7CC4B180654 for ; Fri, 9 Feb 2018 08:15:12 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 6CA2D160C4C; Fri, 9 Feb 2018 07:15:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 177B7160C2E for ; Fri, 9 Feb 2018 08:15:10 +0100 (CET) Received: (qmail 116 invoked by uid 500); 9 Feb 2018 07:15:10 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 105 invoked by uid 99); 9 Feb 2018 07:15:10 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Feb 2018 07:15:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id A8F0618030B for ; Fri, 9 Feb 2018 07:15:09 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.511 X-Spam-Level: X-Spam-Status: No, score=-109.511 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id zo69MkrXD8Th for ; Fri, 9 Feb 2018 07:15:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id E31F95F39F for ; Fri, 9 Feb 2018 07:15:05 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 85B99E015D for ; Fri, 9 Feb 2018 07:15:04 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 9941E240F2 for ; Fri, 9 Feb 2018 07:15:01 +0000 (UTC) Date: Fri, 9 Feb 2018 07:15:01 +0000 (UTC) From: "Fabiano Tarlao (JIRA)" To: dev@directory.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (DIRKRB-692) 1)sgtTicket clientPrincipal is not initialized + 2)KrbClient fails to store SGT ticket in cache file MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DIRKRB-692?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:all-tabpanel ] Fabiano Tarlao updated DIRKRB-692: ---------------------------------- Description:=20 Two bugs that interact each other h1. 1) *SgtTicket*, returned by *KrbClient.requestSgt(..)*, has a _null_ *clientPr= incipal* field (unassigned). Perhaps this is not mandatory but your code as= sumes this property is populated (see later). I highly suggest to populate = this field. I have wrote a workaround that overrides the=C2=A0*requestSgt* method and w= orks for the *USE_TGT* case (the real complete fix is on GitHub,in a set of= subsequent pull requests :) ): =C2=A0 {code:java} @Override =C2=A0=C2=A0=C2=A0 public SgtTicket requestSgt(KOptions requestOptions) thr= ows KrbException { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SgtTicket requestSgt =3D super.r= equestSgt(requestOptions);=20 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 TgtTicket tgt =3D (TgtTicket) re= questOptions.getOptionValue(KrbOption.USE_TGT); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(tgt !=3D null){ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 requestS= gt.setClientPrincipal(tgt.getClientPrincipal()); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return requestSgt; =C2=A0=C2=A0=C2=A0 }{code} =C2=A0 h1. 2) Creating a new credential cache file when storing only one SGT (service tic= ket) fails. (i.e., trying to create a new cache file containing only one SG= T and no TGT) Invoking *KrbClient.storeTicket(sgtTicket, File)* fails for this reason (he= re is the original code in *KrbClientBase* class, my comments in RED ): {{public void storeTicket(SgtTicket sgtTicket, File ccacheFile) throws KrbE= xception {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG.info("Storing the sgt to = the credential cache file.");}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!ccacheFile.exists()) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 creat= eCacheFile(ccacheFile);{color:#ff0000} //Correctly creates a new file but..= .{color}}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ccacheFile.exists() && cc= acheFile.canWrite()) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Crede= ntialCache cCache =3D new CredentialCache();}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try {= }} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.load(ccacheFile);{color:#ff0000} //..this line EX= PLODES cause it tries to initialize from an empty file, the unexistent file= case is not managed correctly{color}}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.addCredential(new Credential(sgtTicket, sgtTicket= .getClientPrincipal()));}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.setPrimaryPrincipal(sgtTicket.getClientPrincipal(= ));}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.store(ccacheFile);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } cat= ch (IOException e) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 throw new KrbException("Failed to store sgt", e);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 throw= new IllegalArgumentException("Invalid ccache file, "}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 + "not exist or writable: " + cc= acheFile.getAbsolutePath());}} {{}}} Here follows my proposal/fix, this code correctly manages the MIT ccache fi= le creation for one SGT, please note that this fix assumes that bug 1 is al= ready fixed: =C2=A0 {code:java} public void storeTicket(SgtTicket sgtTicket, File ccacheFile) throws KrbExc= eption { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG.info("Storing the sgt to the= credential cache file."); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 boolean isFreshNew =3D !ccacheFi= le.exists() || (ccacheFile.length() =3D=3D 0); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (isFreshNew) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 createCa= cheFile(ccacheFile); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ccacheFile.exists() && ccach= eFile.canWrite()) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 CredentialCache cCache; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 if (!isFreshNew) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache =3D new CredentialCache();= =20 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.load(ccacheFile); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.addCredential(new Credential= (sgtTicket, sgtTicket.getClientPrincipal())); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 } else { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 //Remind: contructor sets the cCach= e client principal from the sgtTicket one =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache =3D new CredentialCache(sgtT= icket); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 cCache.store(ccacheFile); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } catch = (IOException e) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 throw new KrbException("Failed to store sgt", e); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 throw ne= w IllegalArgumentException("Invalid ccache file, " =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 + "not exist or writable: " + ccach= eFile.getAbsolutePath()); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0 } {code} =C2=A0 Please note that *YOUR CredentialCache contructor assumes the clientPrincip= al is populated* ;) Hope useful, regards Fabiano P.s: Attached two paches for the project, bug2.diff for bug 2 is..*I think.= . production ready*. bug1.diff for bug 1 is untested.. I ported the modification of my overridin= g method to the *AbstractInternalKrbClient.requestSgt()* method. But I have= not performed run/test of modules, your project is big and needs time to m= anage well. *BUT* is this the right solution? or SHOULD the *clientPrincipa= l* be already populated from the doRequestSgt method? I suggest to look for= a solution at a deeper level starting from *DefaultInternalKrbClient*. Con= sider bug1.diff a fair workaround. P.s.2:Added a pull request on GitHub Regards was: Two bugs that interact each other h1. 1) *SgtTicket*, returned by *KrbClient.requestSgt(..)*, has a _null_ *clientPr= incipal* field (unassigned). Perhaps this is not mandatory but your code as= sumes this property is populated (see later). I highly suggest to populate = this field. I have wrote a workaround that overrides the=C2=A0*requestSgt* method and w= orks for the *USE_TGT* case: =C2=A0 {code:java} @Override =C2=A0=C2=A0=C2=A0 public SgtTicket requestSgt(KOptions requestOptions) thr= ows KrbException { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SgtTicket requestSgt =3D super.r= equestSgt(requestOptions);=20 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 TgtTicket tgt =3D (TgtTicket) re= questOptions.getOptionValue(KrbOption.USE_TGT); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(tgt !=3D null){ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 requestS= gt.setClientPrincipal(tgt.getClientPrincipal()); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return requestSgt; =C2=A0=C2=A0=C2=A0 }{code} =C2=A0 h1. 2) Creating a new credential cache file when storing only one SGT (service tic= ket) fails. (i.e., trying to create a new cache file containing only one SG= T and no TGT) Invoking *KrbClient.storeTicket(sgtTicket, File)* fails for this reason (he= re is the original code in *KrbClientBase* class, my comments in RED ): {{public void storeTicket(SgtTicket sgtTicket, File ccacheFile) throws KrbE= xception {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG.info("Storing the sgt to = the credential cache file.");}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!ccacheFile.exists()) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 creat= eCacheFile(ccacheFile);{color:#ff0000} //Correctly creates a new file but..= .{color}}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ccacheFile.exists() && cc= acheFile.canWrite()) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Crede= ntialCache cCache =3D new CredentialCache();}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try {= }} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.load(ccacheFile);{color:#ff0000} //..this line EX= PLODES cause it tries to initialize from an empty file, the unexistent file= case is not managed correctly{color}}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.addCredential(new Credential(sgtTicket, sgtTicket= .getClientPrincipal()));}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.setPrimaryPrincipal(sgtTicket.getClientPrincipal(= ));}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.store(ccacheFile);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } cat= ch (IOException e) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 throw new KrbException("Failed to store sgt", e);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 throw= new IllegalArgumentException("Invalid ccache file, "}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 + "not exist or writable: " + cc= acheFile.getAbsolutePath());}} {{}}} Here follows my proposal/fix, this code correctly manages the MIT ccache fi= le creation for one SGT, please note that this fix assumes that bug 1 is al= ready fixed: {{public static void storeTicket(SgtTicket sgtTicket, File ccacheFile) thro= ws KrbException {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG.info("Storing the sgt to = the credential cache file.");}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 boolean isFreshNew =3D !ccach= eFile.exists();}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (isFreshNew) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 creat= eCacheFile(ccacheFile);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ccacheFile.exists() && cc= acheFile.canWrite()) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try {= }} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 CredentialCache cCache;}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 if(!isFreshNew){}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache =3D new CredentialCache(s= gtTicket); {color:#ff0000}//This constructor sets also the cCache principal= from sgtTicket principal{color}}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.load(ccacheFile);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.addCredential(new Credent= ial(sgtTicket, sgtTicket.getClientPrincipal()));}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.setPrimaryPrincipal(sgtTi= cket.getClientPrincipal());}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 } else {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache =3D new CredentialCache(s= gtTicket);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.store(ccacheFile);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } cat= ch (IOException e) {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 throw new KrbException("Failed to store sgt", e);}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else {}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 throw= new IllegalArgumentException("Invalid ccache file, "}} {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 + "not exist or writable: " + cc= acheFile.getAbsolutePath());}} Please note that *YOUR CredentialCache contructor assumes the clientPrincip= al is populated* ;) Hope useful, regards Fabiano P.s: Attached two paches for the project, bug2.diff for bug 2 is..*I think.= . production ready*. bug1.diff for bug 1 is untested.. I ported the modification of my overridin= g method to the *AbstractInternalKrbClient.requestSgt()* method. But I have= not performed run/test of modules, your project is big and needs time to m= anage well. *BUT* is this the right solution? or SHOULD the *clientPrincipa= l* be already populated from the doRequestSgt method? I suggest to look for= a solution at a deeper level starting from *DefaultInternalKrbClient*. Con= sider bug1.diff a fair workaround. P.s.2:Added a pull request on GitHub Regards > 1)sgtTicket clientPrincipal is not initialized + 2)KrbClient fails to sto= re SGT ticket in cache file > -------------------------------------------------------------------------= --------------------------- > > Key: DIRKRB-692 > URL: https://issues.apache.org/jira/browse/DIRKRB-692 > Project: Directory Kerberos > Issue Type: Bug > Affects Versions: 1.1.0 > Environment: Linux Mint 17.1 + Netbeans 8.1 with a Maven Project = + kerb-core 1.1.0 in Windows AD (KDC is Windows 2016 Server) > Reporter: Fabiano Tarlao > Priority: Major > Labels: easyfix > Fix For: 1.0.2, 1.1.1 > > Attachments: KrbClientTest.java, bug1.diff, bug2.diff > > > Two bugs that interact each other > h1. 1) > *SgtTicket*, returned by *KrbClient.requestSgt(..)*, has a _null_ *client= Principal* field (unassigned). Perhaps this is not mandatory but your code = assumes this property is populated (see later). I highly suggest to populat= e this field. > I have wrote a workaround that overrides the=C2=A0*requestSgt* method and= works for the *USE_TGT* case (the real complete fix is on GitHub,in a set = of subsequent pull requests :) ): > =C2=A0 > {code:java} > @Override > =C2=A0=C2=A0=C2=A0 public SgtTicket requestSgt(KOptions requestOptions) t= hrows KrbException { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SgtTicket requestSgt =3D super= .requestSgt(requestOptions);=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 TgtTicket tgt =3D (TgtTicket) = requestOptions.getOptionValue(KrbOption.USE_TGT); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(tgt !=3D null){ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 reques= tSgt.setClientPrincipal(tgt.getClientPrincipal()); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return requestSgt; > =C2=A0=C2=A0=C2=A0 }{code} > =C2=A0 > h1. 2) > Creating a new credential cache file when storing only one SGT (service t= icket) fails. (i.e., trying to create a new cache file containing only one = SGT and no TGT) > Invoking *KrbClient.storeTicket(sgtTicket, File)* fails for this reason (= here is the original code in *KrbClientBase* class, my comments in RED ): > {{public void storeTicket(SgtTicket sgtTicket, File ccacheFile) throws Kr= bException {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG.info("Storing the sgt t= o the credential cache file.");}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!ccacheFile.exists()) {= }} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cre= ateCacheFile(ccacheFile);{color:#ff0000} //Correctly creates a new file but= ...{color}}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ccacheFile.exists() && = ccacheFile.canWrite()) {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Cre= dentialCache cCache =3D new CredentialCache();}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try= {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.load(ccacheFile);{color:#ff0000} //..this line= EXPLODES cause it tries to initialize from an empty file, the unexistent f= ile case is not managed correctly{color}}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.addCredential(new Credential(sgtTicket, sgtTic= ket.getClientPrincipal()));}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.setPrimaryPrincipal(sgtTicket.getClientPrincip= al());}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.store(ccacheFile);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } c= atch (IOException e) {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 throw new KrbException("Failed to store sgt", e);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 thr= ow new IllegalArgumentException("Invalid ccache file, "}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 + "not exist or writable: " += ccacheFile.getAbsolutePath());}} > {{}}} > Here follows my proposal/fix, this code correctly manages the MIT ccache = file creation for one SGT, please note that this fix assumes that bug 1 is = already fixed: > =C2=A0 > {code:java} > public void storeTicket(SgtTicket sgtTicket, File ccacheFile) throws KrbE= xception { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG.info("Storing the sgt to t= he credential cache file."); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 boolean isFreshNew =3D !ccache= File.exists() || (ccacheFile.length() =3D=3D 0); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (isFreshNew) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 create= CacheFile(ccacheFile); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ccacheFile.exists() && cca= cheFile.canWrite()) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 CredentialCache cCache; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 if (!isFreshNew) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache =3D new CredentialCache()= ;=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.load(ccacheFile); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.addCredential(new Credent= ial(sgtTicket, sgtTicket.getClientPrincipal())); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 } else { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 //Remind: contructor sets the cC= ache client principal from the sgtTicket one > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache =3D new CredentialCache(s= gtTicket); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 cCache.store(ccacheFile); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } catc= h (IOException e) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 throw new KrbException("Failed to store sgt", e); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 throw = new IllegalArgumentException("Invalid ccache file, " > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 + "not exist or writable: " + cc= acheFile.getAbsolutePath()); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0 } > {code} > =C2=A0 > Please note that *YOUR CredentialCache contructor assumes the clientPrinc= ipal is populated* ;) > Hope useful, > regards > Fabiano > P.s: Attached two paches for the project, bug2.diff for bug 2 is..*I thin= k.. production ready*. > bug1.diff for bug 1 is untested.. I ported the modification of my overrid= ing method to the *AbstractInternalKrbClient.requestSgt()* method. But I ha= ve not performed run/test of modules, your project is big and needs time to= manage well. *BUT* is this the right solution? or SHOULD the *clientPrinci= pal* be already populated from the doRequestSgt method? I suggest to look f= or a solution at a deeper level starting from *DefaultInternalKrbClient*. C= onsider bug1.diff a fair workaround. > P.s.2:Added a pull request on GitHub > Regards -- This message was sent by Atlassian JIRA (v7.6.3#76005)