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.security; 021 022import org.sonar.api.ExtensionPoint; 023import org.sonar.api.server.ServerSide; 024 025/** 026 * @since 2.14 027 */ 028@ServerSide 029@ExtensionPoint 030public abstract class SecurityRealm { 031 032 /** 033 * @return unique name of this realm, e.g. "ldap" 034 */ 035 public String getName() { 036 return getClass().getSimpleName(); 037 } 038 039 /** 040 * Invoked during server startup and can be used to initialize internal state. 041 */ 042 public void init() { 043 } 044 045 /** 046 * @return {@link LoginPasswordAuthenticator} associated with this realm, never null 047 * @deprecated replaced by doGetAuthenticator in version 3.1 048 */ 049 @Deprecated 050 public LoginPasswordAuthenticator getLoginPasswordAuthenticator() { 051 return null; 052 } 053 054 /** 055 * @since 3.1 056 */ 057 public Authenticator doGetAuthenticator() { 058 // this method is not overridden when deprecated getLoginPasswordAuthenticator 059 // is used 060 return new Authenticator() { 061 @Override 062 public boolean doAuthenticate(Context context) { 063 return getLoginPasswordAuthenticator().authenticate(context.getUsername(), context.getPassword()); 064 } 065 }; 066 } 067 068 /** 069 * @return {@link ExternalUsersProvider} associated with this realm, null if not supported 070 */ 071 public ExternalUsersProvider getUsersProvider() { 072 return null; 073 } 074 075 /** 076 * @return {@link ExternalGroupsProvider} associated with this realm, null if not supported 077 */ 078 public ExternalGroupsProvider getGroupsProvider() { 079 return null; 080 } 081}