001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.server.authentication; 021 022import javax.annotation.concurrent.Immutable; 023 024import static com.google.common.base.Preconditions.checkArgument; 025import static org.apache.commons.lang.StringUtils.isNotBlank; 026 027/** 028 * Display information provided by the Identity Provider to be displayed into the login form. 029 * 030 * @since 5.4 031 */ 032@Immutable 033public final class Display { 034 035 private final String iconPath; 036 private final String backgroundColor; 037 038 private Display(Builder builder) { 039 this.iconPath = builder.iconPath; 040 this.backgroundColor = builder.backgroundColor; 041 } 042 043 /** 044 * URL path to the provider icon, as deployed at runtime, for example "/static/authgithub/github.svg" (in this 045 * case "authgithub" is the plugin key. Source file is "src/main/resources/static/github.svg"). 046 * It can also be an external URL, for example "http://www.mydomain/myincon.png". 047 * 048 * Must not be blank. 049 * <p/> 050 * The recommended format is SVG with a size of 24x24 pixels. 051 * Other supported format is PNG, with a size of 40x40 pixels. 052 */ 053 public String getIconPath() { 054 return iconPath; 055 } 056 057 /** 058 * Background color for the provider button displayed in the login form. 059 * It's a Hexadecimal value, for instance #205081. 060 * <p/> 061 * If not provided, the default value is #236a97 062 */ 063 public String getBackgroundColor() { 064 return backgroundColor; 065 } 066 067 public static Builder builder() { 068 return new Builder(); 069 } 070 071 public static class Builder { 072 073 private String iconPath; 074 private String backgroundColor = "#236a97"; 075 076 private Builder() { 077 } 078 079 /** 080 * @see Display#getIconPath() 081 */ 082 public Builder setIconPath(String iconPath) { 083 this.iconPath = iconPath; 084 return this; 085 } 086 087 /** 088 * @see Display#getBackgroundColor() 089 */ 090 public Builder setBackgroundColor(String backgroundColor) { 091 this.backgroundColor = backgroundColor; 092 return this; 093 } 094 095 public Display build() { 096 checkArgument(isNotBlank(iconPath), "Icon path must not be blank"); 097 validateBackgroundColor(); 098 return new Display(this); 099 } 100 101 private void validateBackgroundColor() { 102 checkArgument(isNotBlank(backgroundColor), "Background color must not be blank"); 103 checkArgument(backgroundColor.length() == 7 && backgroundColor.startsWith("#"), 104 "Background color must begin with a sharp followed by 6 characters"); 105 } 106 } 107}