private boolean setupKerberosKeys ( ) { if ( kerberosKeys != null ) { return true ; } try { final AccessControlContext acc = getAccSE ( ) ; kerberosKeys = AccessController . doPrivileged ( // Eliminate dependency on KerberosKey new PrivilegedExceptionAction < SecretKey [ ] > ( ) { public SecretKey [ ] run ( ) throws Exception { // get kerberos key for the default principal return Krb5Helper . getServerKeys ( acc ) ; } } ) ; // check permission to access and use the secret key of the // Kerberized "host" service if ( kerberosKeys != null && kerberosKeys . length > 0 ) { if ( debug != null && Debug . isOn ( "handshake" ) ) { for ( SecretKey k : kerberosKeys ) { System . out . println ( "Using Kerberos key: " + k ) ; } } String serverPrincipal = Krb5Helper . getServerPrincipalName ( kerberosKeys [ 0 ] ) ; SecurityManager sm = System . getSecurityManager ( ) ; try { if ( sm != null ) { // Eliminate dependency on ServicePermission sm . checkPermission ( Krb5Helper . getServicePermission ( serverPrincipal , "accept" ) , acc ) ; } } catch ( SecurityException se ) { kerberosKeys = null ; // %%% destroy keys? or will that affect Subject? if ( debug != null && Debug . isOn ( "handshake" ) ) System . out . println ( "Permission to access Kerberos" + " secret key denied" ) ; return false ; } } return ( kerberosKeys != null && kerberosKeys . length > 0 ) ; } catch ( PrivilegedActionException e ) { // Likely exception here is LoginExceptin if ( debug != null && Debug . isOn ( "handshake" ) ) { System . out . println ( "Attempt to obtain Kerberos key failed: " + e . toString ( ) ) ; } return false ; } }
Retrieve the Kerberos key for the specified server principal from the JAAS configuration file .