use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class UsersService method get.
/*
* Nice little hack since Users don't have an XID.
*/
@Override
public User get(String username) throws NotFoundException, PermissionException {
Assert.notNull(username, "Username required");
if (this.userByUsername != null) {
String usernameLower = username.toLowerCase(Locale.ROOT);
User vo = userByUsername.get(usernameLower, dao::getByXid);
if (vo == null) {
throw new NotFoundException();
}
PermissionHolder currentUser = Common.getUser();
ensureReadPermission(currentUser, vo);
return vo;
} else {
return super.get(username);
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class UsersService method getUserByEmail.
/**
* Get a user by their email address
*
* @param emailAddress the email address of the user to find
* @return the user corresponding to the email address
* @throws NotFoundException if the email address was not found in the database
* @throws PermissionException if the current user does not have permission to read this user
*/
public User getUserByEmail(String emailAddress) throws NotFoundException, PermissionException {
User vo = dao.getUserByEmail(emailAddress);
if (vo == null)
throw new NotFoundException();
PermissionHolder currentUser = Common.getUser();
ensureReadPermission(currentUser, vo);
return vo;
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class SystemPermissionService method update.
/**
*/
public void update(MangoPermission permission, PermissionDefinition def) throws ValidationException {
Objects.requireNonNull(def, "Permission definition cannot be null");
permissionService.ensureAdminRole(Common.getUser());
ProcessResult validation = new ProcessResult();
if (permission == null) {
validation.addContextualMessage("permission", "validate.required");
throw new ValidationException(validation);
}
permission.getRoles().stream().flatMap(Collection::stream).forEach(role -> {
try {
roleService.get(role.getXid());
} catch (NotFoundException e) {
validation.addGenericMessage("validate.role.notFound", role.getXid());
}
});
if (validation.getHasMessages()) {
throw new ValidationException(validation);
}
// Execute in transaction as def.setPermission may make database calls
dao.doInTransaction(tx -> {
dao.update(def.getPermissionTypeName(), def.getPermission(), permission);
def.setPermission(permission);
});
this.eventPublisher.publishEvent(new SystemPermissionUpdated(def));
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class DataSourceService method getReadPermission.
/**
* Get the read permission for this data source
*/
public MangoPermission getReadPermission(int dataPointId) throws NotFoundException, PermissionException {
PermissionHolder user = Common.getUser();
Integer permissionId = dao.getReadPermissionId(dataPointId);
if (permissionId == null) {
throw new NotFoundException();
}
MangoPermission read = permissionService.get(permissionId);
permissionService.ensurePermission(user, read);
return read;
}
Aggregations