@Override public void sourceSection(SectionDesigner designer, SectionSourceContext context) throws Exception { SectionFunctionNamespace namespace = designer.addSectionFunctionNamespace("secure", new HttpFlowSecurerManagedFunctionSource(this.annotation)); SectionFunction function = namespace.addSectionFunction("secure", HttpFlowSecurerManagedFunctionSource.FUNCTION_NAME); designer.link(designer.addSectionInput(INPUT_NAME, null), function); designer.link(function.getFunctionFlow(Flows.SECURE.name()), designer.addSectionOutput(SECURE_OUTPUT_NAME, null, false), false); designer.link(function.getFunctionFlow(Flows.INSECURE.name()), designer.addSectionOutput(INSECURE_OUTPUT_NAME, null, false), false); } }
/** * Adds handling for a {@link Servlet} resource. * * @param inputName * {@link SectionInput} name. * @param requestDispatcherPath * {@link RequestDispatcher} path. * @param servletBridge * {@link ServletBridge} {@link SectionObject}. * @param designer * {@link SectionDesigner}. */ private void addServletResource(String inputName, String requestDispatcherPath, SectionObject servletBridge, SectionDesigner designer) { // Create the task to indicate Servlet container resource SectionWork work = designer.addSectionWork(inputName, ServletContainerResourceWorkSource.class.getName()); work.addProperty( ServletContainerResourceWorkSource.PROPERTY_SERVLET_CONTAINER_RESOURCE, requestDispatcherPath); SectionTask task = work.addSectionTask(inputName, "RESOURCE"); TaskObject dependency = task .getTaskObject(DependencyKeys.SERVLET_BRIDGE.name()); designer.link(dependency, servletBridge); // Link input for task SectionInput input = designer.addSectionInput(inputName, null); designer.link(input, task); }
/** * Links an escalation to an {@link SectionOutput}. * * @param task * {@link SectionTask}. * @param exception * Type of escalation. * @param designer * {@link SectionDesigner}. * @param escalations * Registry of the {@link SectionOutput} by type of escalation. */ static <E extends Throwable> void linkEscalation(SectionTask task, Class<E> exception, SectionDesigner designer, Map<Class<?>, SectionOutput> escalations) { // Obtain the section output SectionOutput output = escalations.get(exception); if (output == null) { output = designer.addSectionOutput(exception.getName(), exception.getName(), true); escalations.put(exception, output); } // Link task escalation to output TaskFlow escalation = task.getTaskEscalation(exception.getName()); designer.link(escalation, output, FlowInstigationStrategyEnum.SEQUENTIAL); }
SectionObject connection = designer.addSectionObject( ServerGwtRpcConnection.class.getName(), ServerGwtRpcConnection.class.getName()); SectionObject cometService = designer.addSectionObject( CometService.class.getName(), CometService.class.getName()); SectionObject cometRequestServicer = designer.addSectionObject( CometRequestServicer.class.getName(), CometRequestServicer.class.getName()); SectionWork subscribeWork = designer.addSectionWork("SUBSCRIBE", ClassWorkSource.class.getName()); subscribeWork.addProperty(ClassWorkSource.CLASS_NAME_PROPERTY_NAME, SubscribeWork.class.getName()); SectionTask preSubscription = subscribeWork.addSectionTask( "PRE_SUBSCRIBE", "preSubscribe"); designer.link(preSubscription.getTaskObject(CometRequestServicer.class .getName()), cometRequestServicer); SectionTask postSubscription = subscribeWork.addSectionTask( "POST_SUBSCRIBE", "postSubscribe"); designer.link(postSubscription.getTaskObject(CometRequestServicer.class .getName()), cometRequestServicer); designer.link(preSubscription, postSubscription); designer.link(designer.addSectionInput(SUBSCRIBE_INPUT_NAME, null), preSubscription); SectionWork publishWork = designer.addSectionWork("PUBLISH_WORK",
SectionInput handle = designer.addSectionInput(HANDLE_INPUT, AuthenticationRequiredException.class.getName()); SectionObject serverHttpConnection = designer.addSectionObject(ServerHttpConnection.class.getSimpleName(), ServerHttpConnection.class.getName()); SectionObject httpSession = designer.addSectionObject(HttpSession.class.getSimpleName(), HttpSession.class.getName()); SectionObject requestState = designer.addSectionObject(HttpRequestState.class.getSimpleName(), HttpRequestState.class.getName()); SectionObject httpChallengeContext = designer.addSectionObject(HttpChallengeContext.class.getSimpleName(), HttpChallengeContext.class.getName()); SectionFunctionNamespace namespace = designer.addSectionFunctionNamespace("handle", new HandleAuthenticationRequiredManagedFunctionSource()); SectionFunction handler = namespace.addSectionFunction("handler", "handler"); handler.getFunctionObject(Dependencies.AUTHENTICATION_REQUIRED_EXCEPTION.name()).flagAsParameter(); designer.link(handler.getFunctionObject(Dependencies.SERVER_HTTP_CONNECTION.name()), serverHttpConnection); designer.link(handler.getFunctionObject(Dependencies.HTTP_SESSION.name()), httpSession); designer.link(handler.getFunctionObject(Dependencies.REQUEST_STATE.name()), requestState); for (String httpSecurityName : this.httpSecurityNames) { SectionOutput output = designer.addSectionOutput(httpSecurityName, null, false); FunctionFlow flow = handler.getFunctionFlow(httpSecurityName); designer.link(flow, output, false); SectionFunction sender = namespace.addSectionFunction("sender", "sender"); designer.link(sender.getFunctionObject( net.officefloor.web.security.impl.SendHttpChallengeFunction.Dependencies.HTTP_CHALLENGE_CONTEXT.name()), httpChallengeContext); designer.link(sender.getFunctionObject(
@Override public void sourceSection(SectionDesigner designer, SectionSourceContext context) throws Exception { final Map<Class<?>, SectionObject> objects = new HashMap<Class<?>, SectionObject>(); final Map<Class<?>, SectionOutput> escalations = new HashMap<Class<?>, SectionOutput>(); // Add file sender SectionWork sendFileWork = designer.addSectionWork("FILE", HttpFileSenderWorkSource.class.getName()); SourceHttpResourceFactory.copyProperties(context, sendFileWork); SectionTask sendFileTask = sendFileWork.addSectionTask( HttpFileSenderWorkSource.TASK_NAME, HttpFileSenderWorkSource.TASK_NAME); WebApplicationSectionSource.linkObject(sendFileTask, DependencyKeys.SERVER_HTTP_CONNECTION.name(), ServerHttpConnection.class, designer, objects); WebApplicationSectionSource.linkObject(sendFileTask, DependencyKeys.HTTP_APPLICATION_LOCATION.name(), HttpApplicationLocation.class, designer, objects); WebApplicationSectionSource.linkEscalation(sendFileTask, IOException.class, designer, escalations); WebApplicationSectionSource.linkEscalation(sendFileTask, InvalidHttpRequestUriException.class, designer, escalations); // Provide input to service SectionInput input = designer.addSectionInput(SERVICE_INPUT_NAME, null); designer.link(input, sendFileTask); // Provide output once file written SectionOutput output = designer.addSectionOutput(FILE_SENT_OUTPUT_NAME, null, false); designer.link(sendFileTask, output); }
.createPropertyList(); properties .addProperty( SectionWork work = designer.addSectionWork( gwtServiceName, GwtServiceWorkSource.class.getName()); for (Property property : properties) { work.addProperty(property.getName(), property.getValue()); SectionTask task = work.addSectionTask( gwtServiceName, GwtServiceWorkSource.SERVICE_TASK_NAME); .getTaskObject(Dependencies.SERVER_GWT_RPC_CONNECTION .name()); SectionObject connectionObject = context .getOrCreateSectionObject(ServerGwtRpcConnection.class .getName()); designer.link(connectionDependency, connectionObject); .addSectionInput(gwtServiceName, null); designer.link(serviceInput, task); WorkType<?> workType = sectionContext.loadWorkType( GwtServiceWorkSource.class.getName(), properties);
@Override public SectionFlowSinkNode secureFlow(SectionDesigner designer, Class<?> argumentType, SectionFlowSinkNode secureFlowSink, SectionFlowSinkNode insecureFlowSink) { // Create the annotation HttpFlowSecurerAnnotation annotation = new HttpFlowSecurerAnnotation( this.httpSecurerBuilder.getHttpSecurityName(), this.httpSecurerBuilder.getAnyRoles(), this.httpSecurerBuilder.getRequiredRoles(), argumentType); // Configure the function String functionName = HttpSecurityArchitectEmployer.this.nextUniqueName(); SectionFunctionNamespace namespace = designer.addSectionFunctionNamespace(functionName, new HttpFlowSecurerManagedFunctionSource(annotation)); SectionFunction function = namespace.addSectionFunction(functionName, HttpFlowSecurerManagedFunctionSource.FUNCTION_NAME); // Configure the function designer.link(function.getFunctionFlow(Flows.SECURE.name()), secureFlowSink, false); designer.link(function.getFunctionFlow(Flows.INSECURE.name()), insecureFlowSink, false); // Return the decision flow sink return function; } }
@Override public void sourceSection(SectionDesigner designer, SectionSourceContext context) throws Exception { // Create the Servlet Bridge dependency SectionObject servletBridge = designer.addSectionObject( "SERVLET_BRIDGE", ServletBridge.class.getName()); // Create the non-handled task String nonHandledInputName = context.getSectionLocation(); this.addServletResource(nonHandledInputName, null, servletBridge, designer); // Create the Servlet container resource tasks Set<String> registeredResources = new HashSet<String>(); for (String inputName : context.getPropertyNames()) { // Obtain the request dispatcher path String requestDispatcherPath = context.getProperty(inputName); // Ensure only register the resource once if (registeredResources.contains(requestDispatcherPath)) { continue; } // Add Servlet Resource this.addServletResource(inputName, requestDispatcherPath, servletBridge, designer); // Resource registered registeredResources.add(requestDispatcherPath); } }
/** * Links the {@link TaskObject} to the {@link SectionObject}. * * @param task * {@link SectionTask}. * @param objectName * Name of the object. * @param objectType * Type of the object. * @param designer * {@link SectionDesigner}. * @param objects * Registry of the {@link SectionObject} by type of object. */ static void linkObject(SectionTask task, String objectName, Class<?> objectType, SectionDesigner designer, Map<Class<?>, SectionObject> objects) { // Obtain the section object SectionObject sectionObject = objects.get(objectType); if (sectionObject == null) { sectionObject = designer.addSectionObject(objectType.getName(), objectType.getName()); objects.put(objectType, sectionObject); } // Link task object to section object TaskObject taskObject = task.getTaskObject(objectName); designer.link(taskObject, sectionObject); }
for (String propertyName : context.getPropertyNames()) { if (propertyName.startsWith(PROPERTY_URL_LINK_PREFIX)) { String inputName = context.getProperty(propertyName); String isSecureText = context.getProperty( PROPERTY_URL_SECURE_PREFIX + uriPath, null); Boolean isSecure = null; work.addProperty( HttpUrlContinuationWorkSource.PROPERTY_URI_PATH, uriPath); if (isSecure != null) { work.addProperty( HttpUrlContinuationWorkSource.PROPERTY_SECURE, String.valueOf(isSecure)); SectionTask task = work.addSectionTask(taskName, HttpUrlContinuationWorkSource.TASK_NAME); .getSubSectionInput(inputName);
.addIssue("Template logic class " + sectionClass.getName() + " is annotated with " + HttpSessionStateful.class.getSimpleName() + " but is not " + Serializable.class.getSimpleName()); .addSectionManagedObjectSource(objectName, HttpSessionObjectManagedObjectSource.class.getName()); managedObjectSource.addProperty(HttpSessionObjectManagedObjectSource.PROPERTY_CLASS_NAME, sectionClass.getName()); this.sectionClassManagedObject = managedObjectSource.addSectionManagedObject(objectName, ManagedObjectScope.PROCESS);
@Override protected DependencyMetaData[] extractClassManagedObjectDependencies(String objectName, Class<?> sectionClass) throws Exception { // Extract the dependency meta-data for default behaviour DependencyMetaData[] metaData = super.extractClassManagedObjectDependencies(objectName, sectionClass); // Determine if stateful boolean isStateful = isHttpSessionStateful(sectionClass); // If not stateful, return meta-data for default behaviour if (!isStateful) { return metaData; } // As stateful, must not have any dependencies into object if (metaData.length > 0) { throw this.getDesigner() .addIssue("Template logic class " + sectionClass.getName() + " is annotated with " + HttpSessionStateful.class.getSimpleName() + " and therefore can not have dependencies injected into the object (only its methods)"); } // Return the dependency meta-data for stateful template logic return new DependencyMetaData[] { new StatefulDependencyMetaData() }; }
@Override protected void enrichTask(SectionTask task, TaskType<?, ?, ?> taskType, Method method, Class<?> parameterType) { // Do not include if no logic class if (NoLogicClass.class.equals(this.sectionClass)) { return; } // Keep track of the tasks to allow linking by case-insensitive names String taskKey = createTaskKey(task.getSectionTaskName()); this.sectionClassMethodTasksByName.put(taskKey, new TemplateClassTask(task, taskType, method, parameterType)); // Enrich the task super.enrichTask(task, taskType, method, parameterType); }
@Override protected void enrichFunction(SectionFunction function, ManagedFunctionType<?, ?> functionType, Method method, Class<?> parameterType) { // Do not include if no logic class if (NoLogicClass.class.equals(this.sectionClass)) { return; } // Keep track of the functions to allow linking by case-insensitive // names String functionKey = createFunctionKey(function.getSectionFunctionName()); this.sectionClassMethodFunctionsByName.put(functionKey, new TemplateClassFunction(function, functionType, method, parameterType)); // Enrich the function super.enrichFunction(function, functionType, method, parameterType); }
.addSectionObject(ServerHttpConnection.class.getSimpleName(), ServerHttpConnection.class.getName()); SectionOutput ioEscalationOutput = designer.addSectionOutput( IOException.class.getSimpleName(), IOException.class.getName(), true); for (String name : context.getPropertyNames()) { if (name.startsWith(PROPERTY_RESOURCE_PREFIX)) { String resourcePath = context.getProperty(name); SectionWork work = designer.addSectionWork(resourcePath, HttpFileWorkSource.class.getName()); SourceHttpResourceFactory.copyProperties(context, work); work.addProperty(HttpFileWorkSource.PROPERTY_RESOURCE_PATH, resourcePath); SectionTask task = work.addSectionTask(resourcePath, HttpFileWorkSource.TASK_HTTP_FILE); .getTaskObject(DependencyKeys.SERVER_HTTP_CONNECTION .name()); designer.link(serverHttpConnectionObject, serverHttpConnectionDependency); .getTaskEscalation(IOException.class.getName()); designer.link(ioEscalationFlow, ioEscalationOutput, FlowInstigationStrategyEnum.SEQUENTIAL);
SectionObject serverHttpConnection = designer.addSectionObject(ServerHttpConnection.class.getSimpleName(), ServerHttpConnection.class.getName()); SectionObject httpSession = designer.addSectionObject(HttpSession.class.getSimpleName(), HttpSession.class.getName()); SectionObject httpRequestState = designer.addSectionObject(HttpRequestState.class.getSimpleName(), HttpRequestState.class.getName()); SectionObject authenticationContext = designer.addSectionObject(AuthenticationContext.class.getSimpleName(), AuthenticationContext.class.getName()); SectionObject accessControl = designer.addSectionObject("AccessControl", accessControlType.getName()); SectionObject httpChallengeContext = designer.addSectionObject(HttpChallengeContext.class.getSimpleName(), HttpChallengeContext.class.getName()); for (int i = 0; i < dependencyObjects.length; i++) { HttpSecurityDependencyType<?> dependencyType = dependencyTypes[i]; dependencyObjects[i] = designer.addSectionObject("Dependency_" + dependencyType.getDependencyName(), dependencyType.getDependencyType().getName()); dependencyObjects[i].setTypeQualifier(dependencyType.getTypeQualifier()); SectionFunctionNamespace namespace = designer.addSectionFunctionNamespace("HttpSecuritySource", new HttpSecurityManagedFunctionSource(security, securityType)); SectionFunction challengeFunction = namespace.addSectionFunction( HttpSecurityManagedFunctionSource.FUNCTION_CHALLENGE, HttpSecurityManagedFunctionSource.FUNCTION_CHALLENGE); designer.link(challengeFunction.getFunctionObject(HttpChallengeContext.class.getSimpleName()), httpChallengeContext); designer.link(challengeFunction.getFunctionObject(ServerHttpConnection.class.getSimpleName()), serverHttpConnection);
SectionWork routeWork = designer.addSectionWork("ROUTE", HttpRouteWorkSource.class.getName()); SectionTask routeTask = routeWork.addSectionTask("ROUTE", HttpRouteWorkSource.TASK_NAME); linkObject(routeTask, SectionInput input = designer.addSectionInput( HttpServerAutoWireOfficeFloorSource.HANDLER_INPUT_NAME, null); designer.link(input, routeTask); .getTaskFlow(HttpRouteTaskFlows.NOT_HANDLED.name()); SectionOutput unhandledRequestOutput = designer.addSectionOutput( UNHANDLED_REQUEST_OUTPUT_NAME, null, false); designer.link(unhandledServiceFlow, unhandledRequestOutput, FlowInstigationStrategyEnum.SEQUENTIAL); SectionWork sendResponseWork = designer.addSectionWork("SEND", HttpResponseSenderWorkSource.class.getName()); SectionTask sendResponseTask = sendResponseWork.addSectionTask("SEND", "SEND"); linkObject(sendResponseTask, linkEscalation(sendResponseTask, IOException.class, designer, escalations); SectionInput sendResponseInput = designer.addSectionInput( SEND_RESPONSE_INPUT_NAME, null); designer.link(sendResponseInput, sendResponseTask);
.addIssue("Template logic class " + sectionClass.getName() + " is annotated with " + HttpSessionStateful.class.getSimpleName() + " but is not " + Serializable.class.getSimpleName()); .addSectionManagedObjectSource(objectName, HttpSessionObjectManagedObjectSource.class.getName()); managedObjectSource.addProperty(HttpSessionObjectManagedObjectSource.PROPERTY_CLASS_NAME, sectionClass.getName()); this.sectionClassManagedObject = managedObjectSource.addSectionManagedObject(objectName, ManagedObjectScope.PROCESS);
@Override protected DependencyMetaData[] extractClassManagedObjectDependencies(String objectName, Class<?> sectionClass) throws Exception { // Extract the dependency meta-data for default behaviour DependencyMetaData[] metaData = super.extractClassManagedObjectDependencies(objectName, sectionClass); // Determine if stateful boolean isStateful = this.isHttpSessionStateful(sectionClass); // If not stateful, return meta-data for default behaviour if (!isStateful) { return metaData; } // As stateful, must not have any dependencies into object if (metaData.length > 0) { this.getDesigner() .addIssue("Template logic class " + sectionClass.getName() + " is annotated with " + HttpSessionStateful.class.getSimpleName() + " and therefore can not have dependencies injected into the object (only its methods)"); } // Return the dependency meta-data for stateful template logic return new DependencyMetaData[] { new StatefulDependencyMetaData() }; }