Search in sources :

Example 1 with RemoteUserMapper

use of org.alfresco.repo.security.authentication.external.RemoteUserMapper in project acs-community-packaging by Alfresco.

the class AuthenticationHelper method getRemoteUserMapper.

/**
 * Gets the remote user mapper if one is configured and active (i.e. external authentication is in use).
 * @param sc
 *           the servlet context
 * @return the remote user mapper if one is configured and active; otherwise <code>null</code>
 */
public static RemoteUserMapper getRemoteUserMapper(final ServletContext sc) {
    final WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
    RemoteUserMapper remoteUserMapper = (RemoteUserMapper) wc.getBean(REMOTE_USER_MAPPER);
    if (remoteUserMapper != null && !(remoteUserMapper instanceof ActivateableBean) || ((ActivateableBean) remoteUserMapper).isActive()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Remote user mapper configured and active.");
        }
        return remoteUserMapper;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("No active remote user mapper.");
    }
    return null;
}
Also used : RemoteUserMapper(org.alfresco.repo.security.authentication.external.RemoteUserMapper) ActivateableBean(org.alfresco.repo.management.subsystems.ActivateableBean) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 2 with RemoteUserMapper

use of org.alfresco.repo.security.authentication.external.RemoteUserMapper in project acs-community-packaging by Alfresco.

the class AuthenticationHelper method getRemoteUser.

/**
 * Uses the remote user mapper, if one is configured, to extract a user ID from the request
 *
 * @param sc
 *           the servlet context
 * @param httpRequest
 *           The HTTP request
 * @return the user ID if a user has been externally authenticated or <code>null</code> otherwise.
 */
public static String getRemoteUser(final ServletContext sc, final HttpServletRequest httpRequest) {
    String userId = null;
    // If the remote user mapper is configured, we may be able to map in an externally authenticated user
    RemoteUserMapper remoteUserMapper = getRemoteUserMapper(sc);
    if (remoteUserMapper != null) {
        userId = remoteUserMapper.getRemoteUser(httpRequest);
    }
    if (logger.isDebugEnabled()) {
        if (userId == null) {
            logger.debug("No external user ID in request.");
        } else {
            logger.debug("Extracted external user ID from request: " + userId);
        }
    }
    return userId;
}
Also used : RemoteUserMapper(org.alfresco.repo.security.authentication.external.RemoteUserMapper)

Aggregations

RemoteUserMapper (org.alfresco.repo.security.authentication.external.RemoteUserMapper)2 ActivateableBean (org.alfresco.repo.management.subsystems.ActivateableBean)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1