use of org.springframework.security.oauth2.common.exceptions.InvalidTokenException in project vorto by eclipse.
the class PublicKeyHelper method toPublicKey.
public static PublicKey toPublicKey(String mod, String exp) {
try {
Decoder urlDecoder = Base64.getUrlDecoder();
BigInteger modulus = new BigInteger(1, urlDecoder.decode(mod));
BigInteger publicExponent = new BigInteger(1, urlDecoder.decode(exp));
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
} catch (Exception e) {
throw new InvalidTokenException("Problem converting the common keys to public keys", e);
}
}
use of org.springframework.security.oauth2.common.exceptions.InvalidTokenException in project vorto by eclipse.
the class BoschIoTSuiteOAuthProviderAuthCode method createAuthentication.
private OAuth2Authentication createAuthentication(JwtToken accessToken) {
Map<String, Object> tokenPayload = accessToken.getPayloadMap();
Optional<String> email = Optional.ofNullable((String) tokenPayload.get(JWT_EMAIL));
Optional<String> name = Optional.ofNullable((String) tokenPayload.get(JWT_NAME)).map(str -> str.split("@")[0]);
String userId = getUserId(tokenPayload).orElseThrow(() -> new InvalidTokenException("Cannot generate a userId from your provided token. Maybe 'sub' or 'client_id' is not present in JWT token?"));
return Optional.ofNullable(userAccountService.getUser(userId)).map(user -> createAuthentication(this.clientId, userId, name.orElse(userId), email.orElse(null), userNamespaceRoleService.getRolesOnAllNamespaces(user))).orElse(null);
}
use of org.springframework.security.oauth2.common.exceptions.InvalidTokenException in project vorto by eclipse.
the class BoschIDOAuthProvider method createAuthentication.
/**
* Authenticates the user from the CIAM issued token by checking if the user is registered in the
* Repository
*/
@Override
public OAuth2Authentication createAuthentication(HttpServletRequest httpRequest, JwtToken accessToken) {
Map<String, Object> tokenPayload = accessToken.getPayloadMap();
Optional<String> email = Optional.ofNullable((String) tokenPayload.get(JWT_EMAIL));
Optional<String> name = Optional.ofNullable((String) tokenPayload.get(JWT_NAME)).map(str -> str.split("@")[0]);
String userId = getUserId(tokenPayload).orElseThrow(() -> new InvalidTokenException("Cannot generate a userId from your provided token. Maybe 'sub' or 'client_id' is not present in JWT token?"));
User user = userAccountService.getUser(userId);
if (user == null) {
throw new InvalidTokenException("User from token is not a registered user in the repository!");
}
return createAuthentication(this.ciamClientId, userId, name.orElse(userId), email.orElse(null), userNamespaceRoleService.getRolesOnAllNamespaces(user));
}
Aggregations