Skip to content

Commit

Permalink
make XsuaaToken serializable (#1243)
Browse files Browse the repository at this point in the history
* make XsuaaToken serializable #1209

Signed-off-by: Līga  <72249435+liga-oz@users.noreply.github.com>

---------

Signed-off-by: Līga  <72249435+liga-oz@users.noreply.github.com>
  • Loading branch information
liga-oz authored Jul 21, 2023
1 parent ce93b66 commit 0028ea8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The `zone_uuid` claim in Identity service tokens has been deprecated and is now
- `DefaultOAuth2TokenKeyService`
- `OAuth2TokenKeyServiceWithCache` (java-security module)
- `SpringOAuth2TokenKeyService`

- [java-security] `AbstractToken` is serializable fixes #1209

#### Dependency upgrades
- Bump spring.core.version from 6.0.9 to 6.0.11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import java.io.Serial;
import java.time.DateTimeException;
import java.time.Instant;
import java.util.*;
Expand All @@ -23,9 +24,12 @@
*/
public class DefaultJsonObject implements JsonObject {

@Serial
private static final long serialVersionUID = 2204172045251807L;

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJsonObject.class);

private final JSONObject jsonObject;
private final transient JSONObject jsonObject;

/**
* Create an instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
package com.sap.cloud.security.json;

import javax.annotation.Nullable;
import java.io.Serializable;
import java.time.Instant;
import java.util.List;
import java.util.Map;

/**
* Interface used to expose JSON data.
*/
public interface JsonObject {
public interface JsonObject extends Serializable {

/**
* @param name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/
package com.sap.cloud.security.token;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;

public interface ScopeConverter {
public interface ScopeConverter extends Serializable {
Set<String> convert(Collection<String> scopes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.sap.cloud.security.xsuaa.Assertions;

import java.io.Serial;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
Expand All @@ -18,6 +19,10 @@
* and prefixed with the "appId.", to local ones.
*/
public class XsuaaScopeConverter implements ScopeConverter {

@Serial
private static final long serialVersionUID = 2204172290850251807L;

private final Pattern globalScopePattern;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serial;
import java.security.Principal;
import java.util.LinkedHashSet;
import java.util.Optional;
Expand All @@ -26,6 +27,9 @@
* and provides access to token header parameters and claims.
*/
public class XsuaaToken extends AbstractToken implements AccessToken {

@Serial
private static final long serialVersionUID = 3304172041930251807L;
static final String UNIQUE_USER_NAME_FORMAT = "user/%s/%s"; // user/<origin>/<logonName>
static final String UNIQUE_CLIENT_NAME_FORMAT = "client/%s"; // client/<clientid>
private static final Logger LOGGER = LoggerFactory.getLogger(XsuaaToken.class);
Expand Down Expand Up @@ -59,7 +63,7 @@ public XsuaaToken(@Nonnull String accessToken) {
* of the access token
* @param userName
* of the access token
* @return unique principal name or <code>null</code> if origin or user name is
* @return unique principal name or <code>null</code> if origin or username is
* <code>null</code> or empty. Origin must also not contain a '/'
* character.
*/
Expand Down Expand Up @@ -100,8 +104,7 @@ public XsuaaToken withScopeConverter(@Nullable ScopeConverter converter) {

@Override
public Set<String> getScopes() {
LinkedHashSet<String> scopes = new LinkedHashSet<>(getClaimAsStringList(TokenClaims.XSUAA.SCOPES));
return scopes;
return new LinkedHashSet<>(getClaimAsStringList(TokenClaims.XSUAA.SCOPES));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serial;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -53,6 +54,9 @@ private String base64Decode(String encoded) {

static class DecodedJwtImpl implements DecodedJwt {

@Serial
private static final long serialVersionUID = 1454353454555430987L;

private final String header;
private final String payload;
private final String signature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package com.sap.cloud.security.xsuaa.jwt;

import java.io.Serializable;

/**
* A Jwt token consists of three parts, separated by ".":
* header.payload.signature
Expand All @@ -13,7 +15,7 @@
* {@link DecodedJwt} instance.
*/

public interface DecodedJwt {
public interface DecodedJwt extends Serializable {

/**
* Get the base64 decoded header of the jwt as UTF-8 String.
Expand Down

0 comments on commit 0028ea8

Please sign in to comment.