001/*
002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 * Contributors:
016 *     Nuxeo - initial API and implementation
017 */
018
019package org.nuxeo.ecm.platform.shibboleth.auth.exceptionhandling;
020
021import javax.servlet.http.HttpServletRequest;
022
023import org.apache.commons.logging.Log;
024import org.apache.commons.logging.LogFactory;
025import org.nuxeo.ecm.platform.shibboleth.service.ShibbolethAuthenticationService;
026import org.nuxeo.ecm.platform.web.common.exceptionhandling.DefaultNuxeoExceptionHandler;
027import org.nuxeo.runtime.api.Framework;
028
029/**
030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
031 */
032public class ShibbolethSecurityExceptionHandler extends DefaultNuxeoExceptionHandler {
033
034    private static final Log log = LogFactory.getLog(ShibbolethSecurityExceptionHandler.class);
035
036    @Override
037    public String getLoginURL(HttpServletRequest request) {
038        ShibbolethAuthenticationService shibService = Framework.getService(ShibbolethAuthenticationService.class);
039        if (shibService == null) {
040            return null;
041        }
042        String loginURL = shibService.getLoginURL(request);
043        if (loginURL == null) {
044            log.error("Unable to handle Shibboleth login, no loginURL registered");
045            return null;
046        }
047        return loginURL;
048    }
049
050}