Skip to content

Commit 0e281be

Browse files
committed
Add SwitchUserGrantedAuthorityMixIn
1 parent f1b79e0 commit 0e281be

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2015-2016 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.web.jackson2;
18+
19+
import org.springframework.security.core.Authentication;
20+
import org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority;
21+
22+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
23+
import com.fasterxml.jackson.annotation.JsonCreator;
24+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
25+
import com.fasterxml.jackson.annotation.JsonProperty;
26+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
27+
28+
/**
29+
* Jackson mixin class to serialize/deserialize {@link SwitchUserGrantedAuthority}.
30+
*
31+
* @author Markus Heiden
32+
* @since 5.8
33+
* @see WebServletJackson2Module
34+
* @see org.springframework.security.jackson2.SecurityJackson2Modules
35+
*/
36+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
37+
@JsonIgnoreProperties(ignoreUnknown = true)
38+
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE,
39+
isGetterVisibility = JsonAutoDetect.Visibility.NONE)
40+
public abstract class SwitchUserGrantedAuthorityMixIn {
41+
42+
@JsonCreator
43+
SwitchUserGrantedAuthorityMixIn(@JsonProperty("role") String role, @JsonProperty("source") Authentication source) {
44+
}
45+
46+
}

0 commit comments

Comments
 (0)