@NotNull public static Map<String, String> toProperties(@NotNull ServerConfig config, @Nullable String valueIfUnset, @Nullable String valueIfPasswordStored, @Nullable String valueIfPasswordNotStored) { Map<String, String> ret = new HashMap<>(); ret.put(PerforceEnvironment.P4PORT, config.getServerName().getDisplayName()); ret.put(PerforceEnvironment.P4TRUST, ! config.hasTrustTicket() || config.getTrustTicket() == null ? valueIfUnset : config.getTrustTicket().toString()); ret.put(PerforceEnvironment.P4USER, config.getUsername()); ret.put(PerforceEnvironment.P4TICKETS, ! config.hasAuthTicket() || config.getAuthTicket() == null ? valueIfUnset : config.getAuthTicket().toString()); ret.put(PerforceEnvironment.P4SERVER_FINGERPRINT, ! config.hasServerFingerprint() || config.getServerFingerprint() == null ? valueIfUnset : config.getServerFingerprint()); ret.put(PerforceEnvironment.P4PASSWD, config.usesStoredPassword() ? valueIfPasswordStored : valueIfPasswordNotStored); ret.put(PerforceEnvironment.P4LOGINSSO, ! config.hasLoginSso() || config.getLoginSso() == null ? valueIfUnset : config.getLoginSso()); return ret; }
private Answer<OneTimeString> getPassword(@NotNull final ServerConfig serverConfig) { if (serverConfig.usesStoredPassword()) { if (LOG.isDebugEnabled()) { LOG.debug("Using password stored in registry."); } // Custom promise handler. We want all password responses, whether a failure or a success, // to resolve. Failures shouldn't be bubbled up from this call. return Answer.resolve(null) .futureMap((x, sink) -> ApplicationPasswordRegistry.getInstance().get(serverConfig) .processed(sink::resolve) .rejected((t) -> { LOG.warn("Problem loading the password", t); sink.resolve(new OneTimeString(EMPTY_PASSWORD)); })); } return Answer.resolve(new OneTimeString(EMPTY_PASSWORD)); }
if (!e.getConfig().usesStoredPassword()) {
(usesStoredPassword() && (!part.requiresUserEnteredPassword() && !part.hasPasswordSet())) || (!usesStoredPassword() && (part.requiresUserEnteredPassword() || part.hasPasswordSet())) ) { return false;
@Test void createFrom_empty() { ServerConfig sc = ServerConfig.createFrom( new MockConfigPart() .withUsername("username") .withServerName("servername") ); assertEquals(P4ServerName.forPort("servername"), sc.getServerName()); assertEquals("username", sc.getUsername()); assertNull(sc.getServerFingerprint()); assertNull(sc.getAuthTicket()); assertNull(sc.getTrustTicket()); assertNull(sc.getLoginSso()); assertThat(sc.getConfigVersion(), greaterThan(0)); assertFalse(sc.hasServerFingerprint()); assertFalse(sc.hasAuthTicket()); assertFalse(sc.hasTrustTicket()); assertFalse(sc.hasLoginSso()); assertFalse(sc.usesStoredPassword()); assertEquals("localhost:servername" + SEP + "username" + SEP + "null" + SEP + "null" + SEP + "null", sc.getServerId()); }