All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spincast.website.HttpAuthInit Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
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");

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy