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
181 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 { | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
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,61 @@ | ||
/* | ||
* 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.JsonMappingException; | ||
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 { | ||
targetSerializer(serializers, value).serialize(value, gen, serializers); | ||
} | ||
|
||
private JsonSerializer<Object> targetSerializer(SerializerProvider serializers, AuthorizationProxy value) | ||
throws JsonMappingException { | ||
return serializers.findValueSerializer(AopProxyUtils.ultimateTargetClass(value)); | ||
} | ||
|
||
@Override | ||
public void serializeWithType(AuthorizationProxy value, JsonGenerator gen, SerializerProvider serializers, | ||
TypeSerializer typeSer) throws IOException { | ||
targetSerializer(serializers, value).serializeWithType(value, gen, serializers, typeSer); | ||
} | ||
|
||
} |
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