Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. */
  20. package org.apache.directory.kerberos.client;
  21.  
  22. import java.io.File;
  23. import java.util.Collections;
  24.  
  25. import org.apache.directory.server.kerberos.shared.keytab.Keytab;
  26. import org.apache.directory.server.kerberos.shared.keytab.KeytabEntry;
  27. import org.apache.directory.shared.kerberos.KerberosTime;
  28. import org.apache.directory.shared.kerberos.codec.types.PrincipalNameType;
  29.  
  30. /**
  31. * Creates a Keytab from the TgTicket.
  32. *
  33. * @author <a href="mailto:kayyagari@keydap.com">Kiran Ayyagari</a>
  34. */
  35. public class KeytabMaker
  36. {
  37. public static void main( String[] args ) throws Exception
  38. {
  39. KdcConfig config = new KdcConfig();
  40. config.setKdcPort( 60088 );
  41.  
  42. KdcConnection kdcCon = new KdcConnection( config );
  43. TgTicket tgt = kdcCon.getTgt( "hnelson@EXAMPLE.COM", "secret" );
  44.  
  45. Keytab kt = new Keytab();
  46. KeytabEntry ke = new KeytabEntry( tgt.getClientName()+"@"+tgt.getRealm(), PrincipalNameType.KRB_NT_PRINCIPAL.getValue(),
  47. new KerberosTime( tgt.getStartTime() ), (byte)tgt.getSessionKey().getKeyVersion(), tgt.getSessionKey() );
  48.  
  49. kt.setEntries( Collections.singletonList( ke ) );
  50.  
  51.  
  52. kt.write( new File("/tmp/apachedskeytab") );
  53.  
  54. // KeytabEncoder encoder = new KeytabEncoder();
  55. // ByteBuffer buf = encoder.write( kt.getKeytabVersion(), kt.getEntries() );
  56. // System.out.println(Strings.dumpBytes( buf.array() ));
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement