from a url.
Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
string rgw::auth::WebIdentityApplier::get_idp_url() const
{
string idp_url = token_claims.iss;
- auto pos = idp_url.find("http://");
- if (pos == std::string::npos) {
- pos = idp_url.find("https://");
- if (pos != std::string::npos) {
- idp_url.erase(pos, 8);
- }
- } else {
- idp_url.erase(pos, 7);
- }
+ idp_url = url_remove_prefix(idp_url);
return idp_url;
}
return dst;
}
+std::string url_remove_prefix(const std::string& url)
+{
+ std::string dst = url;
+ auto pos = dst.find("http://");
+ if (pos == std::string::npos) {
+ pos = dst.find("https://");
+ if (pos != std::string::npos) {
+ dst.erase(pos, 8);
+ } else {
+ pos = dst.find("www.");
+ if (pos != std::string::npos) {
+ dst.erase(pos, 4);
+ }
+ }
+ } else {
+ dst.erase(pos, 7);
+ }
+
+ return dst;
+}
+
string rgw_trim_whitespace(const string& src)
{
if (src.empty()) {
extern void url_encode(const std::string& src, string& dst,
bool encode_slash = true);
extern std::string url_encode(const std::string& src, bool encode_slash = true);
+extern std::string url_remove_prefix(const std::string& url); // Removes hhtp, https and www from url
/* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
extern void calc_hmac_sha1(const char *key, int key_len,
const char *msg, int msg_len, char *dest);
return -EINVAL;
}
- string idp_url = provider_url;
- auto pos = idp_url.find("http://");
- if (pos == std::string::npos) {
- pos = idp_url.find("https://");
- if (pos != std::string::npos) {
- idp_url.erase(pos, 8);
- } else {
- pos = idp_url.find("www.");
- if (pos != std::string::npos) {
- idp_url.erase(pos, 4);
- }
- }
- } else {
- idp_url.erase(pos, 7);
- }
+ string idp_url = url_remove_prefix(provider_url);
/* check to see the name is not used */
ret = read_url(idp_url, tenant);
return ret;
}
- string idp_url = provider_url;
- auto pos = idp_url.find("http://");
- if (pos == std::string::npos) {
- pos = idp_url.find("https://");
- if (pos != std::string::npos) {
- idp_url.erase(pos, 8);
- } else {
- pos = idp_url.find("www.");
- if (pos != std::string::npos) {
- idp_url.erase(pos, 4);
- }
- }
- } else {
- idp_url.erase(pos, 7);
- }
+ string idp_url = url_remove_prefix(provider_url);
if (!verify_user_permission(this,
s,
rgw::ARN(idp_url,