Search in sources :

Example 1 with UserServiceUnexpectedException

use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.

the class PermissionServiceImpl method grantPermission.

@Override
@Transactional(rollbackFor = Throwable.class)
public void grantPermission(String optionalDomainName, String userUuid, String optionalSubjectId, String permissionKey) {
    Preconditions.checkArgument(StringUtils.hasText(permissionKey));
    Preconditions.checkArgument(StringUtils.hasText(userUuid));
    String domainName = getOptionalParamValue(optionalDomainName);
    String subjectId = getOptionalParamValue(optionalSubjectId);
    try {
        permissionDao.grantPermission(domainName, userUuid, subjectId, permissionKey);
    } catch (DuplicateKeyException dke) {
        // it's ok
        log.debug("Duplicate key exception sealed. Looks like same permission is already granted.", dke);
    } catch (Throwable t) {
        String msg = String.format("Failed to grant permission '%s' to user '%s' on subject '%s' in domain '%s'", permissionKey, userUuid, subjectId, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UserServiceUnexpectedException

use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.

the class PermissionServiceImpl method revokeAllPermissionsForSubject.

@Override
@Transactional(rollbackFor = Throwable.class)
public void revokeAllPermissionsForSubject(String optionalDomainName, String optionalSubjectId) {
    String domainName = getOptionalParamValue(optionalDomainName);
    String subjectId = getOptionalParamValue(optionalSubjectId);
    try {
        permissionDao.clearSubjectPermissions(domainName, subjectId);
    } catch (Throwable t) {
        String msg = String.format("Failed to clear subject '%s' permissions in domain '%s'", subjectId, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with UserServiceUnexpectedException

use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.

the class PermissionServiceImpl method findUserPermissionsForSubject.

@Override
public List<String> findUserPermissionsForSubject(String optionalDomainName, String userUuid, String optionalSubjectId) {
    Preconditions.checkArgument(StringUtils.hasText(userUuid));
    String domainName = getOptionalParamValue(optionalDomainName);
    String subjectId = getOptionalParamValue(optionalSubjectId);
    try {
        return permissionDao.getUserPermissionsForSubject(domainName, userUuid, subjectId);
    } catch (Throwable t) {
        String msg = String.format("Failed to get user '%s' permissions for subject '%s' in domain '%s'", userUuid, subjectId, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException)

Example 4 with UserServiceUnexpectedException

use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.

the class PermissionServiceImpl method findSubjectsUserHasPermissionsFor.

@Override
public List<String> findSubjectsUserHasPermissionsFor(String optionalDomainName, String userUuid, String optionalRequiredPermission) {
    Preconditions.checkArgument(StringUtils.hasText(userUuid));
    String domainName = getOptionalParamValue(optionalDomainName);
    try {
        if (!StringUtils.hasText(optionalRequiredPermission)) {
            return permissionDao.getSubjectsUserHasPermissionFor(domainName, userUuid);
        } else {
            return permissionDao.getSubjectsUserHasPermissionForFiltered(domainName, userUuid, optionalRequiredPermission);
        }
    } catch (Throwable t) {
        String msg = String.format("Failed to get subject list user '%s' has permissions (optional = '%s') for in domain '%s'", userUuid, optionalRequiredPermission, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException)

Example 5 with UserServiceUnexpectedException

use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.

the class PermissionServiceImpl method revokeUserPermissions.

@Override
@Transactional(rollbackFor = Throwable.class)
public void revokeUserPermissions(String optionalDomainName, String userUuid) {
    Preconditions.checkArgument(StringUtils.hasText(userUuid));
    String domainName = getOptionalParamValue(optionalDomainName);
    try {
        permissionDao.revokeUserPermissions(domainName, userUuid);
    } catch (Throwable t) {
        String msg = String.format("Failed to revoke user '%s' permissions in domain '%s'", userUuid, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)27 Transactional (org.springframework.transaction.annotation.Transactional)18 User (org.summerb.users.api.dto.User)11 FieldValidationException (org.summerb.validation.FieldValidationException)11 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)9 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 AuthToken (org.summerb.users.api.dto.AuthToken)3 AuthTokenNotFoundException (org.summerb.users.api.exceptions.AuthTokenNotFoundException)3 InvalidPasswordException (org.summerb.users.api.exceptions.InvalidPasswordException)2 DuplicateUserValidationError (org.summerb.users.api.validation.DuplicateUserValidationError)2 Password (org.summerb.users.impl.dom.Password)2 Date (java.util.Date)1 ValidationError (org.summerb.validation.ValidationError)1 FieldRequiredValidationError (org.summerb.validation.errors.FieldRequiredValidationError)1 UserStatus (org.summerb.webappboilerplate.security.dto.UserStatus)1 RegistrationAlreadyRequestedValidationError (org.summerb.webappboilerplate.security.ve.RegistrationAlreadyRequestedValidationError)1