Skip to content

Commit

Permalink
Merge pull request ACRA#104 from paolocasarini/basicauth-patch
Browse files Browse the repository at this point in the history
Added setBasicAuth method to override global credential
  • Loading branch information
KevinGaudin committed Jul 21, 2013
2 parents 9c64057 + feafab7 commit a1e32f3
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/main/java/org/acra/sender/HttpSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public String getContentType() {
private final Map<ReportField, String> mMapping;
private final Method mMethod;
private final Type mType;
private String mUsername;
private String mPassword;

/**
* <p>
Expand Down Expand Up @@ -143,6 +145,8 @@ public HttpSender(Method method, Type type, Map<ReportField, String> mapping) {
mFormUri = null;
mMapping = mapping;
mType = type;
mUsername = null;
mPassword = null;
}

/**
Expand Down Expand Up @@ -175,7 +179,25 @@ public HttpSender(Method method, Type type, String formUri, Map<ReportField, Str
mFormUri = Uri.parse(formUri);
mMapping = mapping;
mType = type;
mUsername = null;
mPassword = null;
}

/**
* <p>
* Set credentials for this HttpSender that override (if present) the ones
* set globally.
* </p>
*
* @param username
* The username to set for HTTP Basic Auth.
* @param password
* The password to set for HTTP Basic Auth.
*/
public void setBasicAuth(String username, String password) {
mUsername = username;
mPassword = password;
}

@Override
public void send(CrashReportData report) throws ReportSenderException {
Expand All @@ -184,9 +206,9 @@ public void send(CrashReportData report) throws ReportSenderException {
URL reportUrl = mFormUri == null ? new URL(ACRA.getConfig().formUri()) : new URL(mFormUri.toString());
Log.d(LOG_TAG, "Connect to " + reportUrl.toString());

final String login = ACRAConfiguration.isNull(ACRA.getConfig().formUriBasicAuthLogin()) ? null : ACRA
final String login = mUsername != null ? mUsername : ACRAConfiguration.isNull(ACRA.getConfig().formUriBasicAuthLogin()) ? null : ACRA
.getConfig().formUriBasicAuthLogin();
final String password = ACRAConfiguration.isNull(ACRA.getConfig().formUriBasicAuthPassword()) ? null : ACRA
final String password = mPassword != null ? mPassword : ACRAConfiguration.isNull(ACRA.getConfig().formUriBasicAuthPassword()) ? null : ACRA
.getConfig().formUriBasicAuthPassword();

final HttpRequest request = new HttpRequest();
Expand Down

0 comments on commit a1e32f3

Please sign in to comment.