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


Java ChallengeScheme类代码示例

本文整理汇总了Java中org.restlet.data.ChallengeScheme的典型用法代码示例。如果您正苦于以下问题:Java ChallengeScheme类的具体用法?Java ChallengeScheme怎么用?Java ChallengeScheme使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChallengeScheme类属于org.restlet.data包,在下文中一共展示了ChallengeScheme类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: administration

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
@SubResource
public void administration()
{
    ChallengeResponse challenge = Request.getCurrent().getChallengeResponse();
    if( challenge == null )
    {
        Response.getCurrent()
            .setChallengeRequests( Collections.singletonList( new ChallengeRequest( ChallengeScheme.HTTP_BASIC, "Forum" ) ) );
        throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
    }

    User user = select( Users.class, Users.USERS_ID ).userNamed( challenge.getIdentifier() );
    if( user == null || !user.isCorrectPassword( new String( challenge.getSecret() ) ) )
    {
        throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
    }

    current().select( user );

    subResource( AdministrationResource.class );
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:22,代码来源:RootResource.java

示例2: main

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
public static void main( String[] args )
    throws Exception
{
    Energy4Java polygene = new Energy4Java(  );

    Server server = new Server( Protocol.HTTP, 8888 );

    Application app = polygene.newApplication( new ForumAssembler(), new MetadataService() );

    app.activate();

    ContextRestlet restlet = app.findModule( "REST", "Restlet" ).newObject( ContextRestlet.class, new org.restlet.Context() );

    ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm");
    MapVerifier mapVerifier = new MapVerifier();
    mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray());
    guard.setVerifier(mapVerifier);

    guard.setNext(restlet);

    server.setNext( restlet );
    server.start();
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:24,代码来源:Main.java

示例3: list

import org.restlet.data.ChallengeScheme; //导入依赖的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

示例4: initializeAuthentication

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
public void initializeAuthentication() {
	if(verifier == null){
		verifier = new DefaultSecretVerifier();
	}
	authenticator = new ChallengeAuthenticator(null, false, ChallengeScheme.HTTP_BASIC, "Foxbpm Realm") {
		protected boolean authenticate(Request request, Response response) {
			if (restAuthenticator != null && !restAuthenticator.requestRequiresAuthentication(request)) {
				return true;
			}
			if (request.getChallengeResponse() == null) {
				response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
				return false;
			} else {
				boolean authenticated = super.authenticate(request, response);
				if (authenticated && restAuthenticator != null) {
					authenticated = restAuthenticator.isRequestAuthorized(request);
				}
				return authenticated;
			}
		}
	};
	authenticator.setVerifier(verifier);
}
 
开发者ID:FoxBPM,项目名称:FoxBPM,代码行数:24,代码来源:AbstractRestApplication.java

示例5: main

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	ClientResource client = new ClientResource("http://localhost:8889/foxbpm-webapps-base/service/identity/allUsers");
	client.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "111", "111");
	Representation result = client.get();
	try {
		BufferedReader br = new BufferedReader(result.getReader());
		String line = null;
		while ((line = br.readLine()) != null) {
			System.out.println(line);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	
}
 
开发者ID:FoxBPM,项目名称:FoxBPM,代码行数:19,代码来源:TestGetAllUsers.java

示例6: postMethodRWS

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
static Response postMethodRWS(ConnectionProperties cp, String uriReference, Representation form) throws RancidApiException {
    
    client.setConnectTimeout(cp.getTimeout());
    client.setProtocols(cp.getProtocols());;

    Request request = new Request(Method.POST, uriReference, form);
    
    if(cp.getAuthOn()){
        
        ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
        ChallengeResponse authentication = new ChallengeResponse(scheme,cp.getUserName(), cp.getPassword());
        

        request.setChallengeResponse(authentication);
    }
    else {
        
    }
    Response response = client.handle(request); 
    if (response.getStatus().isSuccess()) {
        return response;
    } else {
    	throw(handleException(response, "POST" ,uriReference));
    }
    
}
 
开发者ID:OpenNMS,项目名称:rancid-api,代码行数:27,代码来源:RWSClientApi.java

示例7: OAuthEndpoint

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
public OAuthEndpoint(final AbstractOAuthApplication application) {

        getDefaultHost().attachDefault(application);

        getClients().add(Protocol.FILE);
        getClients().add(Protocol.HTTP);
        getClients().add(Protocol.HTTPS);
        // Prevent warnings about unsupported authentication
        Engine.getInstance().getRegisteredAuthenticators()
                .add(new AuthenticatorHelper(ChallengeScheme.HTTP_OAUTH_BEARER, true, false) {
                });
    }
 
开发者ID:blackducksoftware,项目名称:hub-email-extension,代码行数:13,代码来源:OAuthEndpoint.java

示例8: invokeQuery

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
private HandlerCommand invokeQuery( Reference ref, Object queryRequest, ResponseHandler resourceHandler, ResponseHandler processingErrorHandler )
{
    Request request = new Request( Method.GET, ref );

    if( queryRequest != null )
    {
        contextResourceFactory.writeRequest( request, queryRequest );
    }

    contextResourceFactory.updateQueryRequest( request );

    User user = request.getClientInfo().getUser();
    if ( user != null)
        request.setChallengeResponse( new ChallengeResponse( ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret() ) );

    Response response = new Response( request );

    contextResourceFactory.getClient().handle( request, response );

    if( response.getStatus().isSuccess() )
    {
        contextResourceFactory.updateCache( response );

        return resourceHandler.handleResponse( response, this );
    } else if (response.getStatus().isRedirection())
    {
        Reference redirectedTo = response.getLocationRef();
        return invokeQuery( redirectedTo, queryRequest, resourceHandler, processingErrorHandler );
    } else
    {
        if (response.getStatus().equals(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY) && processingErrorHandler != null)
        {
            return processingErrorHandler.handleResponse( response, this );
        } else
        {
            // TODO This needs to be expanded to allow custom handling of all the various cases
            return errorHandler.handleResponse( response, this );
        }
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:41,代码来源:ContextResourceClient.java

示例9: createInboundRoot

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
@Override
public Restlet createInboundRoot()
{
    Context context = getContext();
    Engine.getInstance().getRegisteredConverters().add( new PolygeneConverter( objectFactory ) );

    if( polygeneApplication.mode() == Application.Mode.development )
    {
        setDebugging( true );
    }
    router = new Router( context );

    addRoutes( router );
    router.attach( basePath, newPolygeneRestlet( EntryPointResource.class, EntryPoint.class ) );

    Verifier verifier = createVerifier();
    Enroler enroler = createEnroler();
    if( verifier == null && enroler == null )
    {
        return createInterceptors(new Filter()
            {
            } );
    }
    else
    {
        ChallengeAuthenticator guard = new ChallengeAuthenticator( context, ChallengeScheme.HTTP_BASIC, getName() + " Realm" );

        if( verifier != null )
        {
            guard.setVerifier( verifier );
        }

        if( enroler != null )
        {
            guard.setEnroler( enroler );
        }
        return createInterceptors( guard );
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:40,代码来源:PolygeneRestApplication.java

示例10: main

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    ClientResource resource = new ClientResource(REST_URI);

    // 设置Base Auth认证
    resource.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "kermit", "kermit");

    Representation representation = resource.get();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(representation.getStream());
    Iterator<String> fieldNames = jsonNode.fieldNames();
    while (fieldNames.hasNext()) {
        String fieldName = fieldNames.next();
        System.out.println(fieldName + " : " + jsonNode.get(fieldName));
    }
}
 
开发者ID:shawn-gogh,项目名称:myjavacode,代码行数:16,代码来源:RestRequestByRestlet.java

示例11: getAdminGuard

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
private ChallengeAuthenticator getAdminGuard() {
        // Create a simple password verifier
//        MapVerifier verifier = new MapVerifier();
//        verifier.getLocalSecrets().put("mitko", "qwepoi".toCharArray());

        // Create a guard
        ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(),
                ChallengeScheme.HTTP_BASIC, "FP Admin");
        guard.setVerifier(new AdminVerifier());
        return guard;
    }
 
开发者ID:edabg,项目名称:fpgate,代码行数:12,代码来源:FPServer.java

示例12: getUserGuard

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
private ChallengeAuthenticator getUserGuard() {
    // Create a guard
    ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(),
            ChallengeScheme.HTTP_BASIC, "FP User");
    guard.setVerifier(new UserVerifier());
    guard.setOptional(getAppProperties().getProperty("DisableAnonymous", "1").equals("1")?false:true);
    return guard;
}
 
开发者ID:edabg,项目名称:fpgate,代码行数:9,代码来源:FPServer.java

示例13: createAuthenticator

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
private ChallengeAuthenticator createAuthenticator() {
    ChallengeAuthenticator auth= new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "mcrest");
    MapVerifier mapVerifier = new MapVerifier();
    mapVerifier.getLocalSecrets().put(authpara.getUserId(), authpara.getPassword().toCharArray());
    auth.setVerifier(mapVerifier);
    return auth;
}
 
开发者ID:eternnoir,项目名称:MCRest,代码行数:8,代码来源:RestApplication.java

示例14: getRequestResultWithAuth

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
private Response getRequestResultWithAuth(String path,String user,String password){
    Request request = new Request(Method.GET, serverUrl+path);
    Client client = new Client(Protocol.HTTP);

    ChallengeResponse authentication = new ChallengeResponse(
            ChallengeScheme.HTTP_BASIC, user, password);
    request.setChallengeResponse(authentication);

    Response response = client.handle(request);
    return response;
}
 
开发者ID:eternnoir,项目名称:MCRest,代码行数:12,代码来源:AuthResourceTest.java

示例15: verify

import org.restlet.data.ChallengeScheme; //导入依赖的package包/类
@Override
public int verify(Request request, Response response) {
    final String token;

    try {
        ChallengeResponse cr = request.getChallengeResponse();
        if (cr == null) {
            return RESULT_MISSING;
        } else if (ChallengeScheme.HTTP_OAUTH_BEARER.equals(cr.getScheme())) {
            final String bearer = cr.getRawValue();
            if (bearer == null || bearer.isEmpty()) {
                return RESULT_MISSING;
            }
            token = bearer;
        } else {
            return RESULT_UNSUPPORTED;
        }
    } catch (Exception ex) {
        return RESULT_INVALID;
    }

    Try<User> user = accessTokenVerificationCommandFactory.createVerificationCommand(token).executeCommand();
    return user.map(u -> {
        org.restlet.security.User restletUser = createRestletUser(u);
        request.getClientInfo().setUser(restletUser);
        request.getAttributes().put("token", token);
        return RESULT_VALID;
    }).orElse(RESULT_INVALID);
}
 
开发者ID:cdelmas,项目名称:microservices-comparison,代码行数:30,代码来源:AuthTokenVerifier.java


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