@Override protected SecurityApiException generateAlreadyExistsException(final KombuchaModelDao entity, final InternalCallContext context) { return new SecurityApiException(ErrorCode.__UNKNOWN_ERROR_CODE); }
throw new SecurityApiException(ErrorCode.SECURITY_INVALID_PERMISSIONS, curPerm); throw new SecurityApiException(ErrorCode.SECURITY_INVALID_PERMISSIONS, curPerm);
@Override public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final DateTime updatedDate = clock.getUTCNow(); final UsersSqlDao usersSqlDao = handle.attach(UsersSqlDao.class); final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao == null) { throw new SecurityApiException(ErrorCode.SECURITY_INVALID_USER, username); } usersSqlDao.invalidate(username, updatedDate.toDate(), updatedBy); return null; } });
@Override public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final RolesPermissionsSqlDao rolesPermissionsSqlDao = handle.attach(RolesPermissionsSqlDao.class); final List<RolesPermissionsModelDao> existingRole = rolesPermissionsSqlDao.getByRoleName(role); if (!existingRole.isEmpty()) { throw new SecurityApiException(ErrorCode.SECURITY_ROLE_ALREADY_EXISTS, role); } for (final String permission : permissions) { rolesPermissionsSqlDao.create(new RolesPermissionsModelDao(role, permission, createdDate, createdBy)); } return null; } });
@Override public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final DateTime updatedDate = clock.getUTCNow(); final UsersSqlDao usersSqlDao = handle.attach(UsersSqlDao.class); final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao == null) { throw new SecurityApiException(ErrorCode.SECURITY_INVALID_USER, username); } usersSqlDao.updatePassword(username, hashedPasswordBase64, salt.toBase64(), updatedDate.toDate(), updatedBy); return null; } });
@Override public List<UserRolesModelDao> inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final UsersSqlDao usersSqlDao = handle.attach(UsersSqlDao.class); final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao == null) { throw new SecurityApiException(ErrorCode.SECURITY_INVALID_USER, username); } final UserRolesSqlDao userRolesSqlDao = handle.attach(UserRolesSqlDao.class); return userRolesSqlDao.getByUsername(username); } });
@Override public void checkCurrentUserPermissions(final List<Permission> permissions, final Logical logical, final TenantContext context) throws SecurityApiException { final String[] permissionsString = Lists.<Permission, String>transform(permissions, Functions.toStringFunction()).toArray(new String[permissions.size()]); try { final Subject subject = SecurityUtils.getSubject(); if (permissionsString.length == 1) { subject.checkPermission(permissionsString[0]); } else if (Logical.AND.equals(logical)) { subject.checkPermissions(permissionsString); } else if (Logical.OR.equals(logical)) { boolean hasAtLeastOnePermission = false; for (final String permission : permissionsString) { if (subject.isPermitted(permission)) { hasAtLeastOnePermission = true; break; } } // Cause the exception if none match if (!hasAtLeastOnePermission) { subject.checkPermission(permissionsString[0]); } } } catch (final AuthorizationException e) { throw new SecurityApiException(e, ErrorCode.SECURITY_NOT_ENOUGH_PERMISSIONS); } }
final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao == null) { throw new SecurityApiException(ErrorCode.SECURITY_INVALID_USER, username);
@Override public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final UserRolesSqlDao userRolesSqlDao = handle.attach(UserRolesSqlDao.class); for (final String role : roles) { userRolesSqlDao.create(new UserRolesModelDao(username, role, createdDate, createdBy)); } final UsersSqlDao usersSqlDao = handle.attach(UsersSqlDao.class); final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao != null) { throw new SecurityApiException(ErrorCode.SECURITY_USER_ALREADY_EXISTS, username); } usersSqlDao.create(new UserModelDao(username, hashedPasswordBase64, salt.toBase64(), createdDate, createdBy)); return null; } });
@Override protected SecurityApiException generateAlreadyExistsException(final KombuchaModelDao entity, final InternalCallContext context) { return new SecurityApiException(ErrorCode.__UNKNOWN_ERROR_CODE); }
throw new SecurityApiException(ErrorCode.SECURITY_INVALID_PERMISSIONS, curPerm); throw new SecurityApiException(ErrorCode.SECURITY_INVALID_PERMISSIONS, curPerm);
@Override public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final DateTime updatedDate = clock.getUTCNow(); final UsersSqlDao usersSqlDao = handle.attach(UsersSqlDao.class); final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao == null) { throw new SecurityApiException(ErrorCode.SECURITY_INVALID_USER, username); } usersSqlDao.invalidate(username, updatedDate.toDate(), updatedBy); return null; } });
@Override public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final RolesPermissionsSqlDao rolesPermissionsSqlDao = handle.attach(RolesPermissionsSqlDao.class); final List<RolesPermissionsModelDao> existingRole = rolesPermissionsSqlDao.getByRoleName(role); if (!existingRole.isEmpty()) { throw new SecurityApiException(ErrorCode.SECURITY_ROLE_ALREADY_EXISTS, role); } for (final String permission : permissions) { rolesPermissionsSqlDao.create(new RolesPermissionsModelDao(role, permission, createdDate, createdBy)); } return null; } });
@Override public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final DateTime updatedDate = clock.getUTCNow(); final UsersSqlDao usersSqlDao = handle.attach(UsersSqlDao.class); final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao == null) { throw new SecurityApiException(ErrorCode.SECURITY_INVALID_USER, username); } usersSqlDao.updatePassword(username, hashedPasswordBase64, salt.toBase64(), updatedDate.toDate(), updatedBy); return null; } });
@Override public List<UserRolesModelDao> inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final UsersSqlDao usersSqlDao = handle.attach(UsersSqlDao.class); final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao == null) { throw new SecurityApiException(ErrorCode.SECURITY_INVALID_USER, username); } final UserRolesSqlDao userRolesSqlDao = handle.attach(UserRolesSqlDao.class); return userRolesSqlDao.getByUsername(username); } });
@Override public void checkCurrentUserPermissions(final List<Permission> permissions, final Logical logical, final TenantContext context) throws SecurityApiException { final String[] permissionsString = Lists.<Permission, String>transform(permissions, Functions.toStringFunction()).toArray(new String[permissions.size()]); try { final Subject subject = SecurityUtils.getSubject(); if (permissionsString.length == 1) { subject.checkPermission(permissionsString[0]); } else if (Logical.AND.equals(logical)) { subject.checkPermissions(permissionsString); } else if (Logical.OR.equals(logical)) { boolean hasAtLeastOnePermission = false; for (final String permission : permissionsString) { if (subject.isPermitted(permission)) { hasAtLeastOnePermission = true; break; } } // Cause the exception if none match if (!hasAtLeastOnePermission) { subject.checkPermission(permissionsString[0]); } } } catch (final AuthorizationException e) { throw new SecurityApiException(e, ErrorCode.SECURITY_NOT_ENOUGH_PERMISSIONS); } }
final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao == null) { throw new SecurityApiException(ErrorCode.SECURITY_INVALID_USER, username);
@Override public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception { final UserRolesSqlDao userRolesSqlDao = handle.attach(UserRolesSqlDao.class); for (final String role : roles) { userRolesSqlDao.create(new UserRolesModelDao(username, role, createdDate, createdBy)); } final UsersSqlDao usersSqlDao = handle.attach(UsersSqlDao.class); final UserModelDao userModelDao = usersSqlDao.getByUsername(username); if (userModelDao != null) { throw new SecurityApiException(ErrorCode.SECURITY_USER_ALREADY_EXISTS, username); } usersSqlDao.create(new UserModelDao(username, hashedPasswordBase64, salt.toBase64(), createdDate, createdBy)); return null; } });