added authentication parsing support to add-repo dialog
This commit is contained in:
parent
96def8adca
commit
9786fd2550
@ -23,6 +23,8 @@ public class NewRepoConfig {
|
||||
private String uriString;
|
||||
private String host;
|
||||
private int port = -1;
|
||||
private String username;
|
||||
private String password;
|
||||
private String fingerprint;
|
||||
private String bssid;
|
||||
private String ssid;
|
||||
@ -91,6 +93,18 @@ public class NewRepoConfig {
|
||||
|
||||
boolean isFdroidScheme = TextUtils.equals("fdroidrepo", scheme) || TextUtils.equals("fdroidrepos", scheme);
|
||||
|
||||
String userInfo = uri.getUserInfo();
|
||||
if (userInfo != null) {
|
||||
String[] userInfoTokens = userInfo.split(":");
|
||||
if (userInfoTokens != null && userInfoTokens.length >= 2){
|
||||
username = userInfoTokens[0];
|
||||
password = userInfoTokens[1];
|
||||
for (int i = 2; i < userInfoTokens.length; i++) {
|
||||
password += ":" + userInfoTokens[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fingerprint = uri.getQueryParameter("fingerprint");
|
||||
bssid = uri.getQueryParameter("bssid");
|
||||
ssid = uri.getQueryParameter("ssid");
|
||||
@ -133,6 +147,14 @@ public class NewRepoConfig {
|
||||
return host;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getFingerprint() {
|
||||
return fingerprint;
|
||||
}
|
||||
@ -157,9 +179,11 @@ public class NewRepoConfig {
|
||||
public static String sanitizeRepoUri(Uri uri) {
|
||||
String scheme = uri.getScheme();
|
||||
String host = uri.getHost();
|
||||
String userInfo = uri.getUserInfo();
|
||||
return uri.toString()
|
||||
.replaceAll("\\?.*$", "") // remove the whole query
|
||||
.replaceAll("/*$", "") // remove all trailing slashes
|
||||
.replace(userInfo + "@", "") // remove user authentication
|
||||
.replace(host, host.toLowerCase(Locale.ENGLISH))
|
||||
.replace(scheme, scheme.toLowerCase(Locale.ENGLISH))
|
||||
.replace("fdroidrepo", "http") // proper repo address
|
||||
|
@ -162,6 +162,8 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
|
||||
ClipboardCompat clipboard = ClipboardCompat.create(this);
|
||||
String text = clipboard.getText();
|
||||
String fingerprint = null;
|
||||
String username = null;
|
||||
String password = null;
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
try {
|
||||
new URL(text);
|
||||
@ -171,6 +173,19 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
|
||||
if (TextUtils.isEmpty(fingerprint)) {
|
||||
fingerprint = uri.getQueryParameter("FINGERPRINT");
|
||||
}
|
||||
|
||||
String userInfo = uri.getUserInfo();
|
||||
if (userInfo != null) {
|
||||
String[] userInfoTokens = userInfo.split(":");
|
||||
if (userInfoTokens.length >= 2) {
|
||||
username = userInfoTokens[0];
|
||||
password = userInfoTokens[1];
|
||||
for (int i=2; i<userInfoTokens.length; i++) {
|
||||
password += ":" + userInfoTokens[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
text = NewRepoConfig.sanitizeRepoUri(uri);
|
||||
} catch (MalformedURLException e) {
|
||||
text = null;
|
||||
@ -180,11 +195,11 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
text = DEFAULT_NEW_REPO_TEXT;
|
||||
}
|
||||
showAddRepo(text, fingerprint);
|
||||
showAddRepo(text, fingerprint, username, password);
|
||||
}
|
||||
|
||||
private void showAddRepo(String newAddress, String newFingerprint) {
|
||||
new AddRepo(newAddress, newFingerprint);
|
||||
private void showAddRepo(String newAddress, String newFingerprint, String username, String password) {
|
||||
new AddRepo(newAddress, newFingerprint, username, password);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,10 +221,13 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
|
||||
|
||||
private AddRepoState addRepoState;
|
||||
|
||||
AddRepo(String newAddress, String newFingerprint) {
|
||||
AddRepo(String newAddress, String newFingerprint,final String username, final String password) {
|
||||
|
||||
context = ManageReposActivity.this;
|
||||
|
||||
// TODO uniqx: forward username and password
|
||||
Toast.makeText(context, "username: " + username + ", password: " + password, Toast.LENGTH_LONG).show();
|
||||
|
||||
final View view = getLayoutInflater().inflate(R.layout.addrepo, null);
|
||||
addRepoDialog = new AlertDialog.Builder(context).setView(view).create();
|
||||
final EditText uriEditText = (EditText) view.findViewById(R.id.edit_uri);
|
||||
@ -270,19 +288,21 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
|
||||
|
||||
switch (addRepoState) {
|
||||
case DOESNT_EXIST:
|
||||
prepareToCreateNewRepo(url, fp);
|
||||
prepareToCreateNewRepo(url, fp, username, password);
|
||||
break;
|
||||
|
||||
case IS_SWAP:
|
||||
Utils.debugLog(TAG, "Removing existing swap repo " + url + " before adding new repo.");
|
||||
Repo repo = RepoProvider.Helper.findByAddress(context, url);
|
||||
RepoProvider.Helper.remove(context, repo.getId());
|
||||
prepareToCreateNewRepo(url, fp);
|
||||
prepareToCreateNewRepo(url, fp, username, password);
|
||||
break;
|
||||
|
||||
case EXISTS_DISABLED:
|
||||
case EXISTS_UPGRADABLE_TO_SIGNED:
|
||||
case EXISTS_FINGERPRINT_MATCH:
|
||||
// TODO uniqx:
|
||||
//updateAndEnableExistingRepo(url, fp, username, password);
|
||||
updateAndEnableExistingRepo(url, fp);
|
||||
finishedAddingRepo();
|
||||
break;
|
||||
@ -430,7 +450,7 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
|
||||
/**
|
||||
* Adds a new repo to the database.
|
||||
*/
|
||||
private void prepareToCreateNewRepo(final String originalAddress, final String fingerprint) {
|
||||
private void prepareToCreateNewRepo(final String originalAddress, final String fingerprint, final String username, final String password) {
|
||||
|
||||
addRepoDialog.findViewById(R.id.add_repo_form).setVisibility(View.GONE);
|
||||
addRepoDialog.getButton(AlertDialog.BUTTON_POSITIVE).setVisibility(View.GONE);
|
||||
@ -504,6 +524,13 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
|
||||
final EditText nameInput = (EditText) view.findViewById(R.id.edit_name);
|
||||
final EditText passwordInput = (EditText) view.findViewById(R.id.edit_password);
|
||||
|
||||
if (username != null) {
|
||||
nameInput.setText(username);
|
||||
}
|
||||
if (password != null) {
|
||||
passwordInput.setText(password);
|
||||
}
|
||||
|
||||
credentialsDialog.setTitle(R.string.login_title);
|
||||
credentialsDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
|
||||
getString(R.string.cancel),
|
||||
@ -661,7 +688,7 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
|
||||
NewRepoConfig newRepoConfig = new NewRepoConfig(this, intent);
|
||||
if (newRepoConfig.isValidRepo()) {
|
||||
isImportingRepo = true;
|
||||
showAddRepo(newRepoConfig.getRepoUriString(), newRepoConfig.getFingerprint());
|
||||
showAddRepo(newRepoConfig.getRepoUriString(), newRepoConfig.getFingerprint(), newRepoConfig.getUsername(), newRepoConfig.getPassword());
|
||||
checkIfNewRepoOnSameWifi(newRepoConfig);
|
||||
} else if (newRepoConfig.getErrorMessage() != null) {
|
||||
Toast.makeText(this, newRepoConfig.getErrorMessage(), Toast.LENGTH_LONG).show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user