keycloak
静的公開メンバ関数 | 静的公開変数類 | 全メンバ一覧
org.keycloak.util.TokenUtil クラス
org.keycloak.util.TokenUtil 連携図
Collaboration graph

静的公開メンバ関数

static String attachOIDCScope (String scopeParam)
 
static boolean isOIDCRequest (String scopeParam)
 
static boolean isOfflineTokenRequested (String scopeParam)
 
static boolean hasScope (String scopeParam, String targetScope)
 
static boolean hasPrompt (String promptParam, String targetPrompt)
 
static RefreshToken getRefreshToken (byte[] decodedToken) throws JWSInputException
 
static RefreshToken getRefreshToken (String refreshToken) throws JWSInputException
 
static boolean isOfflineToken (String refreshToken) throws JWSInputException
 
static String jweDirectEncode (Key aesKey, Key hmacKey, JsonWebToken jwt) throws JWEException
 
static< T extends JsonWebToken > T jweDirectVerifyAndDecode (Key aesKey, Key hmacKey, String jweStr, Class< T > expectedClass) throws JWEException
 

静的公開変数類

static final String TOKEN_TYPE_BEARER = "Bearer"
 
static final String TOKEN_TYPE_ID = "ID"
 
static final String TOKEN_TYPE_REFRESH = "Refresh"
 
static final String TOKEN_TYPE_OFFLINE = "Offline"
 

詳解

著者
Marek Posolda

関数詳解

◆ attachOIDCScope()

static String org.keycloak.util.TokenUtil.attachOIDCScope ( String  scopeParam)
inlinestatic
48  {
49  if (scopeParam == null || scopeParam.isEmpty()) {
50  return OAuth2Constants.SCOPE_OPENID;
51  } else if (hasScope(scopeParam, OAuth2Constants.SCOPE_OPENID)) {
52  return scopeParam;
53  } else {
54  return OAuth2Constants.SCOPE_OPENID + " " + scopeParam;
55  }
56  }
static boolean hasScope(String scopeParam, String targetScope)
Definition: TokenUtil.java:66

◆ getRefreshToken() [1/2]

static RefreshToken org.keycloak.util.TokenUtil.getRefreshToken ( byte []  decodedToken) throws JWSInputException
inlinestatic

Return refresh token or offline token

引数
decodedToken
戻り値
103  {
104  try {
105  return JsonSerialization.readValue(decodedToken, RefreshToken.class);
106  } catch (IOException e) {
107  throw new JWSInputException(e);
108  }
109  }

◆ getRefreshToken() [2/2]

static RefreshToken org.keycloak.util.TokenUtil.getRefreshToken ( String  refreshToken) throws JWSInputException
inlinestatic
111  {
112  byte[] encodedContent = new JWSInput(refreshToken).getContent();
113  return getRefreshToken(encodedContent);
114  }
static RefreshToken getRefreshToken(byte[] decodedToken)
Definition: TokenUtil.java:103

◆ hasPrompt()

static boolean org.keycloak.util.TokenUtil.hasPrompt ( String  promptParam,
String  targetPrompt 
)
inlinestatic
81  {
82  if (promptParam == null || targetPrompt == null) {
83  return false;
84  }
85 
86  String[] prompts = promptParam.split(" ");
87  for (String prompt : prompts) {
88  if (targetPrompt.equals(prompt)) {
89  return true;
90  }
91  }
92  return false;
93  }

◆ hasScope()

static boolean org.keycloak.util.TokenUtil.hasScope ( String  scopeParam,
String  targetScope 
)
inlinestatic
66  {
67  if (scopeParam == null || targetScope == null) {
68  return false;
69  }
70 
71  String[] scopes = scopeParam.split(" ");
72  for (String scope : scopes) {
73  if (targetScope.equals(scope)) {
74  return true;
75  }
76  }
77  return false;
78  }

◆ isOfflineToken()

static boolean org.keycloak.util.TokenUtil.isOfflineToken ( String  refreshToken) throws JWSInputException
inlinestatic

Return true if given refreshToken represents offline token

引数
refreshToken
戻り値
122  {
123  RefreshToken token = getRefreshToken(refreshToken);
124  return token.getType().equals(TOKEN_TYPE_OFFLINE);
125  }
static final String TOKEN_TYPE_OFFLINE
Definition: TokenUtil.java:45
static RefreshToken getRefreshToken(byte[] decodedToken)
Definition: TokenUtil.java:103

◆ isOfflineTokenRequested()

static boolean org.keycloak.util.TokenUtil.isOfflineTokenRequested ( String  scopeParam)
inlinestatic
62  {
63  return hasScope(scopeParam, OAuth2Constants.OFFLINE_ACCESS);
64  }
static boolean hasScope(String scopeParam, String targetScope)
Definition: TokenUtil.java:66

◆ isOIDCRequest()

static boolean org.keycloak.util.TokenUtil.isOIDCRequest ( String  scopeParam)
inlinestatic
58  {
59  return hasScope(scopeParam, OAuth2Constants.SCOPE_OPENID);
60  }
static boolean hasScope(String scopeParam, String targetScope)
Definition: TokenUtil.java:66

◆ jweDirectEncode()

static String org.keycloak.util.TokenUtil.jweDirectEncode ( Key  aesKey,
Key  hmacKey,
JsonWebToken  jwt 
) throws JWEException
inlinestatic
128  {
129  int keyLength = aesKey.getEncoded().length;
130  String encAlgorithm;
131  switch (keyLength) {
132  case 16: encAlgorithm = JWEConstants.A128CBC_HS256;
133  break;
134  case 24: encAlgorithm = JWEConstants.A192CBC_HS384;
135  break;
136  case 32: encAlgorithm = JWEConstants.A256CBC_HS512;
137  break;
138  default: throw new IllegalArgumentException("Bad size for Encryption key: " + aesKey + ". Valid sizes are 16, 24, 32.");
139  }
140 
141  try {
142  byte[] contentBytes = JsonSerialization.writeValueAsBytes(jwt);
143 
144  JWEHeader jweHeader = new JWEHeader(JWEConstants.DIR, encAlgorithm, null);
145  JWE jwe = new JWE()
146  .header(jweHeader)
147  .content(contentBytes);
148 
149  jwe.getKeyStorage()
150  .setCEKKey(aesKey, JWEKeyStorage.KeyUse.ENCRYPTION)
151  .setCEKKey(hmacKey, JWEKeyStorage.KeyUse.SIGNATURE);
152 
153  return jwe.encodeJwe();
154  } catch (IOException ioe) {
155  throw new JWEException(ioe);
156  }
157  }

◆ jweDirectVerifyAndDecode()

static <T extends JsonWebToken> T org.keycloak.util.TokenUtil.jweDirectVerifyAndDecode ( Key  aesKey,
Key  hmacKey,
String  jweStr,
Class< T >  expectedClass 
) throws JWEException
inlinestatic
160  {
161  JWE jwe = new JWE();
162  jwe.getKeyStorage()
163  .setCEKKey(aesKey, JWEKeyStorage.KeyUse.ENCRYPTION)
164  .setCEKKey(hmacKey, JWEKeyStorage.KeyUse.SIGNATURE);
165 
166  jwe.verifyAndDecodeJwe(jweStr);
167 
168  try {
169  return JsonSerialization.readValue(jwe.getContent(), expectedClass);
170  } catch (IOException ioe) {
171  throw new JWEException(ioe);
172  }
173  }

メンバ詳解

◆ TOKEN_TYPE_BEARER

final String org.keycloak.util.TokenUtil.TOKEN_TYPE_BEARER = "Bearer"
static

◆ TOKEN_TYPE_ID

final String org.keycloak.util.TokenUtil.TOKEN_TYPE_ID = "ID"
static

◆ TOKEN_TYPE_OFFLINE

final String org.keycloak.util.TokenUtil.TOKEN_TYPE_OFFLINE = "Offline"
static

◆ TOKEN_TYPE_REFRESH

final String org.keycloak.util.TokenUtil.TOKEN_TYPE_REFRESH = "Refresh"
static

このクラス詳解は次のファイルから抽出されました: