org.restlet.Request.setChallengeResponse()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.restlet.Request.setChallengeResponse方法的一些代码示例,展示了Request.setChallengeResponse的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.setChallengeResponse方法的具体详情如下:
包路径:org.restlet.Request
类名称:Request
方法名:setChallengeResponse

Request.setChallengeResponse介绍

[英]Sets the authentication response sent by a client to an origin server. Note that when used with HTTP connectors, this property maps to the "Authorization" header.
[中]设置客户端发送到源服务器的身份验证响应。请注意,当与HTTP连接器一起使用时,此属性映射到“授权”头。

代码示例

代码示例来源:origin: org.restlet.osgi/org.restlet

@Override
public void setChallengeResponse(ChallengeResponse response) {
  super.setChallengeResponse(response);
  this.securityAdded = true;
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Sets the authentication response sent by a client to an origin server.
 * 
 * @param response
 *            The authentication response sent by a client to an origin
 *            server.
 */
@Override
public void setChallengeResponse(ChallengeResponse response) {
  getWrappedRequest().setChallengeResponse(response);
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Sets the authentication response sent by a client to an origin server.
 * 
 * @param challengeResponse
 *            The authentication response sent by a client to an origin
 *            server.
 * @see Request#setChallengeResponse(ChallengeResponse)
 */
public void setChallengeResponse(ChallengeResponse challengeResponse) {
  getRequest().setChallengeResponse(challengeResponse);
}

代码示例来源:origin: stackoverflow.com

@Test
public void test() {
  String url ="http://localhost:8190/project/user/status";
  Client client = new Client(Protocol.HTTP);
  ChallengeResponse challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_BASIC,"user", "f399b0a660f684b2c5a6b4c054f22d89");
  Request request = new Request(Method.GET, url);
  request.setChallengeResponse(challengeResponse);
  Response response = client.handle(request);
  System.out.println("request"+response.getStatus().getCode());
  System.out.println("request test::"+response.getEntityAsText());
}

代码示例来源:origin: org.restlet.osgi/org.restlet.ext.platform

@Override
public void handle(Request request, Response response) {
  if (authenticationEnabled) {
    // Do not add Authentication info from redirection request since
    // authentication has already been done.
    request.getHeaders().removeAll("Authorization");
    request.setChallengeResponse(null);
  }
  super.handle(request, response);
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.apispark

@Override
public void handle(Request request, Response response) {
  if (authenticationEnabled) {
    // Do not add Authentication info from redirection request since
    // authentication has already been done.
    request.getHeaders().removeAll("Authorization");
    request.setChallengeResponse(null);
  }
  super.handle(request, response);
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.platform

@Override
public void handle(Request request, Response response) {
  if (authenticationEnabled) {
    // Do not add Authentication info from redirection request since
    // authentication has already been done.
    request.getHeaders().removeAll("Authorization");
    request.setChallengeResponse(null);
  }
  super.handle(request, response);
}

代码示例来源:origin: org.nuxeo/nuxeo-http-client

protected void setupAuth(Request request) {
  if (authType == AUTH_TYPE_BASIC) {
    ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
    ChallengeResponse authentication = new ChallengeResponse(scheme, userName, password);
    request.setChallengeResponse(authentication);
  } else if (authType == AUTH_TYPE_SECRET) {
    Series<Parameter> additionnalHeaders = new Form();
    Map<String, String> securityHeaders = PortalSSOAuthenticationProvider.getHeaders(secretToken, userName);
    for (String hn : securityHeaders.keySet()) {
      additionnalHeaders.add(hn, securityHeaders.get(hn));
    }
    request.getAttributes().put("org.restlet.http.headers", additionnalHeaders);
  }
}

代码示例来源:origin: org.restlet.jse/org.restlet.ext.platform

@Override
public void handle(Request request, Response response) {
  if (authenticationEnabled) {
    // Do not add Authentication info from redirection request since
    // authentication has already been done.
    request.getHeaders().removeAll("Authorization");
    request.setChallengeResponse(null);
  }
  super.handle(request, response);
}

代码示例来源:origin: org.restlet.gae/org.restlet.ext.platform

@Override
public void handle(Request request, Response response) {
  if (authenticationEnabled) {
    // Do not add Authentication info from redirection request since
    // authentication has already been done.
    request.getHeaders().removeAll("Authorization");
    request.setChallengeResponse(null);
  }
  super.handle(request, response);
}

代码示例来源:origin: com.github.ansell.restlet-utils/restlet-utils

/**
 * Processes the logout request.
 * 
 * @param request
 *            The current request.
 * @param response
 *            The current response.
 */
protected int logout(final Request request, final Response response)
{
  // Clears the credentials
  request.setChallengeResponse(null);
  final CookieSetting credentialsCookie = this.getCredentialsCookie(request, response);
  credentialsCookie.setMaxAge(0);
  
  this.log.debug("calling attemptRedirect after logout");
  // Attempt to redirect
  this.attemptRedirect(request, response, null);
  
  return Filter.STOP;
}

代码示例来源:origin: com.github.ansell.restlet-utils/restlet-utils

/**
 * Restores credentials from the cookie named {@link #getCookieName()} if available. The usual
 * processing is the followed.
 */
@Override
protected boolean authenticate(final Request request, final Response response)
{
  // Restore credentials from the cookie
  final Cookie credentialsCookie = request.getCookies().getFirst(this.getCookieName());
  
  if(credentialsCookie != null)
  {
    ChallengeResponse credentials = this.parseCredentials(credentialsCookie.getValue());
    if(credentials == null)
    {
      response.getCookieSettings().removeAll(this.getCookieName());
    }
    else
    {
      request.setChallengeResponse(credentials);
    }
  }
  
  this.log.debug("Calling super.authenticate");
  return super.authenticate(request, response);
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
protected int beforeHandle(Request request, Response response) {
  Cookie cookie = request.getCookies().getFirst("Credentials");
  if (cookie != null) {
    // Extract the challenge response from the cookie
    String[] credentials = cookie.getValue().split("=");
    if (credentials.length == 2) {
      String identifier = credentials[0];
      String secret = credentials[1];
      request.setChallengeResponse(new ChallengeResponse(
          ChallengeScheme.HTTP_COOKIE, identifier, secret));
    }
  } else if (Method.POST.equals(request.getMethod())
      && request.getResourceRef().getQueryAsForm().getFirst("login") != null) {
    // Intercepting a login form
    Form credentials = new Form(request.getEntity());
    String identifier = credentials.getFirstValue("identifier");
    String secret = credentials.getFirstValue("secret");
    request.setChallengeResponse(new ChallengeResponse(
        ChallengeScheme.HTTP_COOKIE, identifier, secret));
    // Continue call processing to return the target representation if
    // authentication is successful or a new login page
    request.setMethod(Method.GET);
  }
  return super.beforeHandle(request, response);
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
protected int beforeHandle(Request request, Response response) {
  Cookie cookie = request.getCookies().getFirst("Credentials");
  if (cookie != null) {
    // Extract the challenge response from the cookie
    String[] credentials = cookie.getValue().split("=");
    if (credentials.length == 2) {
      String identifier = credentials[0];
      String secret = credentials[1];
      request.setChallengeResponse(new ChallengeResponse(
          ChallengeScheme.HTTP_COOKIE, identifier, secret));
    }
  } else if (Method.POST.equals(request.getMethod())
      && request.getResourceRef().getQueryAsForm().getFirst("login") != null) {
    // Intercepting a login form
    Form credentials = new Form(request.getEntity());
    String identifier = credentials.getFirstValue("identifier");
    String secret = credentials.getFirstValue("secret");
    request.setChallengeResponse(new ChallengeResponse(
        ChallengeScheme.HTTP_COOKIE, identifier, secret));
    // Continue call processing to return the target representation if
    // authentication is successful or a new login page
    request.setMethod(Method.GET);
  }
  return super.beforeHandle(request, response);
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

public static void main(String[] args) throws Exception {
  // Prepare the request
  Request request = new Request(Method.GET,
      "http://s3.amazonaws.com/quotes/nelson");
  request.setChallengeResponse(new ChallengeResponse(
      ChallengeScheme.HTTP_AWS_S3, "44CF9590006BF252F707",
      "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV"));
  // Add some extra headers
  Series<Header> extraHeaders = new Series<Header>(Header.class);
  extraHeaders.add("X-Amz-Meta-Author", "foo@bar.com");
  extraHeaders.add("X-Amz-Magic", "abracadabra");
  // For the test we hard coded a special date header. Normally you don't
  // need this as the
  // HTTP client connector will automatically provide an accurate Date
  // header and use it
  // for authentication.
  // extraHeaders.add("X-Amz-Date", "Thu, 17 Nov 2005 18:49:58 GMT");
  request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS,
      extraHeaders);
  // Handle it using an HTTP client connector
  Client client = new Client(Protocol.HTTP);
  Response response = client.handle(request);
  // Write the response entity on the console
  Representation output = response.getEntity();
  output.write(System.out);
}

代码示例来源:origin: com.github.ansell.restlet-utils/restlet-utils

/**
 * Processes the login request.
 * 
 * @param request
 *            The current request.
 * @param response
 *            The current response.
 */
protected void login(final Request request, final Response response)
{
  // Login detected
  final Form form = new Form(request.getEntity());
  final Parameter identifier = form.getFirst(this.getIdentifierFormName());
  final Parameter secret = form.getFirst(this.getSecretFormName());
  
  // Set credentials
  final ChallengeResponse cr =
      new ChallengeResponse(this.getScheme(), identifier != null ? identifier.getValue() : null,
          secret != null ? secret.getValue() : null);
  request.setChallengeResponse(cr);
  
  this.log.info("calling attemptRedirect after login");
  // Attempt to redirect
  this.attemptRedirect(request, response, form);
}

代码示例来源:origin: org.restlet.osgi/org.restlet.ext.oauth

ChallengeScheme.HTTP_OAUTH_BEARER);
cr.setRawValue(token.getAccessToken());
request.setChallengeResponse(cr);

代码示例来源:origin: apache/attic-polygene-java

request.setChallengeResponse( new ChallengeResponse( ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret() ) );

代码示例来源:origin: apache/attic-polygene-java

request.setChallengeResponse( new ChallengeResponse( ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret() ) );

相关文章