Skip to content

Commit

Permalink
add url matcher to authorizationValue
Browse files Browse the repository at this point in the history
  • Loading branch information
gracekarina authored and frantuma committed Aug 6, 2021
1 parent 655a454 commit 43a5581
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package io.swagger.models.auth;

import java.net.URL;
import java.util.Objects;

public class AuthorizationValue {
private String value, type, keyName;
private UrlMatcher urlMatcher;

public AuthorizationValue() {
}

public AuthorizationValue(String keyName, String value, String type) {
public AuthorizationValue(String keyName, String value, String type, UrlMatcher urlMatcher) {
this.setKeyName(keyName);
this.setValue(value);
this.setType(type);
this.setUrlMatcher(urlMatcher);
}

public AuthorizationValue(String keyName, String value, String type) {
this(keyName, value, type, new UrlMatcher() {
@Override
public boolean test(URL url) {
return true;
}
});
}

public AuthorizationValue value(String value) {
Expand All @@ -27,6 +41,11 @@ public AuthorizationValue keyName(String keyName) {
return this;
}

public AuthorizationValue urlMatcher(UrlMatcher urlMatcher) {
setUrlMatcher(urlMatcher);
return this;
}

public String getValue() {
return value;
}
Expand All @@ -51,13 +70,21 @@ public void setKeyName(String keyName) {
this.keyName = keyName;
}

public UrlMatcher getUrlMatcher() {
return urlMatcher;
}
public void setUrlMatcher(UrlMatcher urlMatcher) {
this.urlMatcher = Objects.requireNonNull(urlMatcher);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((keyName == null) ? 0 : keyName.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
result = prime * result + ((urlMatcher == null) ? 0 : urlMatcher.hashCode());
return result;
}

Expand Down Expand Up @@ -94,6 +121,15 @@ public boolean equals(Object obj) {
} else if (!value.equals(other.value)) {
return false;
}
if (urlMatcher == null) {
if (other.urlMatcher != null) {
return false;
}
} else if (!urlMatcher.equals(other.urlMatcher)) {
if (!urlMatcher.equals(other.urlMatcher)) {
return false;
}
}
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.swagger.models.auth;

import java.net.URL;

public interface UrlMatcher {
boolean test(URL url);
}

0 comments on commit 43a5581

Please sign in to comment.