У меня есть изменение кода ниже.
- @PreAuthorize("isAuthenticated()")
+ @PreAuthorize("hasPermission(#dto.perusteId, 'peruste', 'LUKU')")
public void setStarted(DokumenttiDto dto);
Согласно документации Spring, объект аутентификации не должен быть нулевым. Здесь разработчик убирает проверку аутентификации и ставит проверку hasPermission. Так будет ли метод hasPermission возвращать false, если объект аутентификации имеет значение null? Объект аутентификации будет предоставлен фреймворком безопасности spring автоматически. Можно ли это считать изменением рефакторинга? две проверки (аутентификация + проверка разрешений) объединены в одну (проверка разрешений)! Я не думаю, что реализация метода hasPermission выполняет какие-либо проверки объекта аутентификации. /vm/sade/eperusteet/service/security/PermissionEvaluator.java" rel="nofollow">https://github.com/Opetushallitus/eperusteet/blob/cd9eff86bdda5dd91072354392dedbe0783c9ddf/eperusteet/eperusteet-service/src/main/java/fi /vm/sade/eperusteet/service/security/PermissionEvaluator.java)
Вот ссылка на изменение кода: https://github.com/Opetushallitus/eperusteet/commit/e8459 а>
Method Detail
hasPermission
public boolean hasPermission(Authentication authentication,
Object domainObject,
Object permission)
Determines whether the user has the given permission(s) on the domain object using the ACL configuration. If the domain object is null, returns false (this can always be overridden using a null check in the expression itself).
Specified by:
hasPermission in interface PermissionEvaluator
Parameters:
authentication - represents the user in question. Should not be null.
domainObject - the domain object for which permissions should be checked. May be null in which case implementations should return false, as the null condition can be checked explicitly in the expression.
permission - a representation of the permission object as supplied by the expression system. Not null.