@Test public void loginWithJWT() throws AuthException, ParseException, IOException, URISyntaxException { String jwt = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJxMS1XbTBvelE1TzBtUUg4LVNKYXAyWmNONE1tdWNXd25RV0tZeFpKNG93In0.eyJleHAiOjE1OTAzMTcxNzYsImlhdCI6MTU5MDMxNjg3NiwianRpIjoiY2MyNWQ3MDAtYjc5NC00OTA4LTg0OGUtOTRhNzYzNmM5YzQxIiwiaXNzIjoiaHR0cDovL2F1dGguZGVtby5wcmFnbWF0aWNpbmR1c3RyaWVzLmRlL2F1dGgvcmVhbG1zL0lvVERCIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6Ijg2YWRmNGIzLWE4ZTUtNDc1NC1iNWEwLTQ4OGI0OWY0M2VkMiIsInR5cCI6IkJlYXJlciIsImF6cCI6ImlvdGRiIiwic2Vzc2lvbl9zdGF0ZSI6Ijk0ZmI5NGZjLTg3YTMtNDg4Ny04M2Q3LWE5MmQ1MzMzOTMzMCIsImFjciI6IjEiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImNsaWVudEhvc3QiOiIxOTIuMTY4LjE2OS4yMSIsImNsaWVudElkIjoiaW90ZGIiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsInByZWZlcnJlZF91c2VybmFtZSI6InNlcnZpY2UtYWNjb3VudC1pb3RkYiIsImNsaWVudEFkZHJlc3MiOiIxOTIuMTY4LjE2OS4yMSJ9.GxQFltm1PrZzVL7rR6K-GpQINFLymjqAxxoDt_DGfQEMt61M6ebmx2oHiP_3G0HDSl7sbamajQbbRrfyTg--emBC2wfhdZ7v_7O0qWC60Yd8cWZ9qxwqwTFKYb8a0Z6_TeH9-vUmsy6kp2BfJZXq3mSy0My21VGUAXRmWTbghiM4RFoHKjAZVhsPHWelFmtLftYPdOGxv-7c9iUOVh_W-nOcCNRJpYY7BEjUYN24TsjvCEwWDQWD9E29LMYfA6LNeG0KdL9Jvqad4bc2FTJn9TaCnJMCiAJ7wEEiotqhXn70uEBWYxGXIVlm3vn3MDe3pTKA2TZy7U5xcrE7S8aGMg"; OpenIdAuthorizer authorizer = new OpenIdAuthorizer(JSONObjectUtils.parse(OPEN_ID_PUBLIC_JWK)); boolean login = authorizer.login(jwt, null); assertTrue(login); }
@Override public boolean login(String token, String password) throws AuthException { if (password != null && !password.isEmpty()) { logger.error("JWT Login failed as a non-empty Password was given username (token): {}, password: {}", token, password); return false; } if (token == null || token.isEmpty()) { logger.error("JWT Login failed as a Username (token) was empty!"); return false; } Claims claims; try { claims = validateToken(token); } catch (JwtException e) { logger.error("Unable to login the user wit jwt {}", password, e); return false; } logger.debug("JWT was validated successfully!"); logger.debug("ID: {}", claims.getId()); logger.debug("Subject: {}", claims.getSubject()); logger.debug("Issuer: {}", claims.getIssuer()); logger.debug("Expiration: {}", claims.getExpiration()); String iotdbUsername = getUsername(claims); if (!super.listAllUsers().contains(iotdbUsername)) { logger.info("User {} logs in for first time, storing it locally!", iotdbUsername); super.createUser(iotdbUsername, UUID.randomUUID().toString()); } this.loggedClaims.put(getUsername(claims), claims); return true; }
OpenIdAuthorizer extends BasicAuthorizer { @Override public boolean login(String token, String password) throws AuthException { if (password != null && !password.isEmpty()) { logger.error("JWT Login failed as a non-empty Password was given username (token): {}, password: {}", token, password); return false; } if (token == null || token.isEmpty()) { logger.error("JWT Login failed as a Username (token) was empty!"); return false; } Claims claims; try { claims = validateToken(token); } catch (JwtException e) { logger.error("Unable to login the user wit jwt {}", password, e); return false; } logger.debug("JWT was validated successfully!"); logger.debug("ID: {}", claims.getId()); logger.debug("Subject: {}", claims.getSubject()); logger.debug("Issuer: {}", claims.getIssuer()); logger.debug("Expiration: {}", claims.getExpiration()); String iotdbUsername = getUsername(claims); if (!super.listAllUsers().contains(iotdbUsername)) { logger.info("User {} logs in for first time, storing it locally!", iotdbUsername); super.createUser(iotdbUsername, UUID.randomUUID().toString()); } this.loggedClaims.put(getUsername(claims), claims); return true; } }
OpenIdAuthorizer extends BasicAuthorizer { @Override public boolean login(String token, String password) throws AuthException { if (password != null && !password.isEmpty()) { logger.error("JWT Login failed as a non-empty Password was given username (token): {}, password: {}", token, password); return false; } if (token == null || token.isEmpty()) { logger.error("JWT Login failed as a Username (token) was empty!"); return false; } Claims claims; try { claims = validateToken(token); } catch (JwtException e) { logger.error("Unable to login the user wit jwt {}", password, e); return false; } logger.debug("JWT was validated successfully!"); logger.debug("ID: {}", claims.getId()); logger.debug("Subject: {}", claims.getSubject()); logger.debug("Issuer: {}", claims.getIssuer()); logger.debug("Expiration: {}", claims.getExpiration()); String iotdbUsername = getUsername(claims); if (!super.listAllUsers().contains(iotdbUsername)) { logger.info("User {} logs in for first time, storing it locally!", iotdbUsername); super.createUser(iotdbUsername, UUID.randomUUID().toString()); } this.loggedClaims.put(getUsername(claims), claims); return true; } OpenIdAuthorizer();   OpenIdAuthorizer(JSONObject jwk);   OpenIdAuthorizer(String providerUrl); }
OpenIdAuthorizer extends BasicAuthorizer { @Override public boolean login(String token, String password) throws AuthException { if (password != null && !password.isEmpty()) { logger.error("JWT Login failed as a non-empty Password was given username (token): {}, password: {}", token, password); return false; } if (token == null || token.isEmpty()) { logger.error("JWT Login failed as a Username (token) was empty!"); return false; } Claims claims; try { claims = validateToken(token); } catch (JwtException e) { logger.error("Unable to login the user wit jwt {}", password, e); return false; } logger.debug("JWT was validated successfully!"); logger.debug("ID: {}", claims.getId()); logger.debug("Subject: {}", claims.getSubject()); logger.debug("Issuer: {}", claims.getIssuer()); logger.debug("Expiration: {}", claims.getExpiration()); String iotdbUsername = getUsername(claims); if (!super.listAllUsers().contains(iotdbUsername)) { logger.info("User {} logs in for first time, storing it locally!", iotdbUsername); super.createUser(iotdbUsername, UUID.randomUUID().toString()); } this.loggedClaims.put(getUsername(claims), claims); return true; } OpenIdAuthorizer();   OpenIdAuthorizer(JSONObject jwk);   OpenIdAuthorizer(String providerUrl); @Override boolean login(String token, String password); @Override void createUser(String username, String password); @Override void deleteUser(String username); @Override boolean checkUserPrivileges(String username, String path, int privilegeId); @Override void updateUserPassword(String username, String newPassword); }
OpenIdAuthorizer extends BasicAuthorizer { @Override public boolean login(String token, String password) throws AuthException { if (password != null && !password.isEmpty()) { logger.error("JWT Login failed as a non-empty Password was given username (token): {}, password: {}", token, password); return false; } if (token == null || token.isEmpty()) { logger.error("JWT Login failed as a Username (token) was empty!"); return false; } Claims claims; try { claims = validateToken(token); } catch (JwtException e) { logger.error("Unable to login the user wit jwt {}", password, e); return false; } logger.debug("JWT was validated successfully!"); logger.debug("ID: {}", claims.getId()); logger.debug("Subject: {}", claims.getSubject()); logger.debug("Issuer: {}", claims.getIssuer()); logger.debug("Expiration: {}", claims.getExpiration()); String iotdbUsername = getUsername(claims); if (!super.listAllUsers().contains(iotdbUsername)) { logger.info("User {} logs in for first time, storing it locally!", iotdbUsername); super.createUser(iotdbUsername, UUID.randomUUID().toString()); } this.loggedClaims.put(getUsername(claims), claims); return true; } OpenIdAuthorizer();   OpenIdAuthorizer(JSONObject jwk);   OpenIdAuthorizer(String providerUrl); @Override boolean login(String token, String password); @Override void createUser(String username, String password); @Override void deleteUser(String username); @Override boolean checkUserPrivileges(String username, String path, int privilegeId); @Override void updateUserPassword(String username, String newPassword); static final String IOTDB_ADMIN_ROLE_NAME; static final String OPENID_USER_PREFIX; }