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

org.ligoj.bootstrap.dao.system.SystemUserRepository Maven / Gradle / Ivy

There is a newer version: 3.1.22
Show newest version
/*
 * Licensed under MIT (https://github.com/ligoj/ligoj/blob/master/LICENSE)
 */
package org.ligoj.bootstrap.dao.system;

import org.ligoj.bootstrap.core.dao.RestRepository;
import org.ligoj.bootstrap.model.system.SystemUser;
import org.springframework.data.jpa.repository.Query;

/**
 * User repository.
 */
public interface SystemUserRepository extends RestRepository {

	/**
	 * Return user and his/her roles.
	 *
	 * @param login
	 *            user login.
	 * @return {@link SystemUser} with roles.
	 */
	@Query(value = "SELECT user, r FROM SystemUser user LEFT JOIN user.roles ra LEFT JOIN ra.role r WHERE user.login = ?1")
	Object[][] findByLoginFetchRoles(String login);

	/**
	 * Return true when given user is an administrator. Is
	 * considered administrators, user having all API authorization (.*)
	 * pattern.
	 *
	 * @param user
	 *            The username requesting the operation.
	 * @return true when the current user is an administrator.
	 */
	@Query("SELECT COUNT(s)>0 FROM SystemUser s WHERE " + SystemUser.IS_ADMIN)
	boolean isAdmin(String user);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy