|
@@ -20,6 +20,7 @@ import java.util.function.Supplier;
|
|
|
|
|
|
import org.springframework.context.ApplicationEvent;
|
|
import org.springframework.context.ApplicationEvent;
|
|
import org.springframework.security.authorization.AuthorizationDecision;
|
|
import org.springframework.security.authorization.AuthorizationDecision;
|
|
|
|
+import org.springframework.security.authorization.AuthorizationResult;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
@@ -34,19 +35,32 @@ public class AuthorizationEvent extends ApplicationEvent {
|
|
|
|
|
|
private final Supplier<Authentication> authentication;
|
|
private final Supplier<Authentication> authentication;
|
|
|
|
|
|
- private final AuthorizationDecision decision;
|
|
|
|
|
|
+ private final AuthorizationResult result;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Construct an {@link AuthorizationEvent}
|
|
* Construct an {@link AuthorizationEvent}
|
|
* @param authentication the principal requiring access
|
|
* @param authentication the principal requiring access
|
|
* @param object the object to which access was requested
|
|
* @param object the object to which access was requested
|
|
- * @param decision whether authorization was granted or denied
|
|
|
|
|
|
+ * @param result whether authorization was granted or denied
|
|
*/
|
|
*/
|
|
- public AuthorizationEvent(Supplier<Authentication> authentication, Object object, AuthorizationDecision decision) {
|
|
|
|
|
|
+ public AuthorizationEvent(Supplier<Authentication> authentication, Object object, AuthorizationDecision result) {
|
|
super(object);
|
|
super(object);
|
|
Assert.notNull(authentication, "authentication supplier cannot be null");
|
|
Assert.notNull(authentication, "authentication supplier cannot be null");
|
|
this.authentication = authentication;
|
|
this.authentication = authentication;
|
|
- this.decision = decision;
|
|
|
|
|
|
+ this.result = result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Construct an {@link AuthorizationEvent}
|
|
|
|
+ * @param authentication the principal requiring access
|
|
|
|
+ * @param object the object to which access was requested
|
|
|
|
+ * @param result whether authorization was granted or denied
|
|
|
|
+ */
|
|
|
|
+ public AuthorizationEvent(Supplier<Authentication> authentication, Object object, AuthorizationResult result) {
|
|
|
|
+ super(object);
|
|
|
|
+ Assert.notNull(authentication, "authentication supplier cannot be null");
|
|
|
|
+ this.authentication = authentication;
|
|
|
|
+ this.result = result;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -68,9 +82,27 @@ public class AuthorizationEvent extends ApplicationEvent {
|
|
/**
|
|
/**
|
|
* Get the response to the principal's request
|
|
* Get the response to the principal's request
|
|
* @return the response to the principal's request
|
|
* @return the response to the principal's request
|
|
|
|
+ * @deprecated please use {@link #getAuthorizationResult()}
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public AuthorizationDecision getAuthorizationDecision() {
|
|
public AuthorizationDecision getAuthorizationDecision() {
|
|
- return this.decision;
|
|
|
|
|
|
+ if (this.result == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if (this.result instanceof AuthorizationDecision decision) {
|
|
|
|
+ return decision;
|
|
|
|
+ }
|
|
|
|
+ throw new IllegalArgumentException(
|
|
|
|
+ "Please either call getAuthorizationResult or ensure that the result is of type AuthorizationDecision");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Get the response to the principal's request
|
|
|
|
+ * @return the response to the principal's request
|
|
|
|
+ * @since 6.4
|
|
|
|
+ */
|
|
|
|
+ public AuthorizationResult getAuthorizationResult() {
|
|
|
|
+ return this.result;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|