Minor code cleanups

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@934167 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2010-04-14 20:06:52 +00:00
parent 056b249b0b
commit 6054dd897d
1 changed files with 18 additions and 20 deletions

View File

@ -44,26 +44,28 @@ import org.bouncycastle.asn1.util.ASN1Dump;
/** /**
* Takes Kerberos ticket and wraps into a SPNEGO token. Leaving some optional fields out. * Takes Kerberos ticket and wraps into a SPNEGO token. Leaving some optional fields out.
* Uses bouncycastle libs need a bcprov.jar
*/ */
public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator { public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
private static final Log LOG = LogFactory.getLog(BouncySpnegoTokenGenerator.class);
private DERObjectIdentifier spnegoOid = new DERObjectIdentifier("1.3.6.1.5.5.2"); private final Log log = LogFactory.getLog(getClass());
private DERObjectIdentifier kerbOid = new DERObjectIdentifier("1.2.840.113554.1.2.2");
private final DERObjectIdentifier spnegoOid;
private final DERObjectIdentifier kerbOid;
public BouncySpnegoTokenGenerator() {
super();
this.spnegoOid = new DERObjectIdentifier("1.3.6.1.5.5.2");
this.kerbOid = new DERObjectIdentifier("1.2.840.113554.1.2.2");
}
public byte [] generateSpnegoDERObject(byte [] kerbTicket) throws IOException { public byte [] generateSpnegoDERObject(byte [] kerbTicket) throws IOException {
LOG.debug("enter: generateSpnegoDERObject(byte [] kerbTicket)");
DEROctetString ourKerberosTicket = new DEROctetString(kerbTicket); DEROctetString ourKerberosTicket = new DEROctetString(kerbTicket);
DERSequence kerbOidSeq = new DERSequence(kerbOid); DERSequence kerbOidSeq = new DERSequence(kerbOid);
DERTaggedObject tagged0 = new DERTaggedObject(0, kerbOidSeq); DERTaggedObject tagged0 = new DERTaggedObject(0, kerbOidSeq);
// DERBitString bits = new DERBitString(new byte[]{0x01});
// DERTaggedObject tagged1 = new DERTaggedObject(1, bits);
DERTaggedObject tagged2 = new DERTaggedObject(2, ourKerberosTicket); DERTaggedObject tagged2 = new DERTaggedObject(2, ourKerberosTicket);
ASN1EncodableVector v = new ASN1EncodableVector(); ASN1EncodableVector v = new ASN1EncodableVector();
v.add(tagged0); v.add(tagged0);
// v.add(tagged1);
v.add(tagged2); v.add(tagged2);
DERSequence seq = new DERSequence(v); DERSequence seq = new DERSequence(v);
DERTaggedObject taggedSpnego = new DERTaggedObject(0, seq); DERTaggedObject taggedSpnego = new DERTaggedObject(0, seq);
@ -90,8 +92,14 @@ public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
byte[] app = out.toByteArray(); byte[] app = out.toByteArray();
ASN1InputStream in = new ASN1InputStream(app); ASN1InputStream in = new ASN1InputStream(app);
if( LOG.isDebugEnabled() ){ if (log.isDebugEnabled() ){
dumpToken(app); int skip = 12;
byte [] manipBytes = new byte[app.length - skip];
for(int i=skip; i < app.length; i++){
manipBytes[i-skip] = app[i];
}
ASN1InputStream ourSpnego = new ASN1InputStream( manipBytes );
log.debug(ASN1Dump.dumpAsString(ourSpnego.readObject()));
} }
return in.readObject().getDEREncoded(); return in.readObject().getDEREncoded();
@ -118,14 +126,4 @@ public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
return out.toByteArray(); return out.toByteArray();
} }
protected void dumpToken(byte [] token) throws IOException{
int skip = 12;
byte [] manipBytes = new byte[token.length - skip];
for(int i=skip; i < token.length; i++){
manipBytes[i-skip] = token[i];
}
ASN1InputStream ourSpnego = new ASN1InputStream( manipBytes );
System.out.println(ASN1Dump.dumpAsString( ourSpnego.readObject() ) );
}
} }