Skip to content

Commit a453a71

Browse files
committed
Merge remote-tracking branch 'origin/5.8.x'
2 parents f9f4104 + 8d09655 commit a453a71

File tree

3 files changed

+98
-30
lines changed

3 files changed

+98
-30
lines changed

Diff for: core/src/main/java/org/springframework/security/authorization/event/AuthorizationDeniedEvent.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,21 @@
2929
* @author Josh Cummings
3030
* @since 5.7
3131
*/
32-
public class AuthorizationDeniedEvent<T> extends ApplicationEvent {
33-
34-
private final Supplier<Authentication> authentication;
35-
36-
private final AuthorizationDecision decision;
32+
public class AuthorizationDeniedEvent<T> extends AuthorizationEvent {
3733

3834
public AuthorizationDeniedEvent(Supplier<Authentication> authentication, T object, AuthorizationDecision decision) {
39-
super(object);
40-
this.authentication = authentication;
41-
this.decision = decision;
42-
}
43-
44-
public Supplier<Authentication> getAuthentication() {
45-
return this.authentication;
35+
super(authentication, object, decision);
4636
}
4737

48-
public AuthorizationDecision getAuthorizationDecision() {
49-
return this.decision;
38+
/**
39+
* Get the object to which access was requested
40+
* @return the object to which access was requested
41+
* @since 5.8
42+
*/
43+
@Override
44+
@SuppressWarnings("unchecked")
45+
public T getObject() {
46+
return (T) getSource();
5047
}
5148

5249
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.authorization.event;
18+
19+
import java.util.function.Supplier;
20+
21+
import org.springframework.context.ApplicationEvent;
22+
import org.springframework.security.authorization.AuthorizationDecision;
23+
import org.springframework.security.core.Authentication;
24+
import org.springframework.util.Assert;
25+
26+
/**
27+
* A parent class for {@link AuthorizationGrantedEvent} and
28+
* {@link AuthorizationDeniedEvent}.
29+
*
30+
* @author Josh Cummings
31+
* @since 5.8
32+
*/
33+
public class AuthorizationEvent extends ApplicationEvent {
34+
35+
private final Supplier<Authentication> authentication;
36+
37+
private final AuthorizationDecision decision;
38+
39+
/**
40+
* Construct an {@link AuthorizationEvent}
41+
* @param authentication the principal requiring access
42+
* @param object the object to which access was requested
43+
* @param decision whether authorization was granted or denied
44+
*/
45+
public AuthorizationEvent(Supplier<Authentication> authentication, Object object, AuthorizationDecision decision) {
46+
super(object);
47+
Assert.notNull(authentication, "authentication supplier cannot be null");
48+
this.authentication = authentication;
49+
this.decision = decision;
50+
}
51+
52+
/**
53+
* Get the principal requiring access
54+
* @return the principal requiring access
55+
*/
56+
public Supplier<Authentication> getAuthentication() {
57+
return this.authentication;
58+
}
59+
60+
/**
61+
* Get the object to which access was requested
62+
* @return the object to which access was requested
63+
*/
64+
public Object getObject() {
65+
return getSource();
66+
}
67+
68+
/**
69+
* Get the response to the princpal's request
70+
* @return
71+
*/
72+
public AuthorizationDecision getAuthorizationDecision() {
73+
return this.decision;
74+
}
75+
76+
}

Diff for: core/src/main/java/org/springframework/security/authorization/event/AuthorizationGrantedEvent.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.springframework.context.ApplicationEvent;
2222
import org.springframework.security.authorization.AuthorizationDecision;
2323
import org.springframework.security.core.Authentication;
24-
import org.springframework.util.Assert;
2524

2625
/**
2726
* An {@link ApplicationEvent} which indicates successful authorization.
@@ -30,26 +29,22 @@
3029
* @author Josh Cummings
3130
* @since 5.7
3231
*/
33-
public class AuthorizationGrantedEvent<T> extends ApplicationEvent {
34-
35-
private final Supplier<Authentication> authentication;
36-
37-
private final AuthorizationDecision decision;
32+
public class AuthorizationGrantedEvent<T> extends AuthorizationEvent {
3833

3934
public AuthorizationGrantedEvent(Supplier<Authentication> authentication, T object,
4035
AuthorizationDecision decision) {
41-
super(object);
42-
Assert.notNull(authentication, "authentication supplier cannot be null");
43-
this.authentication = authentication;
44-
this.decision = decision;
45-
}
46-
47-
public Supplier<Authentication> getAuthentication() {
48-
return this.authentication;
36+
super(authentication, object, decision);
4937
}
5038

51-
public AuthorizationDecision getAuthorizationDecision() {
52-
return this.decision;
39+
/**
40+
* Get the object to which access was requested
41+
* @return the object to which access was requested
42+
* @since 5.8
43+
*/
44+
@Override
45+
@SuppressWarnings("unchecked")
46+
public T getObject() {
47+
return (T) getSource();
5348
}
5449

5550
}

0 commit comments

Comments
 (0)