public void addGlobalHeaders(HttpURLConnection connection) { try { connection.setRequestProperty( APPLICATION_KEY_HEADER, MobiComKitClientService.getApplicationKey(context)); connection.setRequestProperty(SOURCE_HEADER, SOURCE_HEADER_VALUE); connection.setRequestProperty(USERID_HEADER, USERID_HEADER_VALUE); connection.setRequestProperty( DEVICE_KEY_HEADER, MobiComUserPreference.getInstance(context).getDeviceKeyString()); Short authenticationType = Short.valueOf(MobiComUserPreference.getInstance(context).getAuthenticationType()); if (User.AuthenticationType.APPLOZIC.getValue() == authenticationType) { connection.setRequestProperty( ACCESS_TOKEN, MobiComUserPreference.getInstance(context).getPassword()); } if (MobiComKitClientService.getAppModuleName(context) != null) { connection.setRequestProperty( APP_MODULE_NAME_KEY_HEADER, MobiComKitClientService.getAppModuleName(context)); } MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context); if (userPreferences.isRegistered()) { String userCredentials = getCredentials().getUserName() + ":" + String.valueOf(getCredentials().getPassword()); String basicAuth = "Basic " + Base64.encodeToString(userCredentials.getBytes(), Base64.NO_WRAP); connection.setRequestProperty("Authorization", basicAuth); } } catch (Exception e) { e.printStackTrace(); } }
public PasswordAuthentication getCredentials() { MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context); if (!userPreferences.isRegistered()) { return null; } return new PasswordAuthentication( userPreferences.getUserId(), userPreferences.getDeviceKeyString().toCharArray()); }