<commit_before>/*******************************************************************************
 * Copyright (c) 2015 Whizzo Software, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package com.whizzosoftware.hobson.bootstrap.api.user;

import com.whizzosoftware.hobson.api.HobsonAuthenticationException;
import com.whizzosoftware.hobson.api.HobsonAuthorizationException;
import com.whizzosoftware.hobson.api.hub.HubContext;
import com.whizzosoftware.hobson.api.hub.HubManager;
import com.whizzosoftware.hobson.api.user.HobsonUser;
import com.whizzosoftware.hobson.api.user.UserStore;

public class LocalUserStore implements UserStore {
    private HubManager hubManager;

    public LocalUserStore(HubManager hubManager) {
        this.hubManager = hubManager;
    }

    @Override
    public boolean hasDefaultUser() {
        return true;
    }

    @Override
    public String getDefaultUser() {
        return "local";
    }

    @Override
    public HobsonUser authenticate(String username, String password) {
        if (hubManager.getLocalManager() != null && hubManager.getLocalManager().authenticateLocal(HubContext.createLocal(), password)) {
            return createLocalUser();
        } else {
            throw new HobsonAuthenticationException("The authentication credentials are invalid");
        }
    }

    @Override
    public HobsonUser getUser(String username) {
        if (username.equals("local")) {
            return createLocalUser();
        } else {
            throw new HobsonAuthorizationException("You are not authorized to retrieve that information");
        }
    }

    protected HobsonUser createLocalUser() {
        return new HobsonUser.Builder("local")
            .givenName("Local")
            .familyName("User")<commit_msg>Refactored data sets to be a user entity rather than a hub entity.<commit_after>/*******************************************************************************
 * Copyright (c) 2015 Whizzo Software, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package com.whizzosoftware.hobson.bootstrap.api.user;

import com.whizzosoftware.hobson.api.HobsonAuthenticationException;
import com.whizzosoftware.hobson.api.HobsonAuthorizationException;
import com.whizzosoftware.hobson.api.hub.HubContext;
import com.whizzosoftware.hobson.api.hub.HubManager;
import com.whizzosoftware.hobson.api.user.HobsonUser;
import com.whizzosoftware.hobson.api.user.UserStore;

import java.util.Collection;
import java.util.Collections;

public class LocalUserStore implements UserStore {
    private HubManager hubManager;

    public LocalUserStore(HubManager hubManager) {
        this.hubManager = hubManager;
    }

    @Override
    public boolean hasDefaultUser() {
        return true;
    }

    @Override
    public String getDefaultUser() {
        return "local";
    }

    @Override
    public HobsonUser authenticate(String username, String password) {
        if (hubManager.getLocalManager() != null && hubManager.getLocalManager().authenticateLocal(HubContext.createLocal(), password)) {
            return createLocalUser();
        } else {
            throw new HobsonAuthenticationException("The authentication credentials are invalid");
        }
    }

    @Override
    public HobsonUser getUser(String username) {
        if (username.equals("local")) {
            return createLocalUser();
        } else {
            throw new HobsonAuthorizationException("You are not authorized to retrieve that information");
        }
    }

    @Override
    public Collection<String> getUserIds() {
        return Collections.singletonList("local");
    }

    protected HobsonUser createLocalUser() {
        return new HobsonUser.Builder("local")
            .givenName("Local")
            .familyName("User")
{'fraction_non_alphanumeric': 0.15448275862068966, 'fraction_numerical': 0.0036781609195402297, 'mean_word_length': 3.673469387755102, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5714134', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1085, 'n_words': 273}