mitreid-connect
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.mitre.openid.connect.service.impl.DefaultOIDCTokenService クラス
org.mitre.openid.connect.service.impl.DefaultOIDCTokenService の継承関係図
Inheritance graph
org.mitre.openid.connect.service.impl.DefaultOIDCTokenService 連携図
Collaboration graph

公開メンバ関数

JWT createIdToken (ClientDetailsEntity client, OAuth2Request request, Date issueTime, String sub, OAuth2AccessTokenEntity accessToken)
 
OAuth2AccessTokenEntity createRegistrationAccessToken (ClientDetailsEntity client)
 
OAuth2AccessTokenEntity createResourceAccessToken (ClientDetailsEntity client)
 
OAuth2AccessTokenEntity rotateRegistrationAccessTokenForClient (ClientDetailsEntity client)
 
ConfigurationPropertiesBean getConfigBean ()
 
void setConfigBean (ConfigurationPropertiesBean configBean)
 
JWTSigningAndValidationService getJwtService ()
 
void setJwtService (JWTSigningAndValidationService jwtService)
 
AuthenticationHolderRepository getAuthenticationHolderRepository ()
 
void setAuthenticationHolderRepository (AuthenticationHolderRepository authenticationHolderRepository)
 

非公開メンバ関数

OAuth2AccessTokenEntity createAssociatedToken (ClientDetailsEntity client, Set< String > scope)
 

非公開変数類

JWTSigningAndValidationService jwtService
 
AuthenticationHolderRepository authenticationHolderRepository
 
ConfigurationPropertiesBean configBean
 
ClientKeyCacheService encrypters
 
SymmetricKeyJWTValidatorCacheService symmetricCacheService
 
OAuth2TokenEntityService tokenService
 

静的非公開変数類

static final Logger logger = LoggerFactory.getLogger(DefaultOIDCTokenService.class)
 

詳解

Default implementation of service to create specialty OpenID Connect tokens.

著者
Amanda Anganes

関数詳解

◆ createAssociatedToken()

OAuth2AccessTokenEntity org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.createAssociatedToken ( ClientDetailsEntity  client,
Set< String >  scope 
)
inlineprivate
249  {
250 
251  // revoke any previous tokens that might exist, just to be sure
252  OAuth2AccessTokenEntity oldToken = tokenService.getRegistrationAccessTokenForClient(client);
253  if (oldToken != null) {
255  }
256 
257  // create a new token
258 
259  Map<String, String> authorizationParameters = Maps.newHashMap();
260  OAuth2Request clientAuth = new OAuth2Request(authorizationParameters, client.getClientId(),
261  Sets.newHashSet(new SimpleGrantedAuthority("ROLE_CLIENT")), true,
262  scope, null, null, null, null);
263  OAuth2Authentication authentication = new OAuth2Authentication(clientAuth, null);
264 
265  OAuth2AccessTokenEntity token = new OAuth2AccessTokenEntity();
266  token.setClient(client);
267  token.setScope(scope);
268 
269  AuthenticationHolderEntity authHolder = new AuthenticationHolderEntity();
270  authHolder.setAuthentication(authentication);
271  authHolder = authenticationHolderRepository.save(authHolder);
272  token.setAuthenticationHolder(authHolder);
273 
274  JWTClaimsSet claims = new JWTClaimsSet.Builder()
275  .audience(Lists.newArrayList(client.getClientId()))
276  .issuer(configBean.getIssuer())
277  .issueTime(new Date())
278  .expirationTime(token.getExpiration())
279  .jwtID(UUID.randomUUID().toString()) // set a random NONCE in the middle of it
280  .build();
281 
282  JWSAlgorithm signingAlg = jwtService.getDefaultSigningAlgorithm();
283  JWSHeader header = new JWSHeader(signingAlg, null, null, null, null, null, null, null, null, null,
285  null, null);
286  SignedJWT signed = new SignedJWT(header, claims);
287 
288  jwtService.signJwt(signed);
289 
290  token.setJwt(signed);
291 
292  return token;
293  }
AuthenticationHolderRepository authenticationHolderRepository
Definition: DefaultOIDCTokenService.java:84
OAuth2AccessTokenEntity getRegistrationAccessTokenForClient(ClientDetailsEntity client)
JWTSigningAndValidationService jwtService
Definition: DefaultOIDCTokenService.java:81
AuthenticationHolderEntity save(AuthenticationHolderEntity a)
ConfigurationPropertiesBean configBean
Definition: DefaultOIDCTokenService.java:87
OAuth2TokenEntityService tokenService
Definition: DefaultOIDCTokenService.java:96
String getIssuer()
Definition: ConfigurationPropertiesBean.java:100
void revokeAccessToken(OAuth2AccessTokenEntity accessToken)

◆ createIdToken()

JWT org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.createIdToken ( ClientDetailsEntity  client,
OAuth2Request  request,
Date  issueTime,
String  sub,
OAuth2AccessTokenEntity  accessToken 
)
inline

org.mitre.openid.connect.service.OIDCTokenServiceを実装しています。

99  {
100 
101  JWSAlgorithm signingAlg = jwtService.getDefaultSigningAlgorithm();
102 
103  if (client.getIdTokenSignedResponseAlg() != null) {
104  signingAlg = client.getIdTokenSignedResponseAlg();
105  }
106 
107 
108  JWT idToken = null;
109 
110  JWTClaimsSet.Builder idClaims = new JWTClaimsSet.Builder();
111 
112  // if the auth time claim was explicitly requested OR if the client always wants the auth time, put it in
113  if (request.getExtensions().containsKey(MAX_AGE)
114  || (request.getExtensions().containsKey("idtoken")) // TODO: parse the ID Token claims (#473) -- for now assume it could be in there
115  || (client.getRequireAuthTime() != null && client.getRequireAuthTime())) {
116 
117  if (request.getExtensions().get(AuthenticationTimeStamper.AUTH_TIMESTAMP) != null) {
118 
119  Long authTimestamp = Long.parseLong((String) request.getExtensions().get(AuthenticationTimeStamper.AUTH_TIMESTAMP));
120  if (authTimestamp != null) {
121  idClaims.claim("auth_time", authTimestamp / 1000L);
122  }
123  } else {
124  // we couldn't find the timestamp!
125  logger.warn("Unable to find authentication timestamp! There is likely something wrong with the configuration.");
126  }
127  }
128 
129  idClaims.issueTime(issueTime);
130 
131  if (client.getIdTokenValiditySeconds() != null) {
132  Date expiration = new Date(System.currentTimeMillis() + (client.getIdTokenValiditySeconds() * 1000L));
133  idClaims.expirationTime(expiration);
134  }
135 
136  idClaims.issuer(configBean.getIssuer());
137  idClaims.subject(sub);
138  idClaims.audience(Lists.newArrayList(client.getClientId()));
139  idClaims.jwtID(UUID.randomUUID().toString()); // set a random NONCE in the middle of it
140 
141  String nonce = (String)request.getExtensions().get(NONCE);
142  if (!Strings.isNullOrEmpty(nonce)) {
143  idClaims.claim("nonce", nonce);
144  }
145 
146  Set<String> responseTypes = request.getResponseTypes();
147 
148  if (responseTypes.contains("token")) {
149  // calculate the token hash
150  Base64URL at_hash = IdTokenHashUtils.getAccessTokenHash(signingAlg, accessToken);
151  idClaims.claim("at_hash", at_hash);
152  }
153 
154  if (client.getIdTokenEncryptedResponseAlg() != null && !client.getIdTokenEncryptedResponseAlg().equals(Algorithm.NONE)
155  && client.getIdTokenEncryptedResponseEnc() != null && !client.getIdTokenEncryptedResponseEnc().equals(Algorithm.NONE)
156  && (!Strings.isNullOrEmpty(client.getJwksUri()) || client.getJwks() != null)) {
157 
158  JWTEncryptionAndDecryptionService encrypter = encrypters.getEncrypter(client);
159 
160  if (encrypter != null) {
161 
162  idToken = new EncryptedJWT(new JWEHeader(client.getIdTokenEncryptedResponseAlg(), client.getIdTokenEncryptedResponseEnc()), idClaims.build());
163 
164  encrypter.encryptJwt((JWEObject) idToken);
165 
166  } else {
167  logger.error("Couldn't find encrypter for client: " + client.getClientId());
168  }
169 
170  } else {
171 
172  if (signingAlg.equals(Algorithm.NONE)) {
173  // unsigned ID token
174  idToken = new PlainJWT(idClaims.build());
175 
176  } else {
177 
178  // signed ID token
179 
180  if (signingAlg.equals(JWSAlgorithm.HS256)
181  || signingAlg.equals(JWSAlgorithm.HS384)
182  || signingAlg.equals(JWSAlgorithm.HS512)) {
183 
184  JWSHeader header = new JWSHeader(signingAlg, null, null, null, null, null, null, null, null, null,
186  null, null);
187  idToken = new SignedJWT(header, idClaims.build());
188 
189  JWTSigningAndValidationService signer = symmetricCacheService.getSymmetricValidtor(client);
190 
191  // sign it with the client's secret
192  signer.signJwt((SignedJWT) idToken);
193  } else {
194  idClaims.claim("kid", jwtService.getDefaultSignerKeyId());
195 
196  JWSHeader header = new JWSHeader(signingAlg, null, null, null, null, null, null, null, null, null,
198  null, null);
199 
200  idToken = new SignedJWT(header, idClaims.build());
201 
202  // sign it with the server's key
203  jwtService.signJwt((SignedJWT) idToken);
204  }
205  }
206 
207  }
208 
209  return idToken;
210  }
static final Logger logger
Definition: DefaultOIDCTokenService.java:78
JWTEncryptionAndDecryptionService getEncrypter(ClientDetailsEntity client)
Definition: ClientKeyCacheService.java:118
JWTSigningAndValidationService jwtService
Definition: DefaultOIDCTokenService.java:81
JWTSigningAndValidationService getSymmetricValidtor(ClientDetailsEntity client)
Definition: SymmetricKeyJWTValidatorCacheService.java:72
ConfigurationPropertiesBean configBean
Definition: DefaultOIDCTokenService.java:87
ClientKeyCacheService encrypters
Definition: DefaultOIDCTokenService.java:90
SymmetricKeyJWTValidatorCacheService symmetricCacheService
Definition: DefaultOIDCTokenService.java:93
String getIssuer()
Definition: ConfigurationPropertiesBean.java:100

◆ createRegistrationAccessToken()

OAuth2AccessTokenEntity org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.createRegistrationAccessToken ( ClientDetailsEntity  client)
inline
引数
client
戻り値
例外
AuthenticationException

org.mitre.openid.connect.service.OIDCTokenServiceを実装しています。

218  {
219 
220  return createAssociatedToken(client, Sets.newHashSet(SystemScopeService.REGISTRATION_TOKEN_SCOPE));
221 
222  }
OAuth2AccessTokenEntity createAssociatedToken(ClientDetailsEntity client, Set< String > scope)
Definition: DefaultOIDCTokenService.java:249

◆ createResourceAccessToken()

OAuth2AccessTokenEntity org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.createResourceAccessToken ( ClientDetailsEntity  client)
inline
引数
client
戻り値

org.mitre.openid.connect.service.OIDCTokenServiceを実装しています。

229  {
230 
231  return createAssociatedToken(client, Sets.newHashSet(SystemScopeService.RESOURCE_TOKEN_SCOPE));
232 
233  }
OAuth2AccessTokenEntity createAssociatedToken(ClientDetailsEntity client, Set< String > scope)
Definition: DefaultOIDCTokenService.java:249

◆ getAuthenticationHolderRepository()

AuthenticationHolderRepository org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.getAuthenticationHolderRepository ( )
inline
戻り値
the authenticationHolderRepository
326  {
328  }
AuthenticationHolderRepository authenticationHolderRepository
Definition: DefaultOIDCTokenService.java:84

◆ getConfigBean()

ConfigurationPropertiesBean org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.getConfigBean ( )
inline
戻り値
the configBean
298  {
299  return configBean;
300  }
ConfigurationPropertiesBean configBean
Definition: DefaultOIDCTokenService.java:87

◆ getJwtService()

JWTSigningAndValidationService org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.getJwtService ( )
inline
戻り値
the jwtService
312  {
313  return jwtService;
314  }
JWTSigningAndValidationService jwtService
Definition: DefaultOIDCTokenService.java:81

◆ rotateRegistrationAccessTokenForClient()

OAuth2AccessTokenEntity org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.rotateRegistrationAccessTokenForClient ( ClientDetailsEntity  client)
inline

org.mitre.openid.connect.service.OIDCTokenServiceを実装しています。

236  {
237  // revoke any previous tokens
238  OAuth2AccessTokenEntity oldToken = tokenService.getRegistrationAccessTokenForClient(client);
239  if (oldToken != null) {
240  Set<String> scope = oldToken.getScope();
242  return createAssociatedToken(client, scope);
243  } else {
244  return null;
245  }
246 
247  }
OAuth2AccessTokenEntity getRegistrationAccessTokenForClient(ClientDetailsEntity client)
Set< String > getScope()
Definition: OAuth2AccessTokenEntity.java:245
OAuth2AccessTokenEntity createAssociatedToken(ClientDetailsEntity client, Set< String > scope)
Definition: DefaultOIDCTokenService.java:249
OAuth2TokenEntityService tokenService
Definition: DefaultOIDCTokenService.java:96
void revokeAccessToken(OAuth2AccessTokenEntity accessToken)

◆ setAuthenticationHolderRepository()

void org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.setAuthenticationHolderRepository ( AuthenticationHolderRepository  authenticationHolderRepository)
inline
引数
authenticationHolderRepositorythe authenticationHolderRepository to set
334  {
336  }
AuthenticationHolderRepository authenticationHolderRepository
Definition: DefaultOIDCTokenService.java:84

◆ setConfigBean()

void org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.setConfigBean ( ConfigurationPropertiesBean  configBean)
inline
引数
configBeanthe configBean to set
305  {
306  this.configBean = configBean;
307  }
ConfigurationPropertiesBean configBean
Definition: DefaultOIDCTokenService.java:87

◆ setJwtService()

void org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.setJwtService ( JWTSigningAndValidationService  jwtService)
inline
引数
jwtServicethe jwtService to set
319  {
320  this.jwtService = jwtService;
321  }
JWTSigningAndValidationService jwtService
Definition: DefaultOIDCTokenService.java:81

メンバ詳解

◆ authenticationHolderRepository

AuthenticationHolderRepository org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.authenticationHolderRepository
private

◆ configBean

ConfigurationPropertiesBean org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.configBean
private

◆ encrypters

ClientKeyCacheService org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.encrypters
private

◆ jwtService

JWTSigningAndValidationService org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.jwtService
private

◆ logger

final Logger org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.logger = LoggerFactory.getLogger(DefaultOIDCTokenService.class)
staticprivate

Logger for this class

◆ symmetricCacheService

SymmetricKeyJWTValidatorCacheService org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.symmetricCacheService
private

◆ tokenService

OAuth2TokenEntityService org.mitre.openid.connect.service.impl.DefaultOIDCTokenService.tokenService
private

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