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

com.github.lontime.extpac4j.config.builder.DbAuthenticatorExtBuilder Maven / Gradle / Ivy

The newest version!
package com.github.lontime.extpac4j.config.builder;

import java.util.Map;

import com.github.lontime.extpac4j.sql.profile.DbProfileService;
import org.pac4j.config.builder.AbstractBuilder;
import org.pac4j.core.credentials.authenticator.Authenticator;
import org.pac4j.core.credentials.password.PasswordEncoder;

import static com.github.lontime.extpac4j.config.PropertiesExtConstants.JDBI_ATTRIBUTES;
import static com.github.lontime.extpac4j.config.PropertiesExtConstants.JDBI_NAME;
import static com.github.lontime.extpac4j.config.PropertiesExtConstants.JDBI_PASSWORD_ENCODER;
import static com.github.lontime.extpac4j.config.PropertiesExtConstants.JDBI_USERNAME_ATTRIBUTE;
import static com.github.lontime.extpac4j.config.PropertiesExtConstants.JDBI_USERS_TABLE;
import static com.github.lontime.extpac4j.config.PropertiesExtConstants.JDBI_USER_PASSWORD_ATTRIBUTE;

/**
 * Builder for the RDBMS authenticator.
 *
 * @author Jerome Leleu
 * @since 2.1.0
 */
public class DbAuthenticatorExtBuilder extends AbstractBuilder {

    public DbAuthenticatorExtBuilder(final Map properties) {
        super(properties);
    }

    public void tryBuildDbAuthenticator(final Map authenticators, final Map encoders) {
        for (int i = 0; i <= MAX_NUM_AUTHENTICATORS; i++) {
            final String dsName = getProperty(JDBI_NAME, i);
            final DbProfileService authenticator = new DbProfileService(dsName);
            if (containsProperty(JDBI_ATTRIBUTES, i)) {
                authenticator.setAttributes(getProperty(JDBI_ATTRIBUTES, i));
            }
            if (containsProperty(DB_USER_ID_ATTRIBUTE, i)) {
                authenticator.setIdAttribute(getProperty(DB_USER_ID_ATTRIBUTE, i));
            }
            if (containsProperty(JDBI_USERNAME_ATTRIBUTE, i)) {
                authenticator.setUsernameAttribute(getProperty(JDBI_USERNAME_ATTRIBUTE, i));
            }
            if (containsProperty(JDBI_USER_PASSWORD_ATTRIBUTE, i)) {
                authenticator.setPasswordAttribute(getProperty(JDBI_USER_PASSWORD_ATTRIBUTE, i));
            }
            if (containsProperty(JDBI_USERS_TABLE, i)) {
                authenticator.setUsersTable(getProperty(JDBI_USERS_TABLE, i));
            }
            if (containsProperty(JDBI_PASSWORD_ENCODER, i)) {
                authenticator.setPasswordEncoder(encoders.get(getProperty(JDBI_PASSWORD_ENCODER, i)));
            }
            authenticators.put(concat("jdbi", i), authenticator);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy