当前位置: 首页>>代码示例>>Java>>正文


Java ChallengeResponse.setRawValue方法代码示例

本文整理汇总了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);
}
 
开发者ID:cdelmas,项目名称:microservices-comparison,代码行数:21,代码来源:RemoteCarService.java

示例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;
}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:59,代码来源:SpringSecurityGuard.java


注:本文中的org.restlet.data.ChallengeResponse.setRawValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。