Feat:启用jwt配置化

This commit is contained in:
wangyu 2021-01-10 00:13:34 +08:00
parent be17a84462
commit e440659571
17 changed files with 149 additions and 1285 deletions

View File

@ -9,6 +9,7 @@ import java.net.URI;
import java.nio.CharBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* In-memory java file manager.
@ -18,7 +19,7 @@ import java.util.Map;
class MemoryJavaFileManager extends ForwardingJavaFileManager<JavaFileManager> {
// compiled classes in bytes:
final Map<String, byte[]> classBytes = new HashMap<>();
final Map<String, byte[]> classBytes = new ConcurrentHashMap<>();
MemoryJavaFileManager(JavaFileManager fileManager) {
super(fileManager);

View File

@ -2,11 +2,13 @@ package com.flyfish.framework.config;
import com.flyfish.framework.config.properties.JwtProperties;
import com.flyfish.framework.config.properties.SecurityProperties;
import com.flyfish.framework.configuration.jwt.JwtSecurityContextRepository;
import com.flyfish.framework.configuration.jwt.TokenProvider;
import com.flyfish.framework.handler.JsonAuthenticationFailureHandler;
import com.flyfish.framework.handler.JsonAuthenticationSuccessHandler;
import com.flyfish.framework.handler.JsonLogoutSuccessHandler;
import com.flyfish.framework.transform.ResultDataTransformer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
@ -46,6 +48,14 @@ public class WebSecurityConfig {
return delegatingPasswordEncoder;
}
@ConditionalOnProperty(value = "jwt.enable", havingValue = "true")
@Bean("contextRepository")
public JwtSecurityContextRepository jwtSecurityContextRepository() {
return new JwtSecurityContextRepository();
}
@ConditionalOnProperty(value = "jwt.enable", havingValue = "false")
@Bean
public ServerSecurityContextRepository contextRepository() {
return new WebSessionServerSecurityContextRepository();
@ -53,7 +63,9 @@ public class WebSecurityConfig {
@Bean
public TokenProvider tokenProvider(JwtProperties properties) {
return new TokenProvider(properties.getBase64Secret(), properties.getTokenValidityInSeconds(),
return new TokenProvider(
properties.getBase64Secret(),
properties.getTokenValidityInSeconds(),
properties.getTokenValidityInSecondsForRememberMe());
}

View File

@ -14,6 +14,9 @@ import java.util.Map;
@Data
public class JwtProperties {
// 是否启用
private boolean enable = false;
// 头部
private String header = "Authorization";
// This token must be encoded using Base64 with mininum 88 Bits (you can type `echo 'secret-key'|base64` on your command line)
private String base64Secret = "ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=";

View File

@ -1,620 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>19H15</string>
<key>CFBundleExecutable</key>
<string>VoodooPS2Keyboard</string>
<key>CFBundleGetInfoString</key>
<string>2.2.0, Copyright Apple Computer, Inc. 2000-2003, RehabMan 2012-2013</string>
<key>CFBundleIdentifier</key>
<string>as.acidanthera.voodoo.driver.PS2Keyboard</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Voodoo PS/2 Keyboard</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>2.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>2.2.0</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>12B45b</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>11.0</string>
<key>DTSDKBuild</key>
<string>20A2408</string>
<key>DTSDKName</key>
<string>macosx11.0</string>
<key>DTXcode</key>
<string>1220</string>
<key>DTXcodeBuild</key>
<string>12B45b</string>
<key>IOKitPersonalities</key>
<dict>
<key>ApplePS2Keyboard</key>
<dict>
<key>CFBundleIdentifier</key>
<string>as.acidanthera.voodoo.driver.PS2Keyboard</string>
<key>IOClass</key>
<string>ApplePS2Keyboard</string>
<key>IOProviderClass</key>
<string>ApplePS2KeyboardDevice</string>
<key>Platform Profile</key>
<dict>
<key>DELL</key>
<dict>
<key>Dell-Keys</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e005</string>
<string>e006</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 12 items map Fn+fkeys to fkeys</string>
<string>e020=3b</string>
<string>e02e=3c</string>
<string>e030=3d</string>
<string>e022=3e</string>
<string>;Fn+f5 macro</string>
<string>;Fn+f6 macro</string>
<string>;Fn+f7 macro</string>
<string>;Fn+f8 macro</string>
<string>;Fn+f9 macro</string>
<string>;Fn+f10 no code</string>
<string>e005=57</string>
<string>e006=58</string>
<string>;The following 12 items map fkeys to Fn+fkeys</string>
<string>3b=e020</string>
<string>3c=e02e</string>
<string>3d=e030</string>
<string>3e=e022</string>
<string>;Fn+f5 macro</string>
<string>;Fn+f6 macro</string>
<string>;Fn+f7 macro</string>
<string>;Fn+f8 macro</string>
<string>;Fn+f9 macro</string>
<string>;Fn+f10 no code</string>
<string>57=e005</string>
<string>58=e006</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 12 items map Fn+fkeys to Fn+fkeys</string>
<string>e020=e020</string>
<string>e02e=e02e</string>
<string>e030=e030</string>
<string>e022=e022</string>
<string>;Fn+f5 macro</string>
<string>;Fn+f6 macro</string>
<string>;Fn+f7 macro</string>
<string>;Fn+f8 macro</string>
<string>;Fn+f9 macro</string>
<string>;Fn+f10 no code</string>
<string>e005=e005</string>
<string>e006=e006</string>
<string>;The following 12 items map fkeys to fkeys</string>
<string>3b=3b</string>
<string>3c=3c</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>3f=3f</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
<string>57=57</string>
<string>58=58</string>
</array>
</dict>
<key>HSW-LPT</key>
<string>Dell-Keys</string>
<key>SNB-CPT</key>
<dict>
<key>ActionSwipeDown</key>
<string>63 d, 63 u</string>
<key>ActionSwipeUp</key>
<string>61 d, 61 u</string>
<key>Breakless PS2</key>
<array>
<string>e01e;Touchpad Fn+f3 is breakless</string>
<string>e06e;REVIEW: temporary for case that macro inversion does not work...</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>e009=83;Dell Support to Launchpad</string>
<string>e0f1=71;Call brightens up w RKA1 for special mode (was =90)</string>
<string>e0f2=6b;Call brightens down w RKA2 for special mode (was =91)</string>
<string>e06e=70;Map vidmirror key for special mode default is adb90</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>e01e=e037;Map tp disable to Fn+f3</string>
<string>e037=e01e;Prevent PrntScr from triggering tp disable</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 12 items map Fn+fkeys to fkeys</string>
<string>e06e=3b</string>
<string>e008=3c</string>
<string>e01e=3d</string>
<string>e005=3e</string>
<string>e006=3f</string>
<string>e00c=40</string>
<string>;Fn+f7 no dedicated macro</string>
<string>e010=42</string>
<string>e022=43</string>
<string>e019=44</string>
<string>e02e=57</string>
<string>e030=58</string>
<string>;The following 12 items map fkeys to Fn+fkeys</string>
<string>3b=e06e;Map vidmirror key to f1</string>
<string>3c=e0f0;Map radio toggle action from EC query to f2</string>
<string>3d=e037;Map touchpad toggle button to f3</string>
<string>3e=e0f2;Map acpi RKA2 to f4 brightness down</string>
<string>3f=e0f1;Map acpi RKA1 to f5 brightness up</string>
<string>40=e0f3;Map acpi RKA3 to f6 keyboard backlight</string>
<string>;Fn+f7 no macro</string>
<string>42=e010</string>
<string>43=e022</string>
<string>44=e019</string>
<string>57=e02e</string>
<string>58=e030</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 12 items map Fn+fkeys to Fn+fkeys</string>
<string>e06e=e06e;Fn+f1 macro translated</string>
<string>e008=e008;Fn+f2 regular scancode and EC query call q8c</string>
<string>e01e=e037;Fn+f3 regular scancode and EC controls LED</string>
<string>e005=e005;Fn+f4 no ps2scancode and EC query call q81</string>
<string>e006=e006;Fn+f5 no ps2scancode and EC query call q80</string>
<string>e00c=e00c;Fn+f6 no ps2scancode and EC query call q8a</string>
<string>;Fn+f7 no macro just regular f key</string>
<string>e010=e010; Fn+f8 regular scancode</string>
<string>e022=e022; Fn+f9 regular scancode</string>
<string>e019=e019;Fn+f10 regular scancode</string>
<string>e02e=e02e;Fn+f11 regular scancode</string>
<string>e030=e030;Fn+f12 regular scancode</string>
<string>;Fn+f13 is mute dedicated button that always produces e020 regardless of Fn</string>
<string>;The following 12 items map fkeys to fkeys</string>
<string>3b=3b</string>
<string>3c=3c</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>3f=3f</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
<string>57=57</string>
<string>58=58</string>
</array>
<key>Macro Inversion</key>
<array>
<string>;This section maps ps2 codes (packet format) received quickly (macros) into fake ps2 codes (packet format)</string>
<string>;Fn+F1</string>
<data>
//8CbgAAAAACWwEZ
</data>
<data>
//8C7gAAAAAC2wGZ
</data>
<data>
//8C7gAAAAABmQLb
</data>
</array>
<key>MaximumMacroTime</key>
<integer>35000000</integer>
<key>Note-Author</key>
<string>TimeWalker aka TimeWalker75a</string>
<key>Note-Comment</key>
<string>Keyboard Profile for DELL SandyBridge SecureCore Tiano based laptops (Vostro 3450 &amp; 3750, Inspiron N4110, XPS L502x &amp; L702x &amp; L511z)</string>
</dict>
<key>WN09</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e01b</string>
<string>e008</string>
<string>e01e</string>
<string>e005</string>
<string>e06e</string>
<string>e006</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>e01b=70</string>
<string>e06e=83</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>56=2b</string>
<string>29=56</string>
<string>2b=29</string>
<string>e01e=e037</string>
<string>e037=e01e</string>
</array>
</dict>
<key>WN09a</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e01b</string>
<string>e008</string>
<string>e01e</string>
<string>e005</string>
<string>e06e</string>
<string>e006</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>e01b=70</string>
<string>e06e=83</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>e01e=e037</string>
<string>e037=e01e</string>
</array>
</dict>
</dict>
<key>Default</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>;Items must be strings in the form of breaklessscan (in hex)</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>;Items must be strings in the form of scanfrom=adbto (in hex)</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>;Items must be strings in the form of scanfrom=scanto (in hex)</string>
<string>e027=0;disable discrete fnkeys toggle</string>
<string>e028=0;disable discrete trackpad toggle</string>
</array>
<key>HIDF12EjectDelay</key>
<integer>250</integer>
<key>LogScanCodes</key>
<integer>0</integer>
<key>Make Application key into Apple Fn key</key>
<false/>
<key>Make Application key into right windows</key>
<true/>
<key>Make right modifier keys into Hangul and Hanja</key>
<false/>
<key>SleepPressTime</key>
<integer>0</integer>
<key>Swap capslock and left control</key>
<false/>
<key>Swap command and option</key>
<true/>
<key>Use ISO layout keyboard</key>
<false/>
<key>alt_handler_id</key>
<integer>3</integer>
</dict>
<key>HPQOEM</key>
<dict>
<key>1411</key>
<string>ProBook-102;ProBook 4520s</string>
<key>1619</key>
<string>ProBook-87;ProBook 6560b</string>
<key>161C</key>
<string>ProBook-87;ProBook 8460p</string>
<key>164F</key>
<string>ProBook-87;ProBook 5330m</string>
<key>167C</key>
<string>ProBook-102;ProBook 4530s</string>
<key>167E</key>
<string>ProBook-102;ProBook 4330s</string>
<key>1680</key>
<string>ProBook-102;ProBook 4230s</string>
<key>179B</key>
<string>ProBook-87;ProBook 6470b</string>
<key>179C</key>
<string>ProBook-87;ProBook 6470b</string>
<key>17A9</key>
<string>ProBook-87;ProBook 8570b</string>
<key>17F0</key>
<string>ProBook-102;ProBook 4340s</string>
<key>17F3</key>
<string>ProBook-102;ProBook 4440s</string>
<key>17F6</key>
<string>ProBook-102;ProBook 4540s</string>
<key>1942</key>
<string>ProBook-87;ProBook 450s G1</string>
<key>1949</key>
<string>ProBook-87;ProBook 450s G1</string>
<key>1962</key>
<string>Haswell-Envy;HP Envy 15-j063cl</string>
<key>1963</key>
<string>Haswell-Envy;HP Envy 15-j063cl</string>
<key>1965</key>
<string>Haswell-Envy;HP Envy 17t-j100</string>
<key>1966</key>
<string>Haswell-Envy;HP Envy 17t-j000</string>
<key>198F</key>
<string>ProBook-87;ProBook 450s G0</string>
<key>Haswell-Envy</key>
<dict>
<key>Custom ADB Map</key>
<array>
<string>e019=42;next</string>
<string>e010=4d;previous</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>e045=e037</string>
<string>e0ab=0;bogus Fn+F2/F3</string>
</array>
</dict>
<key>ProBook-102</key>
<dict>
<key>Custom PS2 Map</key>
<array>
<string>e005=0</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 12 items map Fn+fkeys to fkeys</string>
<string>e05f=3b</string>
<string>e012=3c</string>
<string>e017=3d</string>
<string>e06e=3e</string>
<string>e00a=3f</string>
<string>e009=40</string>
<string>e020=41</string>
<string>e02e=42</string>
<string>e030=43</string>
<string>e010=44</string>
<string>e022=57</string>
<string>e019=58</string>
<string>;The following 12 items map fkeys to Fn+fkeys</string>
<string>3b=e05f</string>
<string>3c=e012</string>
<string>3d=e017</string>
<string>3e=e06e</string>
<string>3f=e00a</string>
<string>40=e009</string>
<string>41=e020</string>
<string>42=e02e</string>
<string>43=e030</string>
<string>44=e010</string>
<string>57=e022</string>
<string>58=e019</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 12 items map Fn+fkeys to Fn+fkeys</string>
<string>e05f=e05f</string>
<string>e012=e012</string>
<string>e017=e017</string>
<string>e06e=e06e</string>
<string>e00a=e00a</string>
<string>e009=e009</string>
<string>e020=e020</string>
<string>e02e=e02e</string>
<string>e030=e030</string>
<string>e010=e010</string>
<string>e022=e022</string>
<string>e019=e019</string>
<string>;The following 12 items map fkeys to fkeys</string>
<string>3b=3b</string>
<string>3c=3c</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>3f=3f</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
<string>57=57</string>
<string>58=58</string>
</array>
<key>SleepPressTime</key>
<integer>3000</integer>
</dict>
<key>ProBook-87</key>
<dict>
<key>Custom ADB Map</key>
<array>
<string>46=4d;scroll =&gt; Previous-track</string>
<string>e045=34;pause =&gt; Play-Pause</string>
<string>e052=42;insert =&gt; Next-track</string>
<string>e046=92;break =&gt; Eject</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>e005=0</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 8 items map Fn+fkeys to fkeys</string>
<string>e05f=3d</string>
<string>e06e=3e</string>
<string>e02e=40</string>
<string>e030=41</string>
<string>e009=42</string>
<string>e012=43</string>
<string>e017=44</string>
<string>e033=57</string>
<string>;The following 8 items map fkeys to Fn+fkeys</string>
<string>3d=e05f</string>
<string>3e=e06e</string>
<string>40=e02e</string>
<string>41=e030</string>
<string>42=e037</string>
<string>43=e012</string>
<string>44=e017</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 8 items map Fn+fkeys to Fn+fkeys</string>
<string>e05f=e05f</string>
<string>e06e=e06e</string>
<string>e02e=e02e</string>
<string>e030=e030</string>
<string>e009=e009</string>
<string>e012=e012</string>
<string>e017=e017</string>
<string>e033=e033</string>
<string>;The following 8 items map fkeys to fkeys</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
</array>
<key>SleepPressTime</key>
<integer>3000</integer>
</dict>
</dict>
<key>Intel</key>
<dict>
<key>CALPELLA</key>
<string>SamsungKeys</string>
<key>SamsungKeys</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e003</string>
<string>e002</string>
<string>e004</string>
<string>e020</string>
<string>;e031</string>
<string>e033</string>
<string>e006</string>
<string>e077</string>
<string>e079</string>
<string>e008</string>
<string>e009</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>e002=70</string>
<string>e006=80</string>
<string>e008=71 (was =90)</string>
<string>e009=6b (was =91)</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 12 items map Fn+fkeys to fkeys</string>
<string>;fn+f1 no code</string>
<string>e003=3c</string>
<string>;fn+f3 weird code</string>
<string>e002=3e</string>
<string>e004=3f</string>
<string>e020=40</string>
<string>e031=41</string>
<string>e033=42</string>
<string>e006=43</string>
<string>;fn+f10 weird code</string>
<string>;fn+f11 no code</string>
<string>;fn+f12 scrolllock</string>
<string>;The following 12 items map fkeys to Fn+fkeys</string>
<string>;fn+f1 no code</string>
<string>3c=e003</string>
<string>;fn+f3 weird code</string>
<string>3e=e002</string>
<string>3f=e004</string>
<string>40=e020</string>
<string>41=e031</string>
<string>42=e033</string>
<string>43=e006</string>
<string>;fn+f10 weird code</string>
<string>;fn+f11 no code</string>
<string>;fn+f12 scrolllock</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 12 items map Fn+fkeys to Fn+fkeys</string>
<string>;fn+f1 no code</string>
<string>e003=e003</string>
<string>;fn+f3 weird code</string>
<string>e002=e002</string>
<string>e004=e004</string>
<string>e020=e020</string>
<string>e031=e031</string>
<string>e033=e033</string>
<string>e006=e006</string>
<string>;fn+f10 weird code</string>
<string>;fn+f11 no code</string>
<string>;fn+f12 scrolllock</string>
<string>;The following 12 items map fkeys to fkeys</string>
<string>3b=3b</string>
<string>3c=3c</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>3f=3f</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
<string>57=57</string>
<string>58=58</string>
</array>
</dict>
</dict>
<key>SECCSD</key>
<dict>
<key>LH43STAR</key>
<string>SamsungKeys</string>
<key>SamsungKeys</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e020</string>
<string>e02e</string>
<string>e030</string>
</array>
</dict>
</dict>
</dict>
</dict>
</dict>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
<key>OSBundleLibraries</key>
<dict>
<key>as.acidanthera.voodoo.driver.PS2Controller</key>
<string>2.2.0</string>
<key>com.apple.iokit.IOHIDFamily</key>
<string>1.0.0b1</string>
<key>com.apple.kpi.bsd</key>
<string>8.0.0</string>
<key>com.apple.kpi.iokit</key>
<string>8.0.0</string>
<key>com.apple.kpi.libkern</key>
<string>8.0.0</string>
<key>com.apple.kpi.mach</key>
<string>8.0.0</string>
<key>com.apple.kpi.unsupported</key>
<string>8.0.0</string>
</dict>
<key>OSBundleRequired</key>
<string>Console</string>
</dict>
</plist>

View File

@ -1,6 +1,18 @@
package com.flyfish.framework.beans.enums;
public enum RestBeanCandidate {
import com.flyfish.framework.enums.NamedEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
REPOSITORY, SERVICE, CONTROLLER
/**
* rest-bean生成的类型
* @author wangyu
*/
@Getter
@AllArgsConstructor
public enum RestBeanCandidate implements NamedEnum {
REPOSITORY("Repository"), SERVICE("Service"), CONTROLLER("Controller");
private final String name;
}

View File

@ -1,16 +1,18 @@
package com.flyfish.framework.beans.meta;
import com.flyfish.framework.bean.Result;
import com.flyfish.framework.beans.resolver.DynamicRestBeanResolver;
import com.flyfish.framework.utils.StringFormats;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* bean控制器可以通过类直接返回bean信息
@ -22,21 +24,42 @@ import java.util.List;
@Slf4j
public class BeanController {
@Resource
private DynamicRestBeanResolver dynamicRestBeanResolver;
/**
* 通过类标识返回bean信息
*
* @return 结果
*/
@GetMapping("")
public Result<List<BeanProperty>> beanInfo(String className) {
public Result<BeanInfo> beanInfo(String className) {
if (StringUtils.isBlank(className)) {
return Result.ok(Collections.emptyList());
return Result.empty();
}
try {
return Result.ok(BeanProperty.from(ClassUtils.getClass(className)));
Class<?> clazz = ClassUtils.getClass(className);
BeanInfo info = new BeanInfo();
info.setCode(StringFormats.camel2Line(ClassUtils.getShortClassName(clazz)));
if (clazz.isAnnotationPresent(RestBean.class)) {
info.setName(clazz.getAnnotation(RestBean.class).name());
}
info.setProperties(BeanProperty.from(clazz));
return Result.ok(info);
} catch (ClassNotFoundException e) {
log.error(e.getMessage(), e);
return Result.error(e.getMessage());
}
}
/**
* 列出自动注册的bean快速接入
*
* @return 结果
*/
@GetMapping("list")
public Result<List<String>> beanList() {
return Result.accept(dynamicRestBeanResolver.getClasses().stream().map(ClassUtils::getCanonicalName)
.collect(Collectors.toList()));
}
}

View File

@ -0,0 +1,22 @@
package com.flyfish.framework.beans.meta;
import lombok.Data;
import java.util.List;
/**
* bean的属性们
* @author wangyu
*/
@Data
public class BeanInfo {
// bean的编码
private String code;
// bean的显示名
private String name;
// bean的属性们
private List<BeanProperty> properties;
}

View File

@ -1,15 +1,14 @@
package com.flyfish.framework.beans.meta;
import com.flyfish.framework.annotations.Property;
import lombok.Data;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.core.annotation.AnnotationUtils;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -24,6 +23,12 @@ public class BeanProperty {
// 属性名称
private String name;
// 属性标题
private String title;
// 描述信息
private String description;
// bean属性的类型js类型
private BeanPropertyType type;
@ -54,12 +59,22 @@ public class BeanProperty {
* @return 结果
*/
public static BeanProperty form(PropertyDescriptor descriptor, Class<?> beanClass) {
// 尝试获取field
Field field = FieldUtils.getDeclaredField(beanClass, descriptor.getName(), true);
// 存在field可以干一些坏事
BeanProperty property = new BeanProperty();
property.setName(descriptor.getName());
property.setType(BeanPropertyType.of(descriptor, beanClass));
if (null != field) {
Property props = AnnotationUtils.findAnnotation(field, Property.class);
if (null != props) {
String parentName = Optional.ofNullable(beanClass.getAnnotation(RestBean.class)).map(RestBean::name).orElse("");
property.setTitle(props.inherited() ? parentName + props.title() : props.title());
property.setDescription(props.description());
}
}
Class<?> clazz = descriptor.getPropertyType();
if (property.getType() == BeanPropertyType.OBJECT) {
Field field = FieldUtils.getDeclaredField(beanClass, property.getName(), true);
// 有子bean注解才处理
if (null != field && field.isAnnotationPresent(SubBean.class)) {
property.setChildren(from(clazz));

View File

@ -1,12 +1,9 @@
package com.flyfish.framework.beans.meta;
import com.flyfish.framework.domain.base.Domain;
import com.flyfish.framework.domain.base.Po;
import lombok.Getter;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.springframework.data.mongodb.core.mapping.DBRef;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
@ -28,12 +25,7 @@ public enum BeanPropertyType {
DATE("Date", Date.class),
ENUM("Enum", Enum.class),
LIST("Array", Collection.class),
DB_REF("Ref", (descriptor, beanClass) -> {
Class<?> clazz = descriptor.getPropertyType();
Field field = FieldUtils.getDeclaredField(beanClass, descriptor.getName());
return null != field && field.isAnnotationPresent(DBRef.class) &&
Domain.class.isAssignableFrom(clazz) && clazz.isAnnotationPresent(RestBean.class);
}),
DB_REF("Ref", Po.class),
OBJECT("Object", Object.class);
private final BiPredicate<PropertyDescriptor, Class<?>> acceptor;

View File

@ -1,616 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>19G2021</string>
<key>CFBundleExecutable</key>
<string>VoodooPS2Keyboard</string>
<key>CFBundleGetInfoString</key>
<string>2.1.7, Copyright Apple Computer, Inc. 2000-2003, RehabMan 2012-2013</string>
<key>CFBundleIdentifier</key>
<string>as.acidanthera.voodoo.driver.PS2Keyboard</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Voodoo PS/2 Keyboard</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>2.1.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>2.1.7</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>10G8</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>18G74</string>
<key>DTSDKName</key>
<string>macosx10.14</string>
<key>DTXcode</key>
<string>1030</string>
<key>DTXcodeBuild</key>
<string>10G8</string>
<key>IOKitPersonalities</key>
<dict>
<key>ApplePS2Keyboard</key>
<dict>
<key>CFBundleIdentifier</key>
<string>as.acidanthera.voodoo.driver.PS2Keyboard</string>
<key>IOClass</key>
<string>ApplePS2Keyboard</string>
<key>IOProviderClass</key>
<string>ApplePS2KeyboardDevice</string>
<key>Platform Profile</key>
<dict>
<key>DELL</key>
<dict>
<key>Dell-Keys</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e005</string>
<string>e006</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 12 items map Fn+fkeys to fkeys</string>
<string>e020=3b</string>
<string>e02e=3c</string>
<string>e030=3d</string>
<string>e022=3e</string>
<string>;Fn+f5 macro</string>
<string>;Fn+f6 macro</string>
<string>;Fn+f7 macro</string>
<string>;Fn+f8 macro</string>
<string>;Fn+f9 macro</string>
<string>;Fn+f10 no code</string>
<string>e005=57</string>
<string>e006=58</string>
<string>;The following 12 items map fkeys to Fn+fkeys</string>
<string>3b=e020</string>
<string>3c=e02e</string>
<string>3d=e030</string>
<string>3e=e022</string>
<string>;Fn+f5 macro</string>
<string>;Fn+f6 macro</string>
<string>;Fn+f7 macro</string>
<string>;Fn+f8 macro</string>
<string>;Fn+f9 macro</string>
<string>;Fn+f10 no code</string>
<string>57=e005</string>
<string>58=e006</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 12 items map Fn+fkeys to Fn+fkeys</string>
<string>e020=e020</string>
<string>e02e=e02e</string>
<string>e030=e030</string>
<string>e022=e022</string>
<string>;Fn+f5 macro</string>
<string>;Fn+f6 macro</string>
<string>;Fn+f7 macro</string>
<string>;Fn+f8 macro</string>
<string>;Fn+f9 macro</string>
<string>;Fn+f10 no code</string>
<string>e005=e005</string>
<string>e006=e006</string>
<string>;The following 12 items map fkeys to fkeys</string>
<string>3b=3b</string>
<string>3c=3c</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>3f=3f</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
<string>57=57</string>
<string>58=58</string>
</array>
</dict>
<key>HSW-LPT</key>
<string>Dell-Keys</string>
<key>SNB-CPT</key>
<dict>
<key>ActionSwipeDown</key>
<string>63 d, 63 u</string>
<key>ActionSwipeUp</key>
<string>61 d, 61 u</string>
<key>Breakless PS2</key>
<array>
<string>e01e;Touchpad Fn+f3 is breakless</string>
<string>e06e;REVIEW: temporary for case that macro inversion does not work...</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>e009=83;Dell Support to Launchpad</string>
<string>e0f1=71;Call brightens up w RKA1 for special mode (was =90)</string>
<string>e0f2=6b;Call brightens down w RKA2 for special mode (was =91)</string>
<string>e06e=70;Map vidmirror key for special mode default is adb90</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>e01e=e037;Map tp disable to Fn+f3</string>
<string>e037=e01e;Prevent PrntScr from triggering tp disable</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 12 items map Fn+fkeys to fkeys</string>
<string>e06e=3b</string>
<string>e008=3c</string>
<string>e01e=3d</string>
<string>e005=3e</string>
<string>e006=3f</string>
<string>e00c=40</string>
<string>;Fn+f7 no dedicated macro</string>
<string>e010=42</string>
<string>e022=43</string>
<string>e019=44</string>
<string>e02e=57</string>
<string>e030=58</string>
<string>;The following 12 items map fkeys to Fn+fkeys</string>
<string>3b=e06e;Map vidmirror key to f1</string>
<string>3c=e0f0;Map radio toggle action from EC query to f2</string>
<string>3d=e037;Map touchpad toggle button to f3</string>
<string>3e=e0f2;Map acpi RKA2 to f4 brightness down</string>
<string>3f=e0f1;Map acpi RKA1 to f5 brightness up</string>
<string>40=e0f3;Map acpi RKA3 to f6 keyboard backlight</string>
<string>;Fn+f7 no macro</string>
<string>42=e010</string>
<string>43=e022</string>
<string>44=e019</string>
<string>57=e02e</string>
<string>58=e030</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 12 items map Fn+fkeys to Fn+fkeys</string>
<string>e06e=e06e;Fn+f1 macro translated</string>
<string>e008=e008;Fn+f2 regular scancode and EC query call q8c</string>
<string>e01e=e037;Fn+f3 regular scancode and EC controls LED</string>
<string>e005=e005;Fn+f4 no ps2scancode and EC query call q81</string>
<string>e006=e006;Fn+f5 no ps2scancode and EC query call q80</string>
<string>e00c=e00c;Fn+f6 no ps2scancode and EC query call q8a</string>
<string>;Fn+f7 no macro just regular f key</string>
<string>e010=e010; Fn+f8 regular scancode</string>
<string>e022=e022; Fn+f9 regular scancode</string>
<string>e019=e019;Fn+f10 regular scancode</string>
<string>e02e=e02e;Fn+f11 regular scancode</string>
<string>e030=e030;Fn+f12 regular scancode</string>
<string>;Fn+f13 is mute dedicated button that always produces e020 regardless of Fn</string>
<string>;The following 12 items map fkeys to fkeys</string>
<string>3b=3b</string>
<string>3c=3c</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>3f=3f</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
<string>57=57</string>
<string>58=58</string>
</array>
<key>Macro Inversion</key>
<array>
<string>;This section maps ps2 codes (packet format) received quickly (macros) into fake ps2 codes (packet format)</string>
<string>;Fn+F1</string>
<data>
//8CbgAAAAACWwEZ
</data>
<data>
//8C7gAAAAAC2wGZ
</data>
<data>
//8C7gAAAAABmQLb
</data>
</array>
<key>MaximumMacroTime</key>
<integer>35000000</integer>
<key>Note-Author</key>
<string>TimeWalker aka TimeWalker75a</string>
<key>Note-Comment</key>
<string>Keyboard Profile for DELL SandyBridge SecureCore Tiano based laptops (Vostro 3450 &amp; 3750, Inspiron N4110, XPS L502x &amp; L702x &amp; L511z)</string>
</dict>
<key>WN09</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e01b</string>
<string>e008</string>
<string>e01e</string>
<string>e005</string>
<string>e06e</string>
<string>e006</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>e01b=70</string>
<string>e06e=83</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>56=2b</string>
<string>29=56</string>
<string>2b=29</string>
<string>e01e=e037</string>
<string>e037=e01e</string>
</array>
</dict>
<key>WN09a</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e01b</string>
<string>e008</string>
<string>e01e</string>
<string>e005</string>
<string>e06e</string>
<string>e006</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>e01b=70</string>
<string>e06e=83</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>e01e=e037</string>
<string>e037=e01e</string>
</array>
</dict>
</dict>
<key>Default</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>;Items must be strings in the form of breaklessscan (in hex)</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>;Items must be strings in the form of scanfrom=adbto (in hex)</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>;Items must be strings in the form of scanfrom=scanto (in hex)</string>
<string>e027=0;disable discrete fnkeys toggle</string>
<string>e028=0;disable discrete trackpad toggle</string>
</array>
<key>HIDF12EjectDelay</key>
<integer>250</integer>
<key>LogScanCodes</key>
<integer>0</integer>
<key>Make Application key into Apple Fn key</key>
<false/>
<key>Make Application key into right windows</key>
<true/>
<key>Make right modifier keys into Hangul and Hanja</key>
<false/>
<key>SleepPressTime</key>
<integer>0</integer>
<key>Swap capslock and left control</key>
<false/>
<key>Swap command and option</key>
<true/>
<key>Use ISO layout keyboard</key>
<false/>
<key>alt_handler_id</key>
<integer>3</integer>
</dict>
<key>HPQOEM</key>
<dict>
<key>1411</key>
<string>ProBook-102;ProBook 4520s</string>
<key>1619</key>
<string>ProBook-87;ProBook 6560b</string>
<key>161C</key>
<string>ProBook-87;ProBook 8460p</string>
<key>164F</key>
<string>ProBook-87;ProBook 5330m</string>
<key>167C</key>
<string>ProBook-102;ProBook 4530s</string>
<key>167E</key>
<string>ProBook-102;ProBook 4330s</string>
<key>1680</key>
<string>ProBook-102;ProBook 4230s</string>
<key>179B</key>
<string>ProBook-87;ProBook 6470b</string>
<key>179C</key>
<string>ProBook-87;ProBook 6470b</string>
<key>17A9</key>
<string>ProBook-87;ProBook 8570b</string>
<key>17F0</key>
<string>ProBook-102;ProBook 4340s</string>
<key>17F3</key>
<string>ProBook-102;ProBook 4440s</string>
<key>17F6</key>
<string>ProBook-102;ProBook 4540s</string>
<key>1942</key>
<string>ProBook-87;ProBook 450s G1</string>
<key>1949</key>
<string>ProBook-87;ProBook 450s G1</string>
<key>1962</key>
<string>Haswell-Envy;HP Envy 15-j063cl</string>
<key>1963</key>
<string>Haswell-Envy;HP Envy 15-j063cl</string>
<key>1965</key>
<string>Haswell-Envy;HP Envy 17t-j100</string>
<key>1966</key>
<string>Haswell-Envy;HP Envy 17t-j000</string>
<key>198F</key>
<string>ProBook-87;ProBook 450s G0</string>
<key>Haswell-Envy</key>
<dict>
<key>Custom ADB Map</key>
<array>
<string>e019=42;next</string>
<string>e010=4d;previous</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>e045=e037</string>
<string>e0ab=0;bogus Fn+F2/F3</string>
</array>
</dict>
<key>ProBook-102</key>
<dict>
<key>Custom PS2 Map</key>
<array>
<string>e005=0</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 12 items map Fn+fkeys to fkeys</string>
<string>e05f=3b</string>
<string>e012=3c</string>
<string>e017=3d</string>
<string>e06e=3e</string>
<string>e00a=3f</string>
<string>e009=40</string>
<string>e020=41</string>
<string>e02e=42</string>
<string>e030=43</string>
<string>e010=44</string>
<string>e022=57</string>
<string>e019=58</string>
<string>;The following 12 items map fkeys to Fn+fkeys</string>
<string>3b=e05f</string>
<string>3c=e012</string>
<string>3d=e017</string>
<string>3e=e06e</string>
<string>3f=e00a</string>
<string>40=e009</string>
<string>41=e020</string>
<string>42=e02e</string>
<string>43=e030</string>
<string>44=e010</string>
<string>57=e022</string>
<string>58=e019</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 12 items map Fn+fkeys to Fn+fkeys</string>
<string>e05f=e05f</string>
<string>e012=e012</string>
<string>e017=e017</string>
<string>e06e=e06e</string>
<string>e00a=e00a</string>
<string>e009=e009</string>
<string>e020=e020</string>
<string>e02e=e02e</string>
<string>e030=e030</string>
<string>e010=e010</string>
<string>e022=e022</string>
<string>e019=e019</string>
<string>;The following 12 items map fkeys to fkeys</string>
<string>3b=3b</string>
<string>3c=3c</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>3f=3f</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
<string>57=57</string>
<string>58=58</string>
</array>
<key>SleepPressTime</key>
<integer>3000</integer>
</dict>
<key>ProBook-87</key>
<dict>
<key>Custom ADB Map</key>
<array>
<string>46=4d;scroll =&gt; Previous-track</string>
<string>e045=34;pause =&gt; Play-Pause</string>
<string>e052=42;insert =&gt; Next-track</string>
<string>e046=92;break =&gt; Eject</string>
</array>
<key>Custom PS2 Map</key>
<array>
<string>e005=0</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 8 items map Fn+fkeys to fkeys</string>
<string>e05f=3d</string>
<string>e06e=3e</string>
<string>e02e=40</string>
<string>e030=41</string>
<string>e009=42</string>
<string>e012=43</string>
<string>e017=44</string>
<string>e033=57</string>
<string>;The following 8 items map fkeys to Fn+fkeys</string>
<string>3d=e05f</string>
<string>3e=e06e</string>
<string>40=e02e</string>
<string>41=e030</string>
<string>42=e037</string>
<string>43=e012</string>
<string>44=e017</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 8 items map Fn+fkeys to Fn+fkeys</string>
<string>e05f=e05f</string>
<string>e06e=e06e</string>
<string>e02e=e02e</string>
<string>e030=e030</string>
<string>e009=e009</string>
<string>e012=e012</string>
<string>e017=e017</string>
<string>e033=e033</string>
<string>;The following 8 items map fkeys to fkeys</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
</array>
<key>SleepPressTime</key>
<integer>3000</integer>
</dict>
</dict>
<key>Intel</key>
<dict>
<key>CALPELLA</key>
<string>SamsungKeys</string>
<key>SamsungKeys</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e003</string>
<string>e002</string>
<string>e004</string>
<string>e020</string>
<string>;e031</string>
<string>e033</string>
<string>e006</string>
<string>e077</string>
<string>e079</string>
<string>e008</string>
<string>e009</string>
</array>
<key>Custom ADB Map</key>
<array>
<string>e002=70</string>
<string>e006=80</string>
<string>e008=71 (was =90)</string>
<string>e009=6b (was =91)</string>
</array>
<key>Function Keys Special</key>
<array>
<string>;The following 12 items map Fn+fkeys to fkeys</string>
<string>;fn+f1 no code</string>
<string>e003=3c</string>
<string>;fn+f3 weird code</string>
<string>e002=3e</string>
<string>e004=3f</string>
<string>e020=40</string>
<string>e031=41</string>
<string>e033=42</string>
<string>e006=43</string>
<string>;fn+f10 weird code</string>
<string>;fn+f11 no code</string>
<string>;fn+f12 scrolllock</string>
<string>;The following 12 items map fkeys to Fn+fkeys</string>
<string>;fn+f1 no code</string>
<string>3c=e003</string>
<string>;fn+f3 weird code</string>
<string>3e=e002</string>
<string>3f=e004</string>
<string>40=e020</string>
<string>41=e031</string>
<string>42=e033</string>
<string>43=e006</string>
<string>;fn+f10 weird code</string>
<string>;fn+f11 no code</string>
<string>;fn+f12 scrolllock</string>
</array>
<key>Function Keys Standard</key>
<array>
<string>;The following 12 items map Fn+fkeys to Fn+fkeys</string>
<string>;fn+f1 no code</string>
<string>e003=e003</string>
<string>;fn+f3 weird code</string>
<string>e002=e002</string>
<string>e004=e004</string>
<string>e020=e020</string>
<string>e031=e031</string>
<string>e033=e033</string>
<string>e006=e006</string>
<string>;fn+f10 weird code</string>
<string>;fn+f11 no code</string>
<string>;fn+f12 scrolllock</string>
<string>;The following 12 items map fkeys to fkeys</string>
<string>3b=3b</string>
<string>3c=3c</string>
<string>3d=3d</string>
<string>3e=3e</string>
<string>3f=3f</string>
<string>40=40</string>
<string>41=41</string>
<string>42=42</string>
<string>43=43</string>
<string>44=44</string>
<string>57=57</string>
<string>58=58</string>
</array>
</dict>
</dict>
<key>SECCSD</key>
<dict>
<key>LH43STAR</key>
<string>SamsungKeys</string>
<key>SamsungKeys</key>
<dict>
<key>Breakless PS2</key>
<array>
<string>e020</string>
<string>e02e</string>
<string>e030</string>
</array>
</dict>
</dict>
</dict>
</dict>
</dict>
<key>OSBundleLibraries</key>
<dict>
<key>as.acidanthera.voodoo.driver.PS2Controller</key>
<string>2.1.7</string>
<key>com.apple.iokit.IOHIDFamily</key>
<string>1.0.0b1</string>
<key>com.apple.kpi.bsd</key>
<string>8.0.0</string>
<key>com.apple.kpi.iokit</key>
<string>8.0.0</string>
<key>com.apple.kpi.libkern</key>
<string>8.0.0</string>
<key>com.apple.kpi.mach</key>
<string>8.0.0</string>
<key>com.apple.kpi.unsupported</key>
<string>8.0.0</string>
</dict>
<key>OSBundleRequired</key>
<string>Console</string>
</dict>
</plist>

View File

@ -10,7 +10,9 @@ import org.springframework.web.reactive.result.method.annotation.RequestMappingH
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 动态Bean生成解析器
@ -22,6 +24,7 @@ import java.util.List;
public class DynamicRestBeanResolver implements InitializingBean, DisposableBean {
private static final List<String> controllers = new ArrayList<>();
private static final Set<Class<?>> classes = new HashSet<>();
private final Method handlerRegister;
private final RequestMappingHandlerMapping mapping;
@ -34,6 +37,14 @@ public class DynamicRestBeanResolver implements InitializingBean, DisposableBean
controllers.add(controller);
}
public static void setClasses(Set<Class<?>> classSet) {
classes.addAll(classSet);
}
public Set<Class<?>> getClasses() {
return classes;
}
@Override
public void destroy() throws Exception {
log.info("正在销毁rest自动配置器");

View File

@ -1,6 +1,7 @@
package com.flyfish.framework.config;
import com.flyfish.framework.beans.annotations.EnableRestBeanDetect;
import com.flyfish.framework.beans.enums.RestBeanCandidate;
import com.flyfish.framework.beans.meta.RestBean;
import com.flyfish.framework.beans.repository.CustomRepositoryRegistrar;
import com.flyfish.framework.beans.resolver.DynamicRestBeanResolver;
@ -31,6 +32,8 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.flyfish.framework.beans.enums.RestBeanCandidate.*;
/**
* rest bean的自动配置
*
@ -40,10 +43,10 @@ import java.util.stream.Stream;
public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware {
// 预编译模板
private final Map<String, Function<JavaSource, String>> templates = Stream.of("Repository", "Service", "Controller")
.collect(Collectors.toMap(key -> key, filename -> TemplateCompiler.compile("/templates/" + filename + ".tpl")));
private final Map<RestBeanCandidate, Function<JavaSource, String>> templates = Arrays.stream(values())
.collect(Collectors.toMap(key -> key, key -> TemplateCompiler.compile("/templates/" + key.getName() + ".tpl")));
// 存放父类值的映射
private final Map<String, Function<RestBean, Class<?>>> superClasses;
private final Map<RestBeanCandidate, Function<RestBean, Class<?>>> superClasses;
// 编译器引用
private final DynamicJavaCompiler compiler = DynamicJavaCompiler.delegate();
@ -54,9 +57,9 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
public RestBeanAutoConfigure() {
superClasses = new HashMap<>();
superClasses.put("Controller", RestBean::controllerClass);
superClasses.put("Repository", RestBean::repoClass);
superClasses.put("Service", RestBean::serviceClass);
superClasses.put(CONTROLLER, RestBean::controllerClass);
superClasses.put(REPOSITORY, RestBean::repoClass);
superClasses.put(SERVICE, RestBean::serviceClass);
}
/**
@ -76,9 +79,12 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
CustomRepositoryRegistrar repositoryRegistrar = new CustomRepositoryRegistrar(metadata, resourceLoader,
environment, registry, beanNameGenerator);
// 准备注册的repo
Map<String, List<Class<?>>> loadedClasses = new ConcurrentHashMap<>();
Map<RestBeanCandidate, List<Class<?>>> loadedClasses = new ConcurrentHashMap<>();
// 获取被注解的类开始编译
reflections.getTypesAnnotatedWith(RestBean.class).parallelStream().forEach(clazz -> {
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(RestBean.class);
DynamicRestBeanResolver.setClasses(classes);
// 并发编译快速接入
classes.parallelStream().forEach(clazz -> {
RestBean restBean = clazz.getDeclaredAnnotation(RestBean.class);
if (null != restBean) {
// 创建java source信息
@ -88,13 +94,13 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
.setPackageName(basePackages.stream().findFirst().orElse("com.flyfish.project"))
.setUri(makePath(clazz.getSimpleName(), restBean.value()));
// 分别生成实现类从repo到controller
templates.forEach((key, template) -> {
source.setSuperClass(superClasses.get(key).apply(restBean).getCanonicalName());
source.setClassName(clazz.getSimpleName() + key);
templates.forEach((type, template) -> {
source.setSuperClass(superClasses.get(type).apply(restBean).getCanonicalName());
source.setClassName(clazz.getSimpleName() + type.getName());
try {
log.info("尝试注册{}", source.getClassName());
Class<?> compiled = compiler.compile(source.getClassName() + ".java", template.apply(source));
loadedClasses.computeIfAbsent(key, k -> new ArrayList<>()).add(compiled);
loadedClasses.computeIfAbsent(type, k -> new ArrayList<>()).add(compiled);
// IllegalAccessException | InvocationTargetException
} catch (ClassNotFoundException | IOException e) {
log.error("注册{}时发生异常!", source.getClassName(), e);
@ -103,11 +109,11 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
}
});
// 从repo开始注册bean
loadedClasses.getOrDefault("Repository", Collections.emptyList())
loadedClasses.getOrDefault(REPOSITORY, Collections.emptyList())
.forEach(repositoryRegistrar::register);
loadedClasses.getOrDefault("Service", Collections.emptyList())
loadedClasses.getOrDefault(SERVICE, Collections.emptyList())
.forEach(clazz -> registerBean(clazz, registry));
loadedClasses.getOrDefault("Controller", Collections.emptyList())
loadedClasses.getOrDefault(CONTROLLER, Collections.emptyList())
.forEach(clazz -> registerBean(clazz, registry));
log.info("结束注册rest bean...");
}

View File

@ -64,7 +64,10 @@ public class EnumController {
* @return 结果
*/
@GetMapping
public Result<List<EnumValue>> values(@PathVariable("code") String code) {
public Result<?> values(@PathVariable("code") String code) {
if ("all".equals(code)) {
return Result.ok(values);
}
return Result.ok(values.getOrDefault(code, Collections.emptyList()));
}
}
}

View File

@ -22,11 +22,11 @@ public class JsonAuthenticationFailureHandler implements ServerAuthenticationFai
private final String defaultMessage = "用户登录异常!";
// 数据块工厂
private final DataBufferTransformer<Result> dataBufferTransformer;
private final DataBufferTransformer<Result<?>> dataBufferTransformer;
private Map<Class<? extends AuthenticationException>, String> descriptionMap = new HashMap<>();
private final Map<Class<? extends AuthenticationException>, String> descriptionMap = new HashMap<>();
public JsonAuthenticationFailureHandler(DataBufferTransformer<Result> dataBufferTransformer) {
public JsonAuthenticationFailureHandler(DataBufferTransformer<Result<?>> dataBufferTransformer) {
this.dataBufferTransformer = dataBufferTransformer;
descriptionMap.put(BadCredentialsException.class, "用户名密码不正确!");
// todo 剩下的都在userDetailsService

View File

@ -21,7 +21,7 @@ import reactor.core.publisher.Mono;
public class JsonAuthenticationSuccessHandler implements ServerAuthenticationSuccessHandler {
// 数据块工厂
private final DataBufferTransformer<Result> dataBufferTransformer;
private final DataBufferTransformer<Result<?>> dataBufferTransformer;
/**
* 登录成功后要返回用户的基本信息节省带宽

View File

@ -20,7 +20,7 @@ import reactor.core.publisher.Mono;
public class JsonLogoutSuccessHandler implements ServerLogoutSuccessHandler {
// 数据块工厂
private final DataBufferTransformer<Result> dataBufferTransformer;
private final DataBufferTransformer<Result<?>> dataBufferTransformer;
private final TokenProvider tokenProvider;

View File

@ -12,16 +12,16 @@ import java.nio.charset.Charset;
*
* @author wangyu
*/
public class ResultDataTransformer implements DataBufferTransformer<Result> {
public class ResultDataTransformer implements DataBufferTransformer<Result<?>> {
private DataBufferFactory factory;
private final DataBufferFactory factory;
public ResultDataTransformer() {
this.factory = SharedDataBufferFactory.getDefaultFactory();
}
@Override
public DataBuffer transform(Result source) {
public DataBuffer transform(Result<?> source) {
return JacksonUtil.toJson(source)
.map(result -> result.getBytes(Charset.defaultCharset()))
.map(factory::wrap)