forked from spring-projects/spring-security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve serialize of proxy objects generated by AuthorizeReturnObject
Issue spring-projectsgh-15561
- Loading branch information
Showing
6 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core/src/main/java/org/springframework/security/authorization/method/AuthorizationProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.authorization.method; | ||
|
||
/** | ||
* Marker interface implemented by Authorization proxies. Used to detect whether objects | ||
* are AuthorizeReturnObject proxies. | ||
* | ||
* @author DingHao | ||
* @since 6.4 | ||
* @see org.springframework.security.authorization.method.AuthorizeReturnObject | ||
*/ | ||
public interface AuthorizationProxy { | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
core/src/main/java/org/springframework/security/jackson2/AuthorizationProxySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.jackson2; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
|
||
import org.springframework.aop.framework.AopProxyUtils; | ||
import org.springframework.security.authorization.method.AuthorizationProxy; | ||
import org.springframework.security.authorization.method.AuthorizeReturnObject; | ||
|
||
/** | ||
* Serialize AuthorizationProxy objects generated by {@link AuthorizeReturnObject} | ||
* | ||
* @author DingHao | ||
* @since 6.4 | ||
*/ | ||
public final class AuthorizationProxySerializer extends StdSerializer<AuthorizationProxy> { | ||
|
||
public AuthorizationProxySerializer() { | ||
super(AuthorizationProxy.class); | ||
} | ||
|
||
@Override | ||
public void serialize(AuthorizationProxy value, JsonGenerator gen, SerializerProvider serializers) | ||
throws IOException { | ||
JsonSerializer<Object> serializer = serializers.findValueSerializer(AopProxyUtils.ultimateTargetClass(value)); | ||
serializer.serialize(value, gen, serializers); | ||
} | ||
|
||
@Override | ||
public void serializeWithType(AuthorizationProxy value, JsonGenerator gen, SerializerProvider serializers, | ||
TypeSerializer typeSer) throws IOException { | ||
serialize(value, gen, serializers); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters