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