Merge pull request #2782 from lachlan-roberts/jetty-9.4.x-321-JaspiAuthenticatorFactory-DeadCode

Issue #321 - jaspi authenticator factory dead code
This commit is contained in:
Greg Wilkins 2018-08-10 12:44:07 +10:00 committed by GitHub
commit 82264bccb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 15 deletions

View File

@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.security.auth.Subject; import javax.security.auth.Subject;
import javax.security.auth.message.AuthException; import javax.security.auth.message.AuthException;
import javax.security.auth.message.config.AuthConfigFactory; import javax.security.auth.message.config.AuthConfigFactory;
@ -95,20 +94,16 @@ public class JaspiAuthenticatorFactory extends DefaultAuthenticatorFactory
try try
{ {
AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory(); AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
RegistrationListener listener = new RegistrationListener() RegistrationListener listener = (layer, appContext) -> {};
{
@Override
public void notify(String layer, String appContext)
{}
};
Subject serviceSubject=findServiceSubject(server); Subject serviceSubject=findServiceSubject(server);
String serverName=findServerName(server,serviceSubject); String serverName=findServerName(server, serviceSubject);
String contextPath=context.getContextPath(); String contextPath=context.getContextPath();
if (contextPath==null || contextPath.length()==0) if (contextPath==null || contextPath.length()==0)
contextPath="/"; contextPath="/";
String appContext = serverName + " " + context.getContextPath(); String appContext = serverName + " " + contextPath;
AuthConfigProvider authConfigProvider = authConfigFactory.getConfigProvider(MESSAGE_LAYER,appContext,listener); AuthConfigProvider authConfigProvider = authConfigFactory.getConfigProvider(MESSAGE_LAYER,appContext,listener);
if (authConfigProvider != null) if (authConfigProvider != null)
@ -146,7 +141,7 @@ public class JaspiAuthenticatorFactory extends DefaultAuthenticatorFactory
return _serviceSubject; return _serviceSubject;
List<Subject> subjects = (List<Subject>)server.getBeans(Subject.class); List<Subject> subjects = (List<Subject>)server.getBeans(Subject.class);
if (subjects.size()>0) if (subjects.size()>0)
return (Subject)subjects.get(0); return subjects.get(0);
return null; return null;
} }
@ -155,14 +150,15 @@ public class JaspiAuthenticatorFactory extends DefaultAuthenticatorFactory
* If {@link #setServerName(String)} has not been called, then * If {@link #setServerName(String)} has not been called, then
* use the name of the a principal in the service subject. * use the name of the a principal in the service subject.
* If not found, return "server". * If not found, return "server".
* @param server not used * @param server the server to find the name of
* @param subject the subject to use * @return the server name from the service Subject (or default value if not found in subject or principals)
* @return the server name from the subject (or default value if not found in subject or principals)
*/ */
protected String findServerName(Server server, Subject subject) protected String findServerName(Server server)
{ {
if (_serverName!=null) if (_serverName!=null)
return _serverName; return _serverName;
Subject subject = findServiceSubject(server);
if (subject!=null) if (subject!=null)
{ {
Set<Principal> principals = subject.getPrincipals(); Set<Principal> principals = subject.getPrincipals();
@ -172,4 +168,19 @@ public class JaspiAuthenticatorFactory extends DefaultAuthenticatorFactory
return "server"; return "server";
} }
/* ------------------------------------------------------------ */
/** Find a servername.
* If {@link #setServerName(String)} has not been called, then
* use the name of the a principal in the service subject.
* If not found, return "server".
* @param server the server to use
* @param subject not used
* @return the server name from the subject of the server (or default value if not found in subject or principals)
*/
@Deprecated
protected String findServerName(Server server, Subject subject)
{
return findServerName(server);
}
} }