Commit 158d8c2e authored by Maxym Borodenko's avatar Maxym Borodenko

FIX: GrantedAuthority deserialization issue in OAuthClient

parent 0a7aa543
......@@ -15,6 +15,7 @@
*/
package org.genesys.blocks.oauth.model;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
......@@ -39,6 +40,10 @@ import javax.persistence.Table;
import javax.persistence.Transient;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.model.JsonViews;
......@@ -492,6 +497,7 @@ public class OAuthClient extends AclSid implements ClientDetails, Copyable<OAuth
* org.springframework.security.oauth2.provider.ClientDetails#getAuthorities()
*/
@Override
@JsonDeserialize(contentUsing = GrantedAuthorityDeserializer.class)
public Collection<GrantedAuthority> getAuthorities() {
return roles.stream().collect(Collectors.toList());
}
......@@ -680,4 +686,11 @@ public class OAuthClient extends AclSid implements ClientDetails, Copyable<OAuth
public void setAllowedOrigins(Set<String> allowedOrigins) {
this.allowedOrigins = allowedOrigins;
}
private static class GrantedAuthorityDeserializer extends JsonDeserializer<GrantedAuthority> {
@Override
public GrantedAuthority deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return OAuthRole.valueOf(p.getText());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment