@Test public void testAuthenticateWithShortenedToken() throws AuthenticationException { final HMACAuthenticator authenticator = createMockedAuthenticator(); String token = generateTokenForAuthenticatedUser(authenticator); final String brokenToken = token.substring(0, token.length() - 4); assertThrows(AuthenticationException.class, () -> authenticator.authenticate(CredentialsBuilder.build().token(brokenToken).create())); }
@Override public AuthenticatedUser authenticate(final Map<String, String> credentials) throws AuthenticationException { if (credentials.get(PROPERTY_GENERATE_TOKEN) != null) { credentials.put(PROPERTY_TOKEN, getToken(credentials)); return authenticateUser(credentials); } else if (credentials.get(PROPERTY_TOKEN) != null) { if (validateToken(credentials)) { final Map<String, String> tokenMap = parseToken(credentials.get(PROPERTY_TOKEN)); return new AuthenticatedUser(tokenMap.get(PROPERTY_USERNAME)); } else { throw new AuthenticationException("Invalid token"); } } else { return authenticateUser(credentials); } }
HMACAuthenticator extends JanusGraphAbstractAuthenticator { @Override public AuthenticatedUser authenticate(final Map<String, String> credentials) throws AuthenticationException { if (credentials.get(PROPERTY_GENERATE_TOKEN) != null) { credentials.put(PROPERTY_TOKEN, getToken(credentials)); return authenticateUser(credentials); } else if (credentials.get(PROPERTY_TOKEN) != null) { if (validateToken(credentials)) { final Map<String, String> tokenMap = parseToken(credentials.get(PROPERTY_TOKEN)); return new AuthenticatedUser(tokenMap.get(PROPERTY_USERNAME)); } else { throw new AuthenticationException("Invalid token"); } } else { return authenticateUser(credentials); } } }
HMACAuthenticator extends JanusGraphAbstractAuthenticator { @Override public AuthenticatedUser authenticate(final Map<String, String> credentials) throws AuthenticationException { if (credentials.get(PROPERTY_GENERATE_TOKEN) != null) { credentials.put(PROPERTY_TOKEN, getToken(credentials)); return authenticateUser(credentials); } else if (credentials.get(PROPERTY_TOKEN) != null) { if (validateToken(credentials)) { final Map<String, String> tokenMap = parseToken(credentials.get(PROPERTY_TOKEN)); return new AuthenticatedUser(tokenMap.get(PROPERTY_USERNAME)); } else { throw new AuthenticationException("Invalid token"); } } else { return authenticateUser(credentials); } }  }
HMACAuthenticator extends JanusGraphAbstractAuthenticator { @Override public AuthenticatedUser authenticate(final Map<String, String> credentials) throws AuthenticationException { if (credentials.get(PROPERTY_GENERATE_TOKEN) != null) { credentials.put(PROPERTY_TOKEN, getToken(credentials)); return authenticateUser(credentials); } else if (credentials.get(PROPERTY_TOKEN) != null) { if (validateToken(credentials)) { final Map<String, String> tokenMap = parseToken(credentials.get(PROPERTY_TOKEN)); return new AuthenticatedUser(tokenMap.get(PROPERTY_USERNAME)); } else { throw new AuthenticationException("Invalid token"); } } else { return authenticateUser(credentials); } }  @Override boolean requireAuthentication(); @Override SaslNegotiator newSaslNegotiator(final InetAddress remoteAddress); SaslNegotiator newSaslNegotiator(); void setup(final Map<String,Object> config); @Override AuthenticatedUser authenticate(final Map<String, String> credentials); }
HMACAuthenticator extends JanusGraphAbstractAuthenticator { @Override public AuthenticatedUser authenticate(final Map<String, String> credentials) throws AuthenticationException { if (credentials.get(PROPERTY_GENERATE_TOKEN) != null) { credentials.put(PROPERTY_TOKEN, getToken(credentials)); return authenticateUser(credentials); } else if (credentials.get(PROPERTY_TOKEN) != null) { if (validateToken(credentials)) { final Map<String, String> tokenMap = parseToken(credentials.get(PROPERTY_TOKEN)); return new AuthenticatedUser(tokenMap.get(PROPERTY_USERNAME)); } else { throw new AuthenticationException("Invalid token"); } } else { return authenticateUser(credentials); } }  @Override boolean requireAuthentication(); @Override SaslNegotiator newSaslNegotiator(final InetAddress remoteAddress); SaslNegotiator newSaslNegotiator(); void setup(final Map<String,Object> config); @Override AuthenticatedUser authenticate(final Map<String, String> credentials); static final String CONFIG_HMAC_ALGO; static final String CONFIG_TOKEN_TIMEOUT; static final String CONFIG_HMAC_SECRET; }