package edu.internet2.middleware.shibboleth.idp.profile;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.Timer;
import java.util.concurrent.locks.Lock;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
-import org.apache.log4j.Logger;
-import org.opensaml.util.resource.Resource;
-import org.opensaml.xml.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import edu.internet2.middleware.shibboleth.common.config.BaseReloadableService;
import edu.internet2.middleware.shibboleth.common.profile.ProfileHandlerManager;
import edu.internet2.middleware.shibboleth.common.profile.provider.AbstractRequestURIMappedProfileHandler;
import edu.internet2.middleware.shibboleth.idp.authn.LoginHandler;
-import edu.internet2.middleware.shibboleth.idp.authn.LoginContext;
/**
* Implementation of a {@link ProfileHandlerManager} that maps the request path, without the servlet context, to a
public class IdPProfileHandlerManager extends BaseReloadableService implements ProfileHandlerManager {
/** Class logger. */
- private final Logger log = Logger.getLogger(IdPProfileHandlerManager.class);
+ private final Logger log = LoggerFactory.getLogger(IdPProfileHandlerManager.class);
/** Handler used for errors. */
private AbstractErrorHandler errorHandler;
/** Map of request paths to profile handlers. */
private Map<String, AbstractRequestURIMappedProfileHandler> profileHandlers;
- /** Map of authentication methods to authentication handlers. */
- private Map<String, LoginHandler> authenticationHandlers;
+ /** Map of authentication methods to login handlers. */
+ private Map<String, LoginHandler> loginHandlers;
- /**
- * Constructor. Configuration resources are not monitored for changes.
- *
- * @param configurations configuration resources for this service
- */
- public IdPProfileHandlerManager(List<Resource> configurations) {
- super(configurations);
- profileHandlers = new HashMap<String, AbstractRequestURIMappedProfileHandler>();
- authenticationHandlers = new HashMap<String, LoginHandler>();
- }
-
- /**
- * Constructor.
- *
- * @param timer timer resource polling tasks are scheduled with
- * @param configurations configuration resources for this service
- * @param pollingFrequency the frequency, in milliseconds, to poll the policy resources for changes, must be greater
- * than zero
- */
- public IdPProfileHandlerManager(List<Resource> configurations, Timer timer, long pollingFrequency) {
- super(timer, configurations, pollingFrequency);
+ /** Constructor. */
+ public IdPProfileHandlerManager() {
+ super();
profileHandlers = new HashMap<String, AbstractRequestURIMappedProfileHandler>();
- authenticationHandlers = new HashMap<String, LoginHandler>();
+ loginHandlers = new HashMap<String, LoginHandler>();
}
/** {@inheritDoc} */
ProfileHandler handler;
String requestPath = ((HttpServletRequest) request).getPathInfo();
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Looking up profile handler for request path: " + requestPath);
- }
+ log.debug("{}: Looking up profile handler for request path: {}", getId(), requestPath);
+
Lock readLock = getReadWriteLock().readLock();
readLock.lock();
handler = profileHandlers.get(requestPath);
readLock.unlock();
if (handler != null) {
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Located profile handler of the following type for request path "
- + requestPath + ": " + handler.getClass().getName());
- }
+ log.debug("{}: Located profile handler of the following type for the request path: {}", getId(), handler
+ .getClass().getName());
} else {
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": No profile handler registered for request path " + requestPath);
- }
+ log.debug("{}: No profile handler registered for request path {}", getId(), requestPath);
}
return handler;
}
}
/**
- * Gets the authentication handler appropriate for the given loging context. The mechanism used to determine the
- * "appropriate" handler is implementation specific.
- *
- * @param loginContext current login context
- *
- * @return authentication method URI and handler appropriate for given login context
- */
- public Pair<String, LoginHandler> getAuthenticationHandler(LoginContext loginContext) {
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Looking up authentication method for relying party "
- + loginContext.getRelyingPartyId());
- }
- List<String> requestedMethods = loginContext.getRequestedAuthenticationMethods();
- if (requestedMethods != null) {
- LoginHandler candidateHandler;
- for (String requestedMethod : requestedMethods) {
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Checking for authentication handler for method " + requestedMethod
- + " which was requested for relying party " + loginContext.getRelyingPartyId());
- }
- candidateHandler = authenticationHandlers.get(requestedMethod);
- if (candidateHandler != null) {
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Authentication handler for method " + requestedMethod
- + " for relying party " + loginContext.getRelyingPartyId()
- + " found. Checking if it meets othe criteria.");
- }
- if(loginContext.getPassiveAuth() && !candidateHandler.supportsPassive()){
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Authentication handler for method " + requestedMethod
- + " for relying party " + loginContext.getRelyingPartyId()
- + " does not meet required support for passive auth. Skipping it");
- }
- continue;
- }
-
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Authentication handler for method " + requestedMethod
- + " for relying party " + loginContext.getRelyingPartyId()
- + " meets all requirements, using it.");
- }
- return new Pair<String, LoginHandler>(requestedMethod, candidateHandler);
- }
- }
- } else {
- log.error(getId() + ": No requested authentication methods for relying party "
- + loginContext.getRelyingPartyId());
- }
-
- return null;
- }
-
- /**
* Gets the registered authentication handlers.
*
* @return registered authentication handlers
*/
- public Map<String, LoginHandler> getAuthenticationHandlers() {
- return authenticationHandlers;
+ public Map<String, LoginHandler> getLoginHandlers() {
+ return loginHandlers;
}
/** {@inheritDoc} */
- protected void newContextCreated(ApplicationContext newServiceContext) {
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Loading new configuration into service");
- }
+ protected void onNewContextCreated(ApplicationContext newServiceContext) {
+ log.debug("{}: Loading new configuration into service", getId());
Lock writeLock = getReadWriteLock().writeLock();
writeLock.lock();
loadNewErrorHandler(newServiceContext);
*/
protected void loadNewErrorHandler(ApplicationContext newServiceContext) {
String[] errorBeanNames = newServiceContext.getBeanNamesForType(AbstractErrorHandler.class);
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Loading " + errorBeanNames.length + " new error handler.");
- }
+ log.debug("{}: Loading {} new error handler.", getId(), errorBeanNames.length);
errorHandler = (AbstractErrorHandler) newServiceContext.getBean(errorBeanNames[0]);
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Loaded new error handler of type: " + errorHandler.getClass().getName());
- }
+ log.debug("{}: Loaded new error handler of type: {}", getId(), errorHandler.getClass().getName());
}
/**
*/
protected void loadNewProfileHandlers(ApplicationContext newServiceContext) {
String[] profileBeanNames = newServiceContext.getBeanNamesForType(AbstractRequestURIMappedProfileHandler.class);
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Loading " + profileBeanNames.length + " new profile handlers.");
- }
+ log.debug("{}: Loading {} new profile handlers.", getId(), profileBeanNames.length);
profileHandlers.clear();
- AbstractRequestURIMappedProfileHandler<?,?> profileHandler;
+ AbstractRequestURIMappedProfileHandler<?, ?> profileHandler;
for (String profileBeanName : profileBeanNames) {
profileHandler = (AbstractRequestURIMappedProfileHandler) newServiceContext.getBean(profileBeanName);
for (String requestPath : profileHandler.getRequestPaths()) {
profileHandlers.put(requestPath, profileHandler);
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Loaded profile handler of type "
- + profileHandler.getClass().getName() + " handling requests to request path "
- + requestPath);
- }
+ log.debug("{}: Loaded profile handler for handling requests to request path {}", getId(), requestPath);
}
}
}
*/
protected void loadNewAuthenticationHandlers(ApplicationContext newServiceContext) {
String[] authnBeanNames = newServiceContext.getBeanNamesForType(LoginHandler.class);
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Loading " + authnBeanNames.length + " new authentication handlers.");
- }
+ log.debug("{}: Loading {} new authentication handlers.", getId(), authnBeanNames.length);
- authenticationHandlers.clear();
+ loginHandlers.clear();
LoginHandler authnHandler;
for (String authnBeanName : authnBeanNames) {
authnHandler = (LoginHandler) newServiceContext.getBean(authnBeanName);
- if (log.isDebugEnabled()) {
- log.debug(getId() + ": Loading authentication handler of type "
- + authnHandler.getClass().getName() + " supporting authentication methods: "
- + authnHandler.getSupportedAuthenticationMethods());
- }
+ log.debug("{}: Loading authentication handler of type supporting authentication methods: {}", getId(),
+ authnHandler.getSupportedAuthenticationMethods());
+
for (String authnMethod : authnHandler.getSupportedAuthenticationMethods()) {
- authenticationHandlers.put(authnMethod, authnHandler);
+ loginHandlers.put(authnMethod, authnHandler);
}
}
}