{
if (requestDispatcher == null)
throw new NullPointerException("null dispatcher is passed in");
KerberosKey serverKey;
GSSCredential serverCred;
try {
// make sure that serverPrincipal is in serverSubject
if (serverSubject != null &&
!serverSubject.getPrincipals().contains(serverPrincipal))
{
throw new UnsupportedConstraintException(
"Failed to find serverPrincipal " + serverPrincipal +
"in serverSubject's principal set, cannot listen.");
}
// getKey checks AuthenticationPermission "listen"
serverKey = getKey(serverSubject, serverPrincipal);
if (serverKey == null) {
throw new UnsupportedConstraintException(
"No valid Kerberos key in the server subject for " +
serverPrincipal + ", cannot listen.");
}
synchronized (classLock) {
if (gssManager == null) {
gssManager = GSSManager.getInstance();
}
}
try {
serverCred = (GSSCredential) Security.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws GSSException {
return KerberosUtil.getGSSCredential(
serverSubject, serverPrincipal,
gssManager, GSSCredential.ACCEPT_ONLY);
}
});
} catch (PrivilegedActionException pe) {
GSSException ge = (GSSException) pe.getException();
throw new UnsupportedConstraintException(
"Failed to get GSSCredential for server principal: " +
serverPrincipal, ge);
}
} catch (UnsupportedConstraintException uce) {
if (logger.isLoggable(Levels.FAILED)) {
KerberosUtil.logThrow(
logger, Levels.FAILED, this.getClass(),
"listen", "listen for {0}\nthrows",
new Object[] {this}, uce);
}
throw uce;
} catch (SecurityException se) {
if (logger.isLoggable(Levels.FAILED)) {
KerberosUtil.logThrow(
logger, Levels.FAILED, this.getClass(),
"listen", "listen for {0}\nthrows",
new Object[] {this}, se);
}
throw se;
}
ServerSocket serverSocket;
boolean done = false;
try {
if (ssf != null) {
serverSocket = ssf.createServerSocket(port);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "created {0} using factory " +
"{1}", new Object[]{serverSocket, ssf});
}
} else {
serverSocket = new ServerSocket(port);
logger.log(Level.FINE, "created {0}", serverSocket);
}
done = true;
} finally {
if (!done) {
try {
serverCred.dispose();
} catch (GSSException e) {}
}
}
ListenHandleImpl listenHandle = new ListenHandleImpl(