org.sonar.plugins.ldap.LdapRealm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonar-ldap-plugin Show documentation
Show all versions of sonar-ldap-plugin Show documentation
Delegates authentication to LDAP.
The newest version!
/*
* Sonar LDAP Plugin
* Copyright (C) 2009 SonarSource
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.ldap;
import org.sonar.api.security.ExternalGroupsProvider;
import org.sonar.api.security.ExternalUsersProvider;
import org.sonar.api.security.LoginPasswordAuthenticator;
import org.sonar.api.security.SecurityRealm;
import java.util.Map;
/**
* @author Evgeny Mandrikov
*/
public class LdapRealm extends SecurityRealm {
private LdapUsersProvider usersProvider;
private LdapGroupsProvider groupsProvider;
private LdapAuthenticator authenticator;
private final LdapSettingsManager settingsManager;
public LdapRealm(LdapSettingsManager settingsManager) {
this.settingsManager = settingsManager;
}
@Override
public String getName() {
return "LDAP";
}
/**
* Initializes LDAP realm and tests connection.
*
* @throws org.sonar.api.utils.SonarException if a NamingException was thrown during test
*/
@Override
public void init() {
Map contextFactories = settingsManager.getContextFactories();
Map userMappings = settingsManager.getUserMappings();
usersProvider = new LdapUsersProvider(contextFactories, userMappings);
authenticator = new LdapAuthenticator(contextFactories, userMappings);
Map groupMappings = settingsManager.getGroupMappings();
if (!groupMappings.isEmpty()) {
groupsProvider = new LdapGroupsProvider(contextFactories, userMappings, groupMappings);
}
for (LdapContextFactory contextFactory : contextFactories.values()) {
contextFactory.testConnection();
}
}
@Override
public LoginPasswordAuthenticator getLoginPasswordAuthenticator() {
return authenticator;
}
@Override
public ExternalUsersProvider getUsersProvider() {
return usersProvider;
}
@Override
public ExternalGroupsProvider getGroupsProvider() {
return groupsProvider;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy