net.jini.jeri.ssl
Class ServerAuthManager

java.lang.Object
  extended by net.jini.jeri.ssl.Utilities
      extended by net.jini.jeri.ssl.FilterX509TrustManager
          extended by net.jini.jeri.ssl.AuthManager
              extended by net.jini.jeri.ssl.ServerAuthManager
All Implemented Interfaces:
KeyManager, TrustManager, X509KeyManager, X509TrustManager

 class ServerAuthManager
extends AuthManager

An AuthManager for servers. Invalidates sessions when a new key is returned of a particular key type.

Author:
Sun Microsystems, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from class net.jini.jeri.ssl.Utilities
Utilities.SSLContextInfo
 
Field Summary
private  Map credentialCache
          Maps a key type to last private credentials returned for that key type, or a String describing problems that prevented getting private credentials.
private  long credentialsValidUntil
          The time when the credentials for the session in the session cache become invalid.
private static Logger logger
          Server transport logger
private  X500PrivateCredential[] readOnlyPrivateCredentials
          The subject's private credentials, if the subject is read-only.
private  Reference sessionCache
          The SSL session for the last successful call to checkCredentials.
private  SSLSessionContext sslSessionContext
          The SSLSessionContext for all connections.
 
Fields inherited from class net.jini.jeri.ssl.AuthManager
subjectIsReadOnly
 
Fields inherited from class net.jini.jeri.ssl.Utilities
ANY_KEY_ALGORITHM, clientLogger, DSA_KEY_ALGORITHM, getSubjectPermission, initLogger, INTEGRITY_PREFERRED, INTEGRITY_REQUIRED, RSA_KEY_ALGORITHM, serverLogger, UNKNOWN_PRINCIPAL
 
Constructor Summary
ServerAuthManager(Subject subject, Set permittedPrincipals, SSLSessionContext sslSessionContext)
          Creates an AuthManager that retrieves principals and credentials for authentication from the specified subject.
 
Method Summary
(package private)  void checkCredentials(SSLSession session, Subject clientSubject)
          Checks if the server subject still contains the proper credentials to use the specified session.
private  long checkCredentials(X500PrivateCredential cred, Subject clientSubject, String permissionAction)
          Checks that the principals and credentials associated with the specified private credential are present and valid in the server subject, and that the caller has permission to access them given the specified client subject and permission action.
 String chooseClientAlias(String[] keyTypes, Principal[] issuers, Socket socket)
           
 String chooseServerAlias(String keyType, Principal[] issuers, Socket socket)
          Returns the last server credential selected for this key type, if still usable.
private  AuthenticationPermission getAuthPermission(X509Certificate cert, String peer, String action)
          Returns the authentication permission for the specified principals and action.
 String[] getClientAliases(String keyType, Principal[] issuers)
           
(package private)  Logger getLogger()
          Returns the server logger
private  String getPeerPrincipalName(Subject peerSubject)
          Returns the name of the principal for the peer subject, which should be read-only if it is not null.
(package private)  X500PrivateCredential getPrivateCredential(X509Certificate cert)
          Gets the private credential for the specified X.509 certificate, checking for AuthenticationPermission to listen for the specified local principal and all peers.
private  X500PrivateCredential getPrivateCredential(X509Certificate cert, String peer, String permissionAction)
          Checks for AuthenticationPermission to accept for the specified local and peer principals.
 String[] getServerAliases(String keyType, Principal[] issuers)
           
(package private)  X509Certificate getServerCertificate(SSLSession session)
          Returns the principal that the server used to authenticate for the specified session.
 
Methods inherited from class net.jini.jeri.ssl.AuthManager
certificatesValidUntil, certificatesValidUntil, chooseCredential, equalPrivateCredentials, getAliases, getCertificateChain, getPrivateKey, getSubject
 
Methods inherited from class net.jini.jeri.ssl.FilterX509TrustManager
checkClientTrusted, checkServerTrusted, getAcceptedIssuers, setPermittedRemotePrincipals
 
Methods inherited from class net.jini.jeri.ssl.Utilities
checkValidity, contains, doesEncryption, doesServerAuthentication, equals, firstX509Cert, getCertFactory, getCipherAlgorithm, getClassName, getClientPrincipals, getClientPrincipals, getClientSSLContextInfo, getKeyAlgorithm, getKeyExchangeAlgorithm, getPermittedKeyAlgorithms, getServerPrincipals, getServerSSLContextInfo, getSupportedCipherSuites, hasStrongCipherAlgorithm, logThrow, maintainsIntegrity, permittedKeyAlgorithm, position, releaseClientSSLContextInfo, safeEquals, subjectString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final Logger logger
Server transport logger


sslSessionContext

private final SSLSessionContext sslSessionContext
The SSLSessionContext for all connections.


readOnlyPrivateCredentials

private final X500PrivateCredential[] readOnlyPrivateCredentials
The subject's private credentials, if the subject is read-only.


credentialCache

private final Map credentialCache
Maps a key type to last private credentials returned for that key type, or a String describing problems that prevented getting private credentials.


sessionCache

private Reference sessionCache
The SSL session for the last successful call to checkCredentials.


credentialsValidUntil

private long credentialsValidUntil
The time when the credentials for the session in the session cache become invalid.

Constructor Detail

ServerAuthManager

ServerAuthManager(Subject subject,
                  Set permittedPrincipals,
                  SSLSessionContext sslSessionContext)
            throws NoSuchAlgorithmException
Creates an AuthManager that retrieves principals and credentials for authentication from the specified subject.

Parameters:
subject - the subject for retrieving principals and credentials
Throws:
NoSuchAlgorithmException - if the trust manager factory algorithm is not found
Method Detail

getServerCertificate

X509Certificate getServerCertificate(SSLSession session)
Returns the principal that the server used to authenticate for the specified session. Returns null if the session is not found or if the server did not authenticate itself.


checkCredentials

void checkCredentials(SSLSession session,
                      Subject clientSubject)
                throws GeneralSecurityException
Checks if the server subject still contains the proper credentials to use the specified session. Uses the credential cache to find the credentials for sessions with this session's key type. Callers should only call this method if server authentication is being used.

Parameters:
session - the session to check
clientSubject - the client subject for the connection, which should be read-only if it is not null
Throws:
GeneralSecurityException - if there is a problem with the credentials
SecurityException - if the current access control context does not have the proper AuthenticationPermission or if the subject does not contain the proper credentials

checkCredentials

private long checkCredentials(X500PrivateCredential cred,
                              Subject clientSubject,
                              String permissionAction)
Checks that the principals and credentials associated with the specified private credential are present and valid in the server subject, and that the caller has permission to access them given the specified client subject and permission action. Returns the time until which the certificates are valid if successful, otherwise throws SecurityException. The clientSubject should be read-only if it is not null.


getPeerPrincipalName

private String getPeerPrincipalName(Subject peerSubject)
Returns the name of the principal for the peer subject, which should be read-only if it is not null.


getLogger

Logger getLogger()
Returns the server logger

Specified by:
getLogger in class AuthManager

getPrivateCredential

X500PrivateCredential getPrivateCredential(X509Certificate cert)
Gets the private credential for the specified X.509 certificate, checking for AuthenticationPermission to listen for the specified local principal and all peers.

Specified by:
getPrivateCredential in class AuthManager
Parameters:
cert - the certificate for the local principal
Returns:
the associated private credential or null if not found
Throws:
SecurityException - if the current access control context does not have the proper AuthenticationPermission

getPrivateCredential

private X500PrivateCredential getPrivateCredential(X509Certificate cert,
                                                   String peer,
                                                   String permissionAction)
Checks for AuthenticationPermission to accept for the specified local and peer principals. The peer is specified as a String to avoid needing to use the separate X.509 certificate type that JSSE uses for peer certificate chains.

Parameters:
cert - the certificate for the local principal
peer - the name of the peer principal or null if not known
permissionAction - the AuthenticationPermission action
Returns:
the associated private credential or null if not found
Throws:
SecurityException - if the current access control context does not have the proper AuthenticationPermission

getAuthPermission

private AuthenticationPermission getAuthPermission(X509Certificate cert,
                                                   String peer,
                                                   String action)
Returns the authentication permission for the specified principals and action.


getClientAliases

public String[] getClientAliases(String keyType,
                                 Principal[] issuers)

getServerAliases

public String[] getServerAliases(String keyType,
                                 Principal[] issuers)

chooseClientAlias

public String chooseClientAlias(String[] keyTypes,
                                Principal[] issuers,
                                Socket socket)

chooseServerAlias

public String chooseServerAlias(String keyType,
                                Principal[] issuers,
                                Socket socket)
Returns the last server credential selected for this key type, if still usable. If not, then invalidate all sessions with the same key type and attempt to find another key.



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.