本文整理汇总了Java中org.restlet.data.ChallengeResponse.setRawValue方法的典型用法代码示例。如果您正苦于以下问题:Java ChallengeResponse.setRawValue方法的具体用法?Java ChallengeResponse.setRawValue怎么用?Java ChallengeResponse.setRawValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.data.ChallengeResponse
的用法示例。
在下文中一共展示了ChallengeResponse.setRawValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: list
import org.restlet.data.ChallengeResponse; //导入方法依赖的package包/类
@Override
public List<Car> list() {
Client client = new Client(new Context(), Protocol.HTTPS);
Series<Parameter> parameters = client.getContext().getParameters();
parameters.add("truststorePath", System.getProperty("javax.net.ssl.trustStore"));
ClientResource clientResource = new ClientResource("https://localhost:8043/api/cars/cars");
clientResource.setNext(client);
ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER);
challenge.setRawValue(Request.getCurrent().getAttributes().getOrDefault("token", "").toString());
clientResource.setChallengeResponse(challenge);
CarServiceInterface carServiceInterface = clientResource.wrap(CarServiceInterface.class);
Car[] allCars = carServiceInterface.getAllCars();
try {
client.stop();
} catch (Exception e) {
throw new RuntimeException(e);
}
return asList(allCars);
}
示例2: authenticate
import org.restlet.data.ChallengeResponse; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public int authenticate(Request request) {
String url = getRelativePath(request);
// no filter belongs to url
if (filterChainProxy != null && filterChainProxy.getFilters(url) != null && filterChainProxy.getFilters(url).isEmpty()) {
return Guard.AUTHENTICATION_VALID;
}
int result = Guard.AUTHENTICATION_MISSING;
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (this.getScheme() != null) {
// An authentication scheme has been defined,
// the request must be authenticated
final ChallengeResponse cr = request.getChallengeResponse();
if (cr != null) {
if (this.getScheme().equals(cr.getScheme())) {
if (auth != null) {
if (auth.isAuthenticated()) {
return Guard.AUTHENTICATION_VALID;
}
} else {
throw new IllegalArgumentException("Challenge scheme " + this.getScheme() + " not supported by the Restlet engine.");
}
} else {
// The challenge schemes are incompatible, we need to
// challenge the client
}
} else {
if (auth != null) {
ChallengeResponse challengeResponse = new ChallengeResponse(this.getScheme(), auth.getName(), "");
if (auth.getDetails() instanceof User) {
User user = (User) auth.getDetails();
challengeResponse.setRawValue(user.getPassword());
challengeResponse.setRealm(this.getRealm());
org.restlet.security.User u = new org.restlet.security.User(user.getUsername());
if (user.getPassword() != null)
u.setSecret(user.getPassword().toCharArray());
request.getClientInfo().setUser(u);
}
challengeResponse.setAuthenticated(auth.isAuthenticated());
result = Guard.AUTHENTICATION_VALID;
request.setChallengeResponse(challengeResponse);
}
// No challenge response found, we need to challenge the client
}
}
if (request.getChallengeResponse() != null) {
// Update the challenge response accordingly
request.getChallengeResponse().setAuthenticated(result == Guard.AUTHENTICATION_VALID);
}
// Update the client info accordingly
request.getClientInfo().setAuthenticated(result == Guard.AUTHENTICATION_VALID);
return result;
}