Search in sources :

Example 1 with AuthConfig

use of org.nzbhydra.config.AuthConfig in project nzbhydra2 by theotherp.

the class UserInfosProvider method getUserInfos.

public BootstrappedDataTO getUserInfos(Principal principal) {
    BootstrappedDataTO bootstrappedData = new BootstrappedDataTO();
    AuthConfig auth = configProvider.getBaseConfig().getAuth();
    boolean authConfigured = auth.getAuthType() != AuthType.NONE && !auth.getUsers().isEmpty();
    boolean adminRestricted = auth.isRestrictAdmin() && authConfigured;
    boolean statsRestricted = auth.isRestrictStats() && authConfigured;
    boolean searchRestricted = auth.isRestrictSearch() && authConfigured;
    boolean detailsDlRestricted = auth.isRestrictIndexerSelection() && authConfigured;
    boolean indexerSelectionRestricted = auth.isRestrictIndexerSelection() && authConfigured;
    boolean showIndexerSelection;
    String username;
    boolean maySeeAdmin;
    boolean maySeeStats;
    boolean maySeeDetailsDl;
    Optional<UserAuthConfig> user = principal == null ? Optional.empty() : auth.getUsers().stream().filter(x -> Objects.equals(x.getUsername(), principal.getName())).findFirst();
    if (user.isPresent()) {
        maySeeAdmin = user.get().isMaySeeAdmin();
        maySeeStats = user.get().isMaySeeStats() || user.get().isMaySeeAdmin();
        maySeeDetailsDl = user.get().isMaySeeDetailsDl() || !detailsDlRestricted;
        showIndexerSelection = user.get().isShowIndexerSelection() || !indexerSelectionRestricted;
        username = user.get().getUsername();
    } else if (!authConfigured) {
        maySeeAdmin = true;
        maySeeStats = true;
        maySeeDetailsDl = true;
        showIndexerSelection = true;
        username = null;
    } else {
        maySeeAdmin = false;
        maySeeStats = false;
        maySeeDetailsDl = !detailsDlRestricted;
        showIndexerSelection = !indexerSelectionRestricted;
        username = null;
    }
    bootstrappedData.setAuthType(auth.getAuthType().name());
    bootstrappedData.setAuthConfigured(authConfigured);
    bootstrappedData.setAdminRestricted(adminRestricted);
    bootstrappedData.setSearchRestricted(searchRestricted);
    bootstrappedData.setStatsRestricted(statsRestricted);
    bootstrappedData.setShowIndexerSelection(showIndexerSelection);
    bootstrappedData.setMaySeeDetailsDl(maySeeDetailsDl);
    bootstrappedData.setMaySeeAdmin(maySeeAdmin);
    bootstrappedData.setMaySeeStats(maySeeStats);
    bootstrappedData.setMaySeeDetailsDl(maySeeDetailsDl);
    bootstrappedData.setMaySeeSearch(!auth.isRestrictSearch() || !authConfigured || user.isPresent());
    bootstrappedData.setUsername(username);
    return bootstrappedData;
}
Also used : BootstrappedDataTO(org.nzbhydra.web.BootstrappedDataTO) UserAuthConfig(org.nzbhydra.config.UserAuthConfig) UserAuthConfig(org.nzbhydra.config.UserAuthConfig) AuthConfig(org.nzbhydra.config.AuthConfig)

Aggregations

AuthConfig (org.nzbhydra.config.AuthConfig)1 UserAuthConfig (org.nzbhydra.config.UserAuthConfig)1 BootstrappedDataTO (org.nzbhydra.web.BootstrappedDataTO)1