001/* 002 * (C) Copyright 2006-2013 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 */ 017 018package org.nuxeo.ecm.platform.ui.web.auth; 019 020import org.nuxeo.ecm.core.api.NuxeoException; 021import org.nuxeo.ecm.platform.ui.web.auth.service.LoginProviderLinkComputer; 022import org.nuxeo.ecm.platform.ui.web.auth.service.LoginScreenConfig; 023import org.nuxeo.ecm.platform.ui.web.auth.service.PluggableAuthenticationService; 024import org.nuxeo.runtime.api.Framework; 025 026/** 027 * Simple helper class for easy access form the login.jsp page 028 * 029 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 030 * @since 5.7 031 */ 032public class LoginScreenHelper { 033 034 public static LoginScreenConfig getConfig() { 035 PluggableAuthenticationService authService = (PluggableAuthenticationService) Framework.getRuntime().getComponent( 036 PluggableAuthenticationService.NAME); 037 return authService.getLoginScreenConfig(); 038 } 039 040 public static void registerLoginProvider(String name, String iconUrl, String link, String label, 041 String description, LoginProviderLinkComputer computer) { 042 043 LoginScreenConfig config = getConfig(); 044 if (config != null) { 045 config.registerLoginProvider(name, iconUrl, link, label, description, computer); 046 } else { 047 throw new NuxeoException("There is no available LoginScreen config"); 048 } 049 } 050 051 public static String getValueWithDefault(String value, String defaultValue) { 052 if (value == null || value.isEmpty()) { 053 return defaultValue; 054 } 055 return value; 056 } 057 058}