Search in sources :

Example 6 with Restlet

use of org.restlet.Restlet in project pinot by linkedin.

the class SwaggerResource method get.

@Get
@Override
public Representation get() {
    try {
        // Info
        JSONObject info = new JSONObject();
        info.put("title", "Pinot Controller");
        info.put("version", "0.1");
        // Paths
        JSONObject paths = new JSONObject();
        Router router = PinotRestletApplication.getRouter();
        RouteList routeList = router.getRoutes();
        for (Route route : routeList) {
            if (route instanceof TemplateRoute) {
                TemplateRoute templateRoute = (TemplateRoute) route;
                JSONObject pathObject = new JSONObject();
                String routePath = templateRoute.getTemplate().getPattern();
                // Check which methods are present
                Restlet routeTarget = templateRoute.getNext();
                if (routeTarget instanceof Finder) {
                    Finder finder = (Finder) routeTarget;
                    generateSwaggerForFinder(pathObject, routePath, finder);
                } else if (routeTarget instanceof Filter) {
                    do {
                        Filter filter = (Filter) routeTarget;
                        routeTarget = filter.getNext();
                    } while (routeTarget instanceof Filter);
                    if (routeTarget instanceof Finder) {
                        Finder finder = (Finder) routeTarget;
                        generateSwaggerForFinder(pathObject, routePath, finder);
                    }
                }
                if (pathObject.keys().hasNext()) {
                    paths.put(routePath, pathObject);
                }
            }
        }
        // Tags
        JSONArray tags = new JSONArray();
        addTag(tags, "tenant", "Tenant-related operations");
        addTag(tags, "instance", "Instance-related operations");
        addTag(tags, "table", "Table-related operations");
        addTag(tags, "segment", "Segment-related operations");
        addTag(tags, "schema", "Schema-related operations");
        addTag(tags, "version", "Version-related operations");
        // Swagger
        JSONObject swagger = new JSONObject();
        swagger.put("swagger", "2.0");
        swagger.put("info", info);
        swagger.put("paths", paths);
        swagger.put("tags", tags);
        StringRepresentation representation = new StringRepresentation(swagger.toString());
        // Set up CORS
        Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
        if (responseHeaders == null) {
            responseHeaders = new Series(Header.class);
            getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
        }
        responseHeaders.add(new Header("Access-Control-Allow-Origin", "*"));
        return representation;
    } catch (JSONException e) {
        return new StringRepresentation(e.toString());
    }
}
Also used : Restlet(org.restlet.Restlet) TemplateRoute(org.restlet.routing.TemplateRoute) Finder(org.restlet.resource.Finder) JSONArray(org.json.JSONArray) Router(org.restlet.routing.Router) JSONException(org.json.JSONException) RouteList(org.restlet.util.RouteList) Series(org.restlet.util.Series) JSONObject(org.json.JSONObject) Header(org.restlet.engine.header.Header) Filter(org.restlet.routing.Filter) StringRepresentation(org.restlet.representation.StringRepresentation) Route(org.restlet.routing.Route) TemplateRoute(org.restlet.routing.TemplateRoute) Get(org.restlet.resource.Get)

Example 7 with Restlet

use of org.restlet.Restlet in project OpenAM by OpenRock.

the class OAuth2RouterProvider method get.

@Override
public Router get() {
    final Router router = new RestletRealmRouter(realmValidator, coreWrapper);
    // Standard OAuth2 endpoints
    router.attach("/authorize", auditWithOAuthFilter(new AuthorizeEndpointFilter(wrap(AuthorizeResource.class), jacksonRepresentationFactory)));
    router.attach("/access_token", auditWithOAuthFilter(new TokenEndpointFilter(new AccessTokenFlowFinder(), jacksonRepresentationFactory), formAuditor(RESPONSE_TYPE, GRANT_TYPE, CLIENT_ID, USERNAME, SCOPE, REDIRECT_URI), jacksonAuditor(SCOPE, TOKEN_TYPE)));
    router.attach("/tokeninfo", auditWithOAuthFilter(wrap(ValidationServerResource.class), noBodyAuditor(), jacksonAuditor(SCOPE, TOKEN_TYPE)));
    // OAuth 2.0 Token Introspection Endpoint
    router.attach("/introspect", auditWithOAuthFilter(wrap(TokenIntrospectionResource.class), formAuditor(TOKEN_TYPE_HINT), jsonAuditor(SCOPE, TOKEN_TYPE, CLIENT_ID, USERNAME, ACTIVE)));
    // OpenID Connect endpoints
    router.attach("/connect/register", auditWithOAuthFilter(wrap(ConnectClientRegistration.class), jsonAuditor(CLIENT_NAME.getType(), APPLICATION_TYPE.getType(), REDIRECT_URIS.getType()), jacksonAuditor(CLIENT_ID, CLIENT_NAME.getType(), APPLICATION_TYPE.getType(), REDIRECT_URIS.getType())));
    router.attach("/userinfo", auditWithOAuthFilter(wrap(UserInfo.class)));
    router.attach("/connect/endSession", auditWithOAuthFilter(wrap(EndSession.class)));
    router.attach("/connect/jwk_uri", auditWithOAuthFilter(wrap(OpenIDConnectJWKEndpoint.class)));
    // Resource Set Registration
    Restlet resourceSetRegistrationEndpoint = auditWithOAuthFilter(getRestlet(OAuth2Constants.Custom.RSR_ENDPOINT), jsonAuditor(NAME, SCOPES), jacksonAuditor("_id"));
    router.attach("/resource_set/{rsid}", resourceSetRegistrationEndpoint);
    router.attach("/resource_set", resourceSetRegistrationEndpoint);
    router.attach("/resource_set/", resourceSetRegistrationEndpoint);
    // OpenID Connect Discovery
    router.attach("/.well-known/openid-configuration", auditWithOAuthFilter(wrap(OpenIDConnectConfiguration.class)));
    // OAuth 2 Device Flow
    router.attach("/device/user", auditWithOAuthFilter(wrap(DeviceCodeVerificationResource.class)));
    router.attach("/device/code", auditWithOAuthFilter(wrap(DeviceCodeResource.class), formAuditor(RESPONSE_TYPE, GRANT_TYPE, CLIENT_ID, SCOPE), noBodyAuditor()));
    return router;
}
Also used : RestletRealmRouter(org.forgerock.openam.rest.service.RestletRealmRouter) Restlet(org.restlet.Restlet) AuthorizeResource(org.forgerock.oauth2.restlet.AuthorizeResource) AuthorizeEndpointFilter(org.forgerock.oauth2.restlet.AuthorizeEndpointFilter) RestletRealmRouter(org.forgerock.openam.rest.service.RestletRealmRouter) Router(org.restlet.routing.Router) TokenEndpointFilter(org.forgerock.oauth2.restlet.TokenEndpointFilter) AccessTokenFlowFinder(org.forgerock.oauth2.restlet.AccessTokenFlowFinder)

Example 8 with Restlet

use of org.restlet.Restlet in project OpenAM by OpenRock.

the class ServiceEndpointApplication method createInboundRoot.

/**
     * Creates an inbound Restlet root for all registered REST Service endpoints.
     *
     * @return A Restlet for routing incoming REST Service endpoint requests.
     */
@Override
public Restlet createInboundRoot() {
    Restlet router = getRouter();
    router.setContext(getContext());
    return router;
}
Also used : Restlet(org.restlet.Restlet)

Example 9 with Restlet

use of org.restlet.Restlet in project OpenAM by OpenRock.

the class AbstractRestletAccessAuditFilterTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    restlet = mock(Restlet.class);
    AMAuditServiceConfiguration serviceConfig = new AMAuditServiceConfiguration(true);
    AuditServiceBuilder builder = AuditServiceBuilder.newAuditService().withConfiguration(serviceConfig);
    AMAuditService auditService = new DefaultAuditServiceProxy(builder.build(), serviceConfig);
    auditService.startup();
    auditServiceProvider = mock(AuditServiceProvider.class);
    when(auditServiceProvider.getDefaultAuditService()).thenReturn(auditService);
    eventFactory = new AuditEventFactory();
    eventPublisher = mock(AuditEventPublisher.class);
    auditFilter = new RestletAccessAuditFilterTest(restlet, eventPublisher, eventFactory, null, null);
}
Also used : AuditServiceBuilder(org.forgerock.audit.AuditServiceBuilder) DefaultAuditServiceProxy(org.forgerock.openam.audit.DefaultAuditServiceProxy) AuditServiceProvider(org.forgerock.openam.audit.AuditServiceProvider) Restlet(org.restlet.Restlet) AMAuditService(org.forgerock.openam.audit.AMAuditService) AuditEventFactory(org.forgerock.openam.audit.AuditEventFactory) AMAuditServiceConfiguration(org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration) AuditEventPublisher(org.forgerock.openam.audit.AuditEventPublisher) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Restlet (org.restlet.Restlet)9 Request (org.restlet.Request)3 Response (org.restlet.Response)3 SSOToken (com.iplanet.sso.SSOToken)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpRequest (org.restlet.engine.adapter.HttpRequest)2 Router (org.restlet.routing.Router)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Test (org.testng.annotations.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Exchange (org.apache.camel.Exchange)1 AuditServiceBuilder (org.forgerock.audit.AuditServiceBuilder)1 AccessTokenFlowFinder (org.forgerock.oauth2.restlet.AccessTokenFlowFinder)1 AuthorizeEndpointFilter (org.forgerock.oauth2.restlet.AuthorizeEndpointFilter)1 AuthorizeResource (org.forgerock.oauth2.restlet.AuthorizeResource)1 TokenEndpointFilter (org.forgerock.oauth2.restlet.TokenEndpointFilter)1 AMAuditService (org.forgerock.openam.audit.AMAuditService)1 AuditEventFactory (org.forgerock.openam.audit.AuditEventFactory)1 AuditEventPublisher (org.forgerock.openam.audit.AuditEventPublisher)1 AuditServiceProvider (org.forgerock.openam.audit.AuditServiceProvider)1