public static boolean isValidClientConfig(@Nullable ServerConfig serverConfig, @Nullable ConfigPart part) { if (serverConfig == null || part == null || part.hasError()) { return false; } if (isBlank(part.getClientname())) { return false; } if (isBlank(serverConfig.getUsername())) { return false; } return true; }
@NotNull protected CredentialAttributes getCredentialAttributes(@NotNull ServerConfig config, boolean inMemory) { return new CredentialAttributes( "p4ic4idea:" + config.getServerName().getFullPort(), config.getUsername(), null, inMemory); } }
public P4CommandRunner.QueryAnswer<ListClientsForUserResult> checkServerConnection(ServerConfig config) { // This is necessary for loading a project from version control when the project isn't setup yet. // Init is happening earlier now // initComponent(); return connectRunner.getClientsForUser(config, new ListClientsForUserQuery(config.getUsername(), 1)); }
public P4CommandRunner.QueryAnswer<ListClientsForUserResult> getClientsForUser(ServerConfig config) { // This is necessary for loading a project from version control when the project isn't setup yet. // Init is happening earlier now // initComponent(); return connectRunner.getClientsForUser(config, new ListClientsForUserQuery(config.getUsername(), UserProjectPreferences.getMaxClientRetrieveCount(project))); }
@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; }
private Promise<OneTimeString> promptForPassword(@Nullable Project project, @NotNull ServerConfig config) { final AsyncPromise<OneTimeString> ret = new AsyncPromise<>(); // Because this can happen while a dialog is shown, we instead want to force it to run. // So don't use the ApplicationManager to run later. EventQueue.invokeLater(() -> { CredentialPromptDialog.askPassword( project, P4Bundle.getString("login.password.title"), P4Bundle.message("login.password.message", config.getServerName().getDisplayName(), config.getUsername()), getCredentialAttributes(config, false), true, null); }); return ret; } }
/** * Remove the password associated with the configuration. * * @param config server configuration for the password. */ public final void remove(@NotNull ServerConfig config) { if (LOG.isDebugEnabled()) { LOG.debug("Removing password for config " + config.getServerName()); } CredentialAttributes attr = getCredentialAttributes(config, false); PasswordSafe.getInstance().set(attr, new Credentials(config.getUsername(), (String) null)); }
/** * Stores the given password in the registry, associated with the config. After being * called, the password will be blanked out. * * @param config * @param password */ public final void store(@NotNull ServerConfig config, @NotNull char[] password, boolean inMemoryOnly) { if (LOG.isDebugEnabled()) { LOG.debug("Storing password for config " + config.getServerName()); } final CredentialAttributes attr = getCredentialAttributes(config, inMemoryOnly); PasswordSafe.getInstance().set(attr, new Credentials(config.getUsername(), password)); for (int i = 0; i < password.length; i++) { password[i] = 0; } }
public MockP4RemoteChangelist withConfig(ClientConfig cc) { csRef = cc.getClientServerRef(); //clientname = cc.getClientname(); //serverName = csRef.getServerName(); username = cc.getServerConfig().getUsername(); summary = null; return this; }
private IOptionsServer setupServer(@NotNull ServerConfig config) throws P4JavaException { Server s = setupServer(config.getServerName()); if (serverConfig != null) { s = serverConfig.configure(config, s); } when(s.getUserName()).thenReturn(config.getUsername()); return s; }
private static Collection<P4LocalChangelist> createOpenedChanges( @NotNull ClientConfig clientConfig, @NotNull List<IChangelist> changes, @NotNull List<IExtendedFileSpec> pendingChangelistFiles, @NotNull Map<Integer, List<IFileSpec>> shelvedFiles, @NotNull List<IExtendedFileSpec> openedDefaultChangelistFiles) { List<P4LocalChangelist> ret = new ArrayList<>(changes.size() + 1); // Default changelist ret.add(new P4LocalChangelistImpl.Builder() .withDefaultChangelist(clientConfig.getClientServerRef()) .withClientname(clientConfig.getClientname()) .withUsername(clientConfig.getServerConfig().getUsername()) .withComment("") .withContainedFiles(getLocalFiles(openedDefaultChangelistFiles)) .build()); for (IChangelist change : changes) { ret.add( new P4LocalChangelistImpl.Builder() .withChangelistId(clientConfig.getClientServerRef(), change.getId()) .withClientname(clientConfig.getClientname()) .withUsername(clientConfig.getServerConfig().getUsername()) .withComment(change.getDescription()) .withShelvedFiles(toShelvedFiles(shelvedFiles.get(change.getId()))) .withDeleted(false) .withContainedFiles(toFiles(change, pendingChangelistFiles)) .build() ); } return ret; }
private P4Job createP4Job(ServerConfig config, GetJobSpecResult jobSpec) { assertNotNull(jobSpec); Map<String, Object> details = new HashMap<>(); for (P4JobField jobField : jobSpec.getJobSpec().getFields()) { if (jobField.getSelectValues() != null && !jobField.getSelectValues().isEmpty()) { details.put(jobField.getName(), jobField.getSelectValues().get(0)); } else if (jobField.getPreset() == null) { details.put(jobField.getName(), "unknown"); } } details.put("User", config.getUsername()); return new P4JobImpl(JOB_ID, JOB_DESCRIPTION, details); }
changelist.type = P4ChangelistType.PUBLIC; changelist.deleted = false; changelist.username = root.getServerConfig().getUsername(); changelist.clientname = root.getClientConfig().getClientname(); changelist.shelvedFiles = new ArrayList<>();
new ListClientsForUserQuery(state.config.getUsername(), 1)) .whenCompleted((x) -> { if (LOG.isDebugEnabled()) {
@Test void getCachedOpenedChangelists_noActions() { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); ClientQueryCacheStore clientStore = new ClientQueryCacheStore(clientConfig.getClientServerRef()); P4LocalChangelist cl1 = new P4LocalChangelistImpl.Builder() .withChangelistId(new P4ChangelistIdImpl(1, clientConfig.getClientServerRef())) .withComment("comment 1") .withClientname(clientConfig.getClientname()) .withUsername(serverConfig.getUsername()) .build(); clientStore.setChangelists(cl1); projectStore.addCache(clientStore); Collection<P4LocalChangelist> changes = query.getCachedOpenedChangelists(clientConfig); assertSize(1, changes); assertEqualChangelists(cl1, changes.iterator().next()); }
final Map<String, Object> jobDetails = new HashMap<>(); jobDetails.put("Status", "closed"); jobDetails.put("User", serverConfig.getUsername());
@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()); }
@Test void getCachedOpenedChangelists_deleteAction() { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); ClientQueryCacheStore clientStore = new ClientQueryCacheStore(clientConfig.getClientServerRef()); P4LocalChangelist cl1 = new P4LocalChangelistImpl.Builder() .withChangelistId(new P4ChangelistIdImpl(1, clientConfig.getClientServerRef())) .withComment("comment 1") .withClientname(clientConfig.getClientname()) .withUsername(serverConfig.getUsername()) .build(); projectStore.addPendingAction(ActionStore.createPendingAction( clientConfig.getClientServerRef(), new DeleteChangelistAction(cl1.getChangelistId()))); clientStore.setChangelists(cl1); projectStore.addCache(clientStore); Collection<P4LocalChangelist> changes = query.getCachedOpenedChangelists(clientConfig); assertSize(0, changes); }
assertEquals(config.getUsername(), result[0].getJob().getRawDetails().get("User"));