@NotNull private Properties createProperties(@NotNull ServerConfig serverConfig) { final Properties props = createProperties(); // Should always be set. props.setProperty(PropertyDefs.USER_NAME_KEY, serverConfig.getUsername()); if (serverConfig.hasAuthTicket() && serverConfig.getAuthTicket() != null) { props.setProperty(PropertyDefs.TICKET_PATH_KEY, serverConfig.getAuthTicket().getAbsolutePath()); } // This doesn't actually do anything with the default connection that we use. // props.setProperty(PropertyDefs.PASSWORD_KEY, knownPassword); if (serverConfig.hasTrustTicket() && serverConfig.getTrustTicket() != null) { props.setProperty(PropertyDefs.TRUST_PATH_KEY, serverConfig.getTrustTicket().getAbsolutePath()); } if (serverConfig.hasTrustTicket() && serverConfig.getTrustTicket() != null) { props.setProperty(PropertyDefs.TRUST_PATH_KEY, serverConfig.getTrustTicket().getAbsolutePath()); } return props; }
@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; }
@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()); }
if (! filesEqual(hasTrustTicket(), getTrustTicket(), part.hasTrustTicketFileSet(), part.getTrustTicketFile())) { if (LOG.isDebugEnabled()) { LOG.debug("isSameServerConnection: trust ticket doesn't match: "