org.spincast.website.HttpAuthInit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spincast-website Show documentation
Show all versions of spincast-website Show documentation
Source code for the https://www.spincast.org website.
package org.spincast.website;
import java.util.List;
import org.spincast.core.server.Server;
import org.spincast.shaded.org.apache.commons.lang3.tuple.Pair;
import com.google.inject.Inject;
/**
* Initilizes the HTTP authentication.
*/
public class HttpAuthInit {
private final AppConfig appConfig;
private final Server server;
@Inject
public HttpAuthInit(AppConfig appConfig, Server server) {
this.appConfig = appConfig;
this.server = server;
}
protected AppConfig getAppConfig() {
return this.appConfig;
}
protected Server getServer() {
return this.server;
}
@Inject
protected void init() {
//==========================================
// Admin section
//==========================================
List> adminUsernamesPasswords = getAppConfig().getAdminUsernamesPasswords();
for(Pair adminUsernamesPassword : adminUsernamesPasswords) {
getServer().addHttpAuthentication(AppConstants.HTTP_AUTH_REALM_NAME_ADMIN,
adminUsernamesPassword.getKey(),
adminUsernamesPassword.getValue());
}
//==========================================
// Example page
//==========================================
getServer().addHttpAuthentication(AppConstants.HTTP_AUTH_REALM_NAME_EXAMPLE, "Stromgol", "Laroche");
}
}