org.restlet.security.ChallengeAuthenticator Java Examples

The following examples show how to use org.restlet.security.ChallengeAuthenticator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #2
Source File: AbstractRestApplication.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: RestComponent.java    From microservices-comparison with Apache License 2.0 5 votes vote down vote up
private Restlet secure(Application app, Verifier verifier, String realm) {
    ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext().createChildContext(),
            ChallengeScheme.HTTP_OAUTH_BEARER, realm);
    guard.setVerifier(verifier);
    guard.setNext(app);
    return guard;
}
 
Example #4
Source File: PolygeneRestApplication.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@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 );
    }
}
 
Example #5
Source File: Api.java    From vicinity-gateway-api with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a root RESTLET that will receive all incoming calls.
 */
@Override
public synchronized Restlet createInboundRoot() {
	
	
	// create a router Restlet that routes each call to a new instance of 
	Router router = new Router(getContext());

	// define routes
	
	// AUTHENTICATION
	router.attach("/objects/login", ObjectsLogin.class);
	router.attach("/objects/logout", ObjectsLogout.class);
	
	
	// CONSUMPTION
	router.attach("/objects/{oid}/properties", ObjectsOidProperties.class);
	router.attach("/objects/{oid}/properties/{pid}", ObjectsOidPropertiesPid.class);
	router.attach("/objects/{oid}/actions", ObjectsOidActions.class);
	router.attach("/objects/{oid}/actions/{aid}", ObjectsOidActionsAid.class);
	router.attach("/objects/{oid}/actions/{aid}/tasks/{tid}", ObjectsOidActionsAidTasksTid.class);
	
	
	// EXPOSING
	router.attach("/objects/{oid}/events", ObjectsOidEvents.class);
	router.attach("/objects/{oid}/events/{eid}", ObjectsOidEventsEid.class);
	router.attach("/events/{eid}", EventsEid.class);
	
	
	// DISCOVERY
	router.attach("/objects", Objects.class);
	router.attach("/objects/{oid}", ObjectsOid.class);
	//get
	router.attach("/agents/{agid}/objects", AgentsAgidObjects.class);
	
	
	// REGISTRY
	// post, put
	router.attach("/agents/{agid}/objects", AgentsAgidObjects.class);
	// put
	router.attach("/agents/{agid}/objects/update", AgentsAgidObjectsUpdate.class);
	// post
	router.attach("/agents/{agid}/objects/delete", AgentsAgidObjectsDelete.class);
	
	
	// SEARCH
	// sparql query (VCNT)
	router.attach("/search/sparql", SearchSparql.class);
	// semantic query (SHQ)
	router.attach("/search/semantic", SearchSemantic.class);
	
	// solve the question of API authentication
	if (useAuthentication){
		// create authenticator
		ChallengeAuthenticator authenticator = createAuthenticator();
		
		// enable authentication
		authenticator.setNext(router);
		return authenticator;
	} 
	
	return router;
}
 
Example #6
Source File: Activator.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public void start(BundleContext context) throws Exception {
	
	System.err.println("Starting Admin bundle");
	
	context.addServiceListener(new ServiceListener() {
		
		@Override
		public void serviceChanged(ServiceEvent event) {
			System.err.println(event);
			if (event.getType() == ServiceEvent.REGISTERED){
				Application application = new AdminApplication();

				component = new Component();
				component.getServers().add(Protocol.HTTP, 8183);
				component.getClients().add(Protocol.FILE);

				boolean useAuth = Boolean.valueOf(Configuration.getInstance().getProperty("adminapi.use_authentication", "false"));
				
				if (useAuth) {
					String username = Configuration.getInstance().getProperty("adminapi.username", null);
					String password = Configuration.getInstance().getProperty("adminapi.password", null);
					
					ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "myRealm");
					MapVerifier verifier = new MapVerifier();
					verifier.getLocalSecrets().put(username, password.toCharArray());
					guard.setVerifier(verifier);
					guard.setNext(application);
					
					component.getDefaultHost().attachDefault(guard);
				} else {
					component.getDefaultHost().attachDefault(application);
				}
				
				try {
					component.start();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}, "(objectclass=" + ApiStartServiceToken.class.getName() +")");
}
 
Example #7
Source File: Api.java    From vicinity-gateway-api with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Returns an instance of ChallengeAuthenticator, that is able to authenticate requests against the XMPP network.
 * 
 * @return A custom ChallengeAuthenticator.
 */
private ChallengeAuthenticator createAuthenticator() {
	
	String realm = config.getString(CONF_PARAM_AUTHREALM, CONF_DEF_AUTHREALM);
	
	logger.config("Authentication realm: " + realm);
	
	AuthenticationVerifier authVerifier = new AuthenticationVerifier(communicationManager, logger);

	ChallengeAuthenticator auth = new ChallengeAuthenticator(
							applicationContext, false, challengeScheme, realm, authVerifier);
	
	return auth;
   }