UserService.java

/*
 * Copyright 2018 Global Crop Diversity Trust
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.genesys.server.service;

import java.util.List;
import java.util.Set;
import java.util.UUID;

import org.genesys.blocks.security.NoUserFoundException;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys.blocks.security.service.BasicUserService;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys.server.model.UserRole;
import org.genesys.server.model.impl.User;
import org.genesys.server.service.filter.UserFilter;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;

public interface UserService extends BasicUserService<UserRole, User> {

	@PreAuthorize("isAuthenticated()")
	User getMe();

	User getUser(UUID uuid);

	User getUser(UUID uuid, Integer version) throws NoUserFoundException, ConcurrencyFailureException;

	boolean exists(String username);

	Page<User> listUsers(Pageable pageable);

	Page<User> list(UserFilter filter, Pageable pageable);

	boolean checkPasswordsMatch(String rawPassword, String encodedPassword);

	void setAccountActive(UUID uuid, boolean enabled) throws UserException;

	void userEmailValidated(UUID uuid);

	void addVettedUserRole(UUID uuid);

	List<User> autocompleteUser(String email);

	User setAccountType(User user, AccountType accountType);

	void setFtpPassword(User user, String ftpPassword) throws PasswordPolicyException;

	/**
	 * Disables current user's account
	 * @throws UserException 
	 */
	void disableMyAccount() throws UserException;

	/**
	 * Extend expired account for 3 months.
	 *
	 * @param user the user to be updated
	 * @return 
	 */
	User extendAccount(User user);

	/**
	 * Disables the account and removes personally identifiable data.
	 * 
	 * @param user
	 * @throws UserException
	 */
	User archiveUser(User user) throws UserException;

	/**
	 * Autocomplete user.
	 *
	 * @param email the email
	 * @param limit the limit
	 * @return the list of users
	 */
	List<User> autocompleteUser(String email, int limit);

	/**
	 * Sends emails to the selected list of users.
	 *
	 * @param userUuids user uuids
	 * @param template the email template
	 * @param subject the email subject
	 */
	void sendEmail(Set<UUID> userUuids, String template, String subject);

	/**
	 * Load or register a new user by {@link OidcUser}
	 *
	 * @param oidcUser the oidcUser
	 * @return the loaded or created user
	 */
	User loadOrRegisterUser(OidcUser oidcUser, String registrationId);

	User updateUserPreferences(UserPreferences preferences) throws UserException;

	User updateUserPreference(String setting, boolean value) throws UserException;

	class UserPreferences {
		public String language;
		public String timezone;
	}
}