@Test public void testLogin() { try { Node node = new LocalNodeManager().launchNode(); UserAgentManager l = node.getUserManager(); UserAgentImpl a = UserAgentImpl.createUserAgent("pass"); a.unlock("pass"); a.setLoginName("login"); node.storeAgent(a); assertEquals(a.getIdentifier(), l.getAgentIdByLogin("login")); UserAgentImpl b = UserAgentImpl.createUserAgent("pass"); b.unlock("pass"); b.setLoginName("login"); try { node.storeAgent(b); fail("LoginNameAlreadyTakenException expected"); } catch (LoginNameAlreadyTakenException e) { } b.setLoginName("login2"); node.storeAgent(b); assertEquals(b.getIdentifier(), l.getAgentIdByLogin("login2")); b.setLoginName("LOGIN"); try { node.storeAgent(b); fail("LoginNameAlreadyTakenException expected"); } catch (LoginNameAlreadyTakenException e) { } assertEquals(a.getIdentifier(), l.getAgentIdByLogin("LOGIN")); try { l.getAgentIdByLogin("fdewfue"); fail("AgentNotFoundException expected"); } catch (AgentNotFoundException e) { } } catch (Exception e) { e.printStackTrace(); } }
public String getAgentIdByLogin(String name) throws AgentNotFoundException, AgentOperationFailedException { if (name.equalsIgnoreCase(AnonymousAgent.LOGIN_NAME)) { return AnonymousAgentImpl.getInstance().getIdentifier(); } try { EnvelopeVersion env = node.fetchEnvelope(PREFIX_USER_NAME + name.toLowerCase()); return (String) env.getContent(); } catch (EnvelopeNotFoundException e) { throw new AgentNotFoundException("Username not found!", e); } catch (EnvelopeException | SerializationException | CryptoException e) { throw new AgentOperationFailedException("Could not read agent id from storage"); } }
UserAgentManager { public String getAgentIdByLogin(String name) throws AgentNotFoundException, AgentOperationFailedException { if (name.equalsIgnoreCase(AnonymousAgent.LOGIN_NAME)) { return AnonymousAgentImpl.getInstance().getIdentifier(); } try { EnvelopeVersion env = node.fetchEnvelope(PREFIX_USER_NAME + name.toLowerCase()); return (String) env.getContent(); } catch (EnvelopeNotFoundException e) { throw new AgentNotFoundException("Username not found!", e); } catch (EnvelopeException | SerializationException | CryptoException e) { throw new AgentOperationFailedException("Could not read agent id from storage"); } } }
UserAgentManager { public String getAgentIdByLogin(String name) throws AgentNotFoundException, AgentOperationFailedException { if (name.equalsIgnoreCase(AnonymousAgent.LOGIN_NAME)) { return AnonymousAgentImpl.getInstance().getIdentifier(); } try { EnvelopeVersion env = node.fetchEnvelope(PREFIX_USER_NAME + name.toLowerCase()); return (String) env.getContent(); } catch (EnvelopeNotFoundException e) { throw new AgentNotFoundException("Username not found!", e); } catch (EnvelopeException | SerializationException | CryptoException e) { throw new AgentOperationFailedException("Could not read agent id from storage"); } } UserAgentManager(Node node); }
UserAgentManager { public String getAgentIdByLogin(String name) throws AgentNotFoundException, AgentOperationFailedException { if (name.equalsIgnoreCase(AnonymousAgent.LOGIN_NAME)) { return AnonymousAgentImpl.getInstance().getIdentifier(); } try { EnvelopeVersion env = node.fetchEnvelope(PREFIX_USER_NAME + name.toLowerCase()); return (String) env.getContent(); } catch (EnvelopeNotFoundException e) { throw new AgentNotFoundException("Username not found!", e); } catch (EnvelopeException | SerializationException | CryptoException e) { throw new AgentOperationFailedException("Could not read agent id from storage"); } } UserAgentManager(Node node); void registerUserAgent(UserAgent agent); void registerOIDCSub(UserAgentImpl agent, String sub); String getAgentId(String prefixedIdentifier); String getAgentIdByLogin(String name); String getAgentIdByEmail(String email); String getAgentIdByOIDCSub(String sub); }
UserAgentManager { public String getAgentIdByLogin(String name) throws AgentNotFoundException, AgentOperationFailedException { if (name.equalsIgnoreCase(AnonymousAgent.LOGIN_NAME)) { return AnonymousAgentImpl.getInstance().getIdentifier(); } try { EnvelopeVersion env = node.fetchEnvelope(PREFIX_USER_NAME + name.toLowerCase()); return (String) env.getContent(); } catch (EnvelopeNotFoundException e) { throw new AgentNotFoundException("Username not found!", e); } catch (EnvelopeException | SerializationException | CryptoException e) { throw new AgentOperationFailedException("Could not read agent id from storage"); } } UserAgentManager(Node node); void registerUserAgent(UserAgent agent); void registerOIDCSub(UserAgentImpl agent, String sub); String getAgentId(String prefixedIdentifier); String getAgentIdByLogin(String name); String getAgentIdByEmail(String email); String getAgentIdByOIDCSub(String sub);  }