21
21
import org .lowcoder .plugin .api .data .EndpointRequest ;
22
22
import org .lowcoder .plugin .api .data .EndpointResponse ;
23
23
import org .lowcoder .sdk .exception .BaseException ;
24
+ import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
24
25
import org .springframework .context .ApplicationContext ;
25
26
import org .springframework .context .support .GenericApplicationContext ;
26
27
import org .springframework .core .ResolvableType ;
30
31
import org .springframework .web .reactive .function .server .RouterFunction ;
31
32
import org .springframework .web .reactive .function .server .ServerResponse ;
32
33
import org .springframework .web .reactive .function .server .ServerResponse .BodyBuilder ;
33
- import org .springframework .web .reactive .function .server .support .RouterFunctionMapping ;
34
34
35
35
import lombok .RequiredArgsConstructor ;
36
36
import lombok .extern .slf4j .Slf4j ;
@@ -45,7 +45,7 @@ public class PluginEndpointHandlerImpl implements PluginEndpointHandler
45
45
private List <RouterFunction <ServerResponse >> routes = new ArrayList <>();
46
46
47
47
private final ApplicationContext applicationContext ;
48
- private final RouterFunctionMapping routerFunctionMapping ;
48
+ private final DefaultListableBeanFactory beanFactory ;
49
49
50
50
@ Override
51
51
public void registerEndpoints (String pluginUrlPrefix , List <PluginEndpoint > endpoints )
@@ -54,20 +54,24 @@ public void registerEndpoints(String pluginUrlPrefix, List<PluginEndpoint> endpo
54
54
55
55
if (CollectionUtils .isNotEmpty (endpoints ))
56
56
{
57
-
57
+ List < EndpointExtension > toAuthorize = new ArrayList <>();
58
58
for (PluginEndpoint endpoint : endpoints )
59
59
{
60
60
Method [] handlers = endpoint .getClass ().getDeclaredMethods ();
61
61
if (handlers != null && handlers .length > 0 )
62
62
{
63
63
for (Method handler : handlers )
64
64
{
65
- registerEndpointHandler (urlPrefix , endpoint , handler );
65
+ toAuthorize . addAll ( registerEndpointHandler (urlPrefix , endpoint , handler ) );
66
66
}
67
67
}
68
68
}
69
69
70
- ((ReloadableRouterFunctionMapping )routerFunctionMapping ).reloadFunctionMappings ();
70
+ ((ReloadableRouterFunctionMapping )beanFactory .getBean ("routerFunctionMapping" )).reloadFunctionMappings ();
71
+ if (!toAuthorize .isEmpty ())
72
+ {
73
+ // TODO: ludomikula: finish endpoint authorization
74
+ }
71
75
}
72
76
}
73
77
@@ -77,8 +81,10 @@ public List<RouterFunction<ServerResponse>> registeredEndpoints()
77
81
return routes ;
78
82
}
79
83
80
- private void registerEndpointHandler (String urlPrefix , PluginEndpoint endpoint , Method handler )
84
+ private List < EndpointExtension > registerEndpointHandler (String urlPrefix , PluginEndpoint endpoint , Method handler )
81
85
{
86
+ List <EndpointExtension > toAuthorize = new ArrayList <>();
87
+
82
88
if (handler .isAnnotationPresent (EndpointExtension .class ))
83
89
{
84
90
if (checkHandlerMethod (handler ))
@@ -103,13 +109,20 @@ private void registerEndpointHandler(String urlPrefix, PluginEndpoint endpoint,
103
109
routes .add (routerFunction );
104
110
registerRouterFunctionMapping (endpointName , routerFunction );
105
111
112
+ if (endpointMeta .authenticated ())
113
+ {
114
+ toAuthorize .add (endpointMeta );
115
+ }
116
+
106
117
log .info ("Registered endpoint: {} -> {}: {}" , endpoint .getClass ().getSimpleName (), endpointMeta .method (), urlPrefix + endpointMeta .uri ());
107
118
}
108
119
else
109
120
{
110
121
log .error ("Cannot register plugin endpoint: {} -> {}! Handler method must be defined as: public Mono<ServerResponse> {}(ServerRequest request)" , endpoint .getClass ().getSimpleName (), handler .getName (), handler .getName ());
111
122
}
112
123
}
124
+
125
+ return toAuthorize ;
113
126
}
114
127
115
128
private void registerRouterFunctionMapping (String endpointName , RouterFunction <ServerResponse > routerFunction )
0 commit comments