001/*
002 * (C) Copyright 2006-2013 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 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 */
019
020package org.nuxeo.ecm.platform.ui.web.auth;
021
022import org.nuxeo.ecm.core.api.NuxeoException;
023import org.nuxeo.ecm.platform.ui.web.auth.service.LoginProviderLinkComputer;
024import org.nuxeo.ecm.platform.ui.web.auth.service.LoginScreenConfig;
025import org.nuxeo.ecm.platform.ui.web.auth.service.PluggableAuthenticationService;
026import org.nuxeo.runtime.api.Framework;
027
028/**
029 * Simple helper class for easy access form the login.jsp page
030 *
031 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
032 * @since 5.7
033 */
034public class LoginScreenHelper {
035
036    public static LoginScreenConfig getConfig() {
037        PluggableAuthenticationService authService = (PluggableAuthenticationService) Framework.getRuntime().getComponent(
038                PluggableAuthenticationService.NAME);
039        return authService.getLoginScreenConfig();
040    }
041
042    public static void registerLoginProvider(String name, String iconUrl, String link, String label,
043            String description, LoginProviderLinkComputer computer) {
044
045        LoginScreenConfig config = getConfig();
046        if (config != null) {
047            config.registerLoginProvider(name, iconUrl, link, label, description, computer);
048        } else {
049            throw new NuxeoException("There is no available LoginScreen config");
050        }
051    }
052
053    public static String getValueWithDefault(String value, String defaultValue) {
054        if (value == null || value.isEmpty()) {
055            return defaultValue;
056        }
057        return value;
058    }
059
060}