本文整理匯總了Java中com.nike.riposte.server.http.RequestInfo.getPath方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestInfo.getPath方法的具體用法?Java RequestInfo.getPath怎麽用?Java RequestInfo.getPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.nike.riposte.server.http.RequestInfo
的用法示例。
在下文中一共展示了RequestInfo.getPath方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validateSecureRequestForEndpoint
import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
/**
* Performs security validation on the given request {@link RequestInfo} with possibly multiple validations.
*
* If an endpoint has multiple validators associated with it, it must pass validation with at least one of the
* validators.
*/
@Override
public void validateSecureRequestForEndpoint(RequestInfo<?> requestInfo, Endpoint<?> endpoint) {
List<RequestSecurityValidator> validators = validationMap.get(endpoint);
if (validators == null || validators.isEmpty()) {
// if there are no validators for the endpoint, we don't need to validate
return;
}
StringBuilder errorMessages = new StringBuilder("Request failed all auth validation:");
List<Pair<String, String>> extraDetails = new ArrayList<>();
for (RequestSecurityValidator validator : validators) {
try {
validator.validateSecureRequestForEndpoint(requestInfo, endpoint);
return;
}
catch (Unauthorized401Exception ex) {
// move on to the next validator
errorMessages.append(validator.getClass().getSimpleName()).append(": ").append(ex.getMessage())
.append(";");
extraDetails.addAll(ex.extraDetailsForLogging);
}
}
throw new Unauthorized401Exception(errorMessages.toString(), requestInfo.getPath(), null, extraDetails);
}
示例2: validateSecureRequestForEndpoint
import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Override
public void validateSecureRequestForEndpoint(RequestInfo<?> requestInfo, Endpoint<?> endpoint) {
String authorizationHeader = requestInfo.getHeaders().get("Authorization");
if (authorizationHeader == null) {
throw new Unauthorized401Exception("Missing authorization header.", requestInfo.getPath(), null);
}
final String[] authSplit = authorizationHeader.split(" ");
if (authSplit.length != 2 || !"Basic".equals(authSplit[0])) {
throw new Unauthorized401Exception("Authorization header does not contain Basic", requestInfo.getPath(),
authorizationHeader);
}
Base64.Decoder decoder = Base64.getDecoder();
byte[] decodedBytes;
try {
decodedBytes = decoder.decode(authSplit[1]);
}
catch (IllegalArgumentException ex) {
throw new Unauthorized401Exception(
"Malformed Authorization header (not Base64 encoded), caused by: " + ex.toString(),
requestInfo.getPath(), authorizationHeader);
}
String pair = new String(decodedBytes);
String[] userDetails = pair.split(":", 2);
if (userDetails.length != 2) {
throw new Unauthorized401Exception("Malformed Authorization header.", requestInfo.getPath(),
authorizationHeader);
}
String username = userDetails[0];
String password = userDetails[1];
if (!username.equals(expectedUsername) || !password.equals(expectedPassword)) {
throw new Unauthorized401Exception("Invalid username or password", requestInfo.getPath(),
authorizationHeader);
}
}
示例3: validateSecureRequestForEndpoint
import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Override
public void validateSecureRequestForEndpoint(RequestInfo<?> requestInfo, Endpoint<?> endpoint) {
requestInfo.addRequestAttribute(SECURITY_VALIDATOR_EXECUTED_HEADER_KEY, true);
if ("true".equals(requestInfo.getHeaders().get(FORCE_SECURITY_ERROR_HEADER_KEY))) {
requestInfo.addRequestAttribute(SECURITY_VALIDATOR_THREW_ERROR_HEADER_KEY, true);
throw new Unauthorized401Exception("Forcing Security Error.", requestInfo.getPath(), null);
}
else
requestInfo.addRequestAttribute(SECURITY_VALIDATOR_THREW_ERROR_HEADER_KEY, false);
}
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:12,代碼來源:VerifyBeforeAndAfterSecurityRequestAndResponseFiltersComponentTest.java
示例4: RequestContentDeserializationException
import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
public RequestContentDeserializationException(String exceptionMessage, Throwable cause, RequestInfo<?> requestInfo,
TypeReference<?> desiredObjectType) {
super(exceptionMessage, cause);
this.httpMethod = String.valueOf(requestInfo.getMethod());
this.requestPath = requestInfo.getPath();
this.desiredObjectType = desiredObjectType;
}
示例5: matchesPath
import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
/**
* @return Returns the first pattern found in the collection that matches the given request if one exists. Order of
* paths can be significant so when creating a MultiMatcher use an ordered collection if some path may match
* multiple patterns.
*/
@Override
public Optional<String> matchesPath(RequestInfo<?> request) {
if (request == null || request.getPath() == null)
return Optional.empty();
// Ignore trailing slashes on the actual path.
String path = MatcherUtil.stripEndSlash(request.getPath());
return matchingPathTemplates
.stream()
// Ignore trailing slashes on the template.
.filter(pathTemplate -> pathParamExtractor.match(pathTemplate, path))
.findFirst();
}
示例6: matchesPath
import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
public Optional<String> matchesPath(RequestInfo<?> request) {
if (request == null || request.getPath() == null)
return Optional.empty();
// Ignore trailing slashes on actual path.
String path = MatcherUtil.stripEndSlash(request.getPath());
if (pathParamExtractor.match(matchingPathTemplate, path)) {
return cachedMatchesPathResponse;
}
else {
return Optional.empty();
}
}
示例7: findSingleEndpointForExecution
import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
/**
* @return The single {@link Endpoint} that matches and wants to handle the given request (and the path pattern that
* the endpoint used when deciding it wanted to handle the request). This will throw a {@link
* PathNotFound404Exception} if there are no matching endpoints. It will throw a {@link
* MethodNotAllowed405Exception} if there's an endpoint that matches the path but not the HTTP method of the
* request, and this will throw a {@link MultipleMatchingEndpointsException} if there are multiple endpoints that
* fully match the path and HTTP method.
*/
@SuppressWarnings("WeakerAccess")
protected Pair<Endpoint<?>, String> findSingleEndpointForExecution(RequestInfo requestInfo) {
boolean hasPathMatch = false;
List<Endpoint<?>> fullyMatchingEndpoints = new ArrayList<>(1);
String matchingPattern = "";
for (Endpoint<?> endpoint : endpoints) {
Optional<String> pattern = endpoint.requestMatcher().matchesPath(requestInfo);
if (pattern.isPresent()) {
hasPathMatch = true;
if (endpoint.requestMatcher().matchesMethod(requestInfo)) {
fullyMatchingEndpoints.add(endpoint);
matchingPattern = pattern.get();
}
}
}
// If there's no endpoint that even matches the path then this is a 404 situation.
if (!hasPathMatch) {
throw new PathNotFound404Exception(
"No matching endpoint found. requested_uri_path=" + requestInfo.getPath() + ", requested_method="
+ requestInfo.getMethod());
}
// We have at least one path match. fullyMatchingEndpoints will now tell us how many matched both path
// *and* HTTP method.
// Do error checking.
if (fullyMatchingEndpoints.isEmpty()) {
// Not a 404 because we did have at least one endpoint that matched the path, but none matched both path and
// HTTP method so we throw a 405.
throw new MethodNotAllowed405Exception(
"Found path match for incoming request, but no endpoint matched both path and HTTP method",
requestInfo.getPath(), String.valueOf(requestInfo.getMethod()));
}
if (fullyMatchingEndpoints.size() > 1) {
// More than 1 endpoint matched. Also not ok.
throw new MultipleMatchingEndpointsException(
"Found multiple endpoints that matched the incoming request's path and HTTP method. This is not "
+ "allowed - your endpoints must be structured so that only one endpoint can match any given request",
fullyMatchingEndpoints, requestInfo.getPath(), String.valueOf(requestInfo.getMethod())
);
}
// At this point we know there's exactly 1 fully matching endpoint, so go ahead and return it.
return Pair.of(fullyMatchingEndpoints.get(0), matchingPattern);
}