gluu
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.xdi.oxauth.model.token.ClientAssertion クラス
org.xdi.oxauth.model.token.ClientAssertion 連携図
Collaboration graph

公開メンバ関数

 ClientAssertion (AppConfiguration appConfiguration, String clientId, ClientAssertionType clientAssertionType, String encodedAssertion) throws InvalidJwtException
 
String getSubjectIdentifier ()
 
String getClientSecret ()
 

非公開メンバ関数

boolean load (AppConfiguration appConfiguration, String clientId, ClientAssertionType clientAssertionType, String encodedAssertion) throws Exception
 

非公開変数類

Jwt jwt
 
String clientSecret
 

詳解

著者
Javier Rojas Blum
バージョン
August 28, 2017

構築子と解体子

◆ ClientAssertion()

org.xdi.oxauth.model.token.ClientAssertion.ClientAssertion ( AppConfiguration  appConfiguration,
String  clientId,
ClientAssertionType  clientAssertionType,
String  encodedAssertion 
) throws InvalidJwtException
inline
43  {
44  try {
45  if (!load(appConfiguration, clientId, clientAssertionType, encodedAssertion)) {
46  throw new InvalidJwtException("Cannot load the JWT");
47  }
48  } catch (StringEncrypter.EncryptionException e) {
49  throw new InvalidJwtException(e.getMessage(), e);
50  } catch (Exception e) {
51  throw new InvalidJwtException("Cannot verify the JWT", e);
52  }
53  }
boolean load(AppConfiguration appConfiguration, String clientId, ClientAssertionType clientAssertionType, String encodedAssertion)
Definition: ClientAssertion.java:63

関数詳解

◆ getClientSecret()

String org.xdi.oxauth.model.token.ClientAssertion.getClientSecret ( )
inline
59  {
60  return clientSecret;
61  }
String clientSecret
Definition: ClientAssertion.java:40

◆ getSubjectIdentifier()

String org.xdi.oxauth.model.token.ClientAssertion.getSubjectIdentifier ( )
inline
55  {
56  return jwt.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER);
57  }
String getClaimAsString(String key)
Definition: JwtClaimSet.java:55
JwtClaims getClaims()
Definition: JsonWebResponse.java:41
Jwt jwt
Definition: ClientAssertion.java:39

◆ load()

boolean org.xdi.oxauth.model.token.ClientAssertion.load ( AppConfiguration  appConfiguration,
String  clientId,
ClientAssertionType  clientAssertionType,
String  encodedAssertion 
) throws Exception
inlineprivate
64  {
65  boolean result;
66 
67  if (clientAssertionType == ClientAssertionType.JWT_BEARER) {
68  if (StringUtils.isNotBlank(encodedAssertion)) {
69  jwt = Jwt.parse(encodedAssertion);
70 
71  // TODO: Store jti this value to check for duplicates
72 
73  // Validate clientId
74  String issuer = jwt.getClaims().getClaimAsString(JwtClaimName.ISSUER);
75  String subject = jwt.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER);
76  List<String> audience = jwt.getClaims().getClaimAsStringList(JwtClaimName.AUDIENCE);
77  Date expirationTime = jwt.getClaims().getClaimAsDate(JwtClaimName.EXPIRATION_TIME);
78  //SignatureAlgorithm algorithm = SignatureAlgorithm.fromName(jwt.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM));
79  if ((clientId == null && StringUtils.isNotBlank(issuer) && StringUtils.isNotBlank(subject) && issuer.equals(subject))
80  || (StringUtils.isNotBlank(clientId) && StringUtils.isNotBlank(issuer)
81  && StringUtils.isNotBlank(subject) && clientId.equals(issuer) && issuer.equals(subject))) {
82 
83  // Validate audience
84  String tokenUrl = appConfiguration.getTokenEndpoint();
85  if (audience != null && audience.contains(tokenUrl)) {
86 
87  // Validate expiration
88  if (expirationTime.after(new Date())) {
89  ClientService clientService = CdiUtil.bean(ClientService.class);
90  Client client = clientService.getClient(subject);
91 
92  // Validate client
93  if (client != null) {
94  JwtType jwtType = JwtType.fromString(jwt.getHeader().getClaimAsString(JwtHeaderName.TYPE));
95  AuthenticationMethod authenticationMethod = client.getAuthenticationMethod();
96  SignatureAlgorithm signatureAlgorithm = jwt.getHeader().getAlgorithm();
97 
98  if (jwtType == null && signatureAlgorithm != null) {
99  jwtType = signatureAlgorithm.getJwtType();
100  }
101 
102  if (jwtType != null && signatureAlgorithm != null && signatureAlgorithm.getFamily() != null &&
103  ((authenticationMethod == AuthenticationMethod.CLIENT_SECRET_JWT && SignatureAlgorithmFamily.HMAC.equals(signatureAlgorithm.getFamily()))
104  || (authenticationMethod == AuthenticationMethod.PRIVATE_KEY_JWT && (SignatureAlgorithmFamily.RSA.equals(signatureAlgorithm.getFamily()) || SignatureAlgorithmFamily.EC.equals(signatureAlgorithm.getFamily()))))) {
105  if (client.getTokenEndpointAuthSigningAlg() == null || SignatureAlgorithm.fromString(client.getTokenEndpointAuthSigningAlg()).equals(signatureAlgorithm)) {
106  clientSecret = clientService.decryptSecret(client.getClientSecret());
107 
108  // Validate the crypto segment
109  String keyId = jwt.getHeader().getKeyId();
110  JSONObject jwks = Strings.isNullOrEmpty(client.getJwks()) ?
111  JwtUtil.getJSONWebKeys(client.getJwksUri()) :
112  new JSONObject(client.getJwks());
113  String sharedSecret = clientService.decryptSecret(client.getClientSecret());
114  AbstractCryptoProvider cryptoProvider = CryptoProviderFactory.getCryptoProvider(
115  appConfiguration);
116  boolean validSignature = cryptoProvider.verifySignature(jwt.getSigningInput(), jwt.getEncodedSignature(),
117  keyId, jwks, sharedSecret, signatureAlgorithm);
118 
119  if (validSignature) {
120  result = true;
121  } else {
122  throw new InvalidJwtException("Invalid cryptographic segment");
123  }
124  } else {
125  throw new InvalidJwtException("Invalid signing algorithm");
126  }
127  } else {
128  throw new InvalidJwtException("Invalid authentication method");
129  }
130  } else {
131  throw new InvalidJwtException("Invalid client");
132  }
133  } else {
134  throw new InvalidJwtException("JWT has expired");
135  }
136  } else {
137  throw new InvalidJwtException("Invalid audience: " + audience + ", tokenUrl: " + tokenUrl);
138  }
139  } else {
140  throw new InvalidJwtException("Invalid clientId");
141  }
142  } else {
143  throw new InvalidJwtException("The Client Assertion is null or empty");
144  }
145  } else {
146  throw new InvalidJwtException("Invalid Client Assertion Type");
147  }
148 
149  return result;
150  }
JwtType getJwtType()
Definition: SignatureAlgorithm.java:79
String getClaimAsString(String key)
Definition: JwtClaimSet.java:55
String getSigningInput()
Definition: Jwt.java:46
JwtClaims getClaims()
Definition: JsonWebResponse.java:41
SignatureAlgorithm getAlgorithm()
Definition: JwtHeader.java:53
List< String > getClaimAsStringList(String key)
Definition: JwtClaimSet.java:81
String getEncodedSignature()
Definition: Jwt.java:38
Jwt jwt
Definition: ClientAssertion.java:39
Date getClaimAsDate(String key)
Definition: JwtClaimSet.java:103
String getKeyId()
Definition: JwtHeader.java:86
JwtHeader getHeader()
Definition: JsonWebResponse.java:33
String clientSecret
Definition: ClientAssertion.java:40
static Jwt parse(String encodedJwt)
Definition: Jwt.java:54

メンバ詳解

◆ clientSecret

String org.xdi.oxauth.model.token.ClientAssertion.clientSecret
private

◆ jwt

Jwt org.xdi.oxauth.model.token.ClientAssertion.jwt
private

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