Custom User Authentication
Custom authentication API is based on Sun JAAS API. To provide your own authentication scheme, you should provide a login module class which must implement interface javax.security.auth.spi.LoginModule and register it in the jetbrains.buildServer.serverSide.auth.LoginConfiguration.
For example:
public class CustomLoginModule implements javax.security.auth.spi.LoginModule {
private Subject mySubject;
private CallbackHandler myCallbackHandler;
private Callback[] myCallbacks;
private NameCallback myNameCallback;
private PasswordCallback myPasswordCallback;
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
myCallbackHandler = callbackHandler;
myNameCallback = new NameCallback("login:");
myPasswordCallback = new PasswordCallback("password:", false);
myCallbacks = new Callback[] {myNameCallback, myPasswordCallback};
mySubject = subject;
}
public boolean login() throws LoginException {
try {
myCallbackHandler.handle(myCallbacks);
}
catch (Throwable t) {
throw new LoginException(t.toString());
}
final String login = myNameCallback.getName();
final String password = new String(myPasswordCallback.getPassword());
if (checkPassword(login, password)) {
mySubject.getPrincipals().add(new ServerPrincipal(null, login));
return true;
}
return false;
}
private boolean checkPassword(final String login, final String password) {
return true;
}
public boolean commit() throws LoginException {
return true;
}
public boolean abort() throws LoginException {
return true;
}
public boolean logout() throws LoginException {
return true;
}
}
Now we should register this module in the server. To do so, we create a login module descriptor:
public class CustomLoginModuleDescriptor implements jetbrains.buildServer.serverSide.auth.LoginModuleDescriptor {
public CustomLoginModuleDescriptor(LoginConfiguration loginConfiguration) {
loginConfiguration.registerLoginModule(this);
}
public Class<? extends LoginModule> getLoginModuleClass() {
return CustomLoginModule.class;
}
public Map<String, ?> getOptions() {
return null;
}
public String getTextForLoginPage() {
return null;
}
public String getDisplayName() {
return "My custom authentication plugin";
}
}
Finally we should create build-server-plugin-ourUserAuth.xml as it is described above and write there CustomLoginModuleDescriptor bean:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="constructor">
<bean id="customLoginModuleDescriptor" class="some.package.CustomLoginModuleDescriptor"/>
</beans>
Create a jar, put it into the WEB-INF/lib directory of the TeamCity server and restart it. When the server is started, you should be able to choose your custom plugin from the drop down list of the Administration > Server Configuration page.