commit ad77be09416dd0a5ddcbc8a2ad7483aaa8e2641f Author: zhouping Date: Thu Jan 17 17:02:31 2019 +0800 demo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d91e065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.iml +.idea/ +lib/report/*.jar +.DS_Store +.classpath \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..ab586ec --- /dev/null +++ b/build.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/report/.gitkeep b/lib/report/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..d27e5dc --- /dev/null +++ b/plugin.xml @@ -0,0 +1,22 @@ + + + com.fr.plugin.passport + + yes + 1.0 + 10.0~ + 2019-01-15 + author + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e6967da --- /dev/null +++ b/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + + com.fr.plugin + starter + 10.0 + + jar + demo-custom-passport + + + ${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.passport-1.0/classes + + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/decision/passport/CustomPassport.java b/src/main/java/com/fr/plugin/decision/passport/CustomPassport.java new file mode 100644 index 0000000..800f6c5 --- /dev/null +++ b/src/main/java/com/fr/plugin/decision/passport/CustomPassport.java @@ -0,0 +1,76 @@ +package com.fr.plugin.decision.passport; + +import com.fr.config.Identifier; +import com.fr.config.holder.Conf; +import com.fr.config.holder.factory.Holders; +import com.fr.decision.authorize.impl.AbstractPassport; +import com.fr.general.ComparatorUtils; +import com.fr.stable.AssistUtils; +import com.fr.stable.StringUtils; + +/** + * Created by zhouping on 2019/1/16. + */ +public class CustomPassport extends AbstractPassport { + private static final long serialVersionUID = 6518713050327446011L; + + @Identifier("extraAttr1") + private Conf extraAttr1 = Holders.simple(StringUtils.EMPTY); + + @Identifier("extraAttr2") + private Conf extraAttr2 = Holders.simple(StringUtils.EMPTY); + + @Identifier("extraAttr3") + private Conf extraAttr3 = Holders.simple(StringUtils.EMPTY); + + public CustomPassport() { + } + + @Override + public String markType() { + return CustomPassportProvider.PASSPORT_TYPE; + } + + @Override + public boolean equals(Object o) { + return o instanceof CustomPassport + && ComparatorUtils.equals(extraAttr1.get(), ((CustomPassport) o).getExtraAttr1()) + && ComparatorUtils.equals(extraAttr2.get(), ((CustomPassport) o).getExtraAttr2()) + && ComparatorUtils.equals(extraAttr3.get(), ((CustomPassport) o).getExtraAttr3()); + } + + @Override + public int hashCode() { + return AssistUtils.hashCode(extraAttr1.get(), extraAttr2.get(), extraAttr3.get()); + } + + @Override + public boolean checkTicket(String username, String inputPassword, String savedPassword, String hashPassword) { + System.out.println("CustomPassport checkTicket!"); + return true; + } + + public String getExtraAttr1() { + return extraAttr1.get(); + } + + public void setExtraAttr1(String extraAttr1) { + this.extraAttr1.set(extraAttr1); + } + + public String getExtraAttr2() { + return extraAttr2.get(); + } + + public void setExtraAttr2(String extraAttr2) { + this.extraAttr2.set(extraAttr2); + } + + public String getExtraAttr3() { + return extraAttr3.get(); + } + + public void setExtraAttr3(String extraAttr3) { + this.extraAttr3.set(extraAttr3); + } +} diff --git a/src/main/java/com/fr/plugin/decision/passport/CustomPassportBean.java b/src/main/java/com/fr/plugin/decision/passport/CustomPassportBean.java new file mode 100644 index 0000000..250d64e --- /dev/null +++ b/src/main/java/com/fr/plugin/decision/passport/CustomPassportBean.java @@ -0,0 +1,66 @@ +package com.fr.plugin.decision.passport; + +import com.fr.decision.authorize.Passport; +import com.fr.decision.webservice.bean.authentication.PassportBean; +import com.fr.third.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * Created by zhouping on 2019/1/16. + */ +@JsonSubTypes.Type(value = CustomPassportBean.class, name = "CustomPassportBean") +public class CustomPassportBean extends PassportBean { + private static final long serialVersionUID = -3233988427322347510L; + + //自定义属性1 + private String extraAttr1; + //自定义属性2 + private String extraAttr2; + //自定义属性3 + private String extraAttr3; + + @Override + public String markType() { + return CustomPassportProvider.PASSPORT_TYPE; + } + + @Override + public PassportBean createPassportBean(CustomPassport passport) { + this.setExtraAttr1(passport.getExtraAttr1()); + this.setExtraAttr2(passport.getExtraAttr2()); + this.setExtraAttr3(passport.getExtraAttr3()); + return this; + } + + @Override + public Passport createPassport() { + CustomPassport passport = new CustomPassport(); + passport.setExtraAttr1(getExtraAttr1()); + passport.setExtraAttr2(getExtraAttr2()); + passport.setExtraAttr3(getExtraAttr3()); + return passport; + } + + public String getExtraAttr1() { + return extraAttr1; + } + + public void setExtraAttr1(String extraAttr1) { + this.extraAttr1 = extraAttr1; + } + + public String getExtraAttr2() { + return extraAttr2; + } + + public void setExtraAttr2(String extraAttr2) { + this.extraAttr2 = extraAttr2; + } + + public String getExtraAttr3() { + return extraAttr3; + } + + public void setExtraAttr3(String extraAttr3) { + this.extraAttr3 = extraAttr3; + } +} diff --git a/src/main/java/com/fr/plugin/decision/passport/CustomPassportProvider.java b/src/main/java/com/fr/plugin/decision/passport/CustomPassportProvider.java new file mode 100644 index 0000000..31d08e7 --- /dev/null +++ b/src/main/java/com/fr/plugin/decision/passport/CustomPassportProvider.java @@ -0,0 +1,29 @@ +package com.fr.plugin.decision.passport; + +import com.fr.decision.authorize.Passport; +import com.fr.decision.fun.impl.AbstractPassportProvider; +import com.fr.decision.webservice.bean.authentication.PassportBean; +import com.fr.plugin.transform.FunctionRecorder; + +/** + * Created by zhouping on 2018/12/14. + */ +@FunctionRecorder +public class CustomPassportProvider extends AbstractPassportProvider { + public static final String PASSPORT_TYPE = "custom"; + + @Override + public String passportType() { + return PASSPORT_TYPE; + } + + @Override + public Class classForPassportBean() { + return CustomPassportBean.class; + } + + @Override + public Class classForPassportConfig() { + return CustomPassport.class; + } +} diff --git a/src/main/java/com/fr/plugin/decision/passport/CustomWebResourceProvider.java b/src/main/java/com/fr/plugin/decision/passport/CustomWebResourceProvider.java new file mode 100644 index 0000000..b295651 --- /dev/null +++ b/src/main/java/com/fr/plugin/decision/passport/CustomWebResourceProvider.java @@ -0,0 +1,33 @@ +package com.fr.plugin.decision.passport; + +import com.fr.decision.fun.impl.AbstractWebResourceProvider; +import com.fr.decision.web.MainComponent; +import com.fr.web.struct.Atom; +import com.fr.web.struct.Component; +import com.fr.web.struct.browser.RequestClient; +import com.fr.web.struct.category.ScriptPath; +import com.fr.web.struct.category.StylePath; + +/** + * Created by zhouping on 2019/1/16. + */ +public class CustomWebResourceProvider extends AbstractWebResourceProvider { + @Override + public Atom attach() { + return MainComponent.KEY; + } + + @Override + public Atom client() { + return new Component() { + @Override + public ScriptPath script(RequestClient requestClient) { + return ScriptPath.build("/com/fr/plugin/decision/passport/js/demo.js"); + } + @Override + public StylePath style(RequestClient requestClient) { + return StylePath.EMPTY; + } + }; + } +} diff --git a/src/main/java/com/fr/plugin/decision/passport/PluginLocaleFinderBridge.java b/src/main/java/com/fr/plugin/decision/passport/PluginLocaleFinderBridge.java new file mode 100644 index 0000000..061a8ad --- /dev/null +++ b/src/main/java/com/fr/plugin/decision/passport/PluginLocaleFinderBridge.java @@ -0,0 +1,10 @@ +package com.fr.plugin.decision.passport; + +import com.fr.stable.fun.impl.AbstractLocaleFinder; + +public class PluginLocaleFinderBridge extends AbstractLocaleFinder { + @Override + public String find() { + return "com/fr/plugin/decision/passport/locale/passport"; + } +} diff --git a/src/main/resources/com/fr/plugin/decision/passport/js/demo.js b/src/main/resources/com/fr/plugin/decision/passport/js/demo.js new file mode 100644 index 0000000..5c03920 --- /dev/null +++ b/src/main/resources/com/fr/plugin/decision/passport/js/demo.js @@ -0,0 +1,135 @@ +BI.config("dec.user.setting.authentications", function (items) { + items.push({ + value: "custom", // value 值 + text: "自定义认证方式", // 认证方式名,需国际化 + "@class": "com.fr.plugin.decision.passport.CustomPassportBean", //对应后台认证对象的完整类名,必选属性 + component: { + type: "dec.plugin.custom_authentication" + } + }); + return items; +}); +// 自定义的component组件接受configs props,需要实现getValue方法读取配置 +var WIDTH = 125; + +var Demo = BI.inherit(BI.Widget, { + + props: { + baseCls: "", + configs: { + extraAttr1:"", + extraAttr2:"", + extraAttr3:"1" + } + }, + + render: function () { + var self = this, o = this.options; + return { + type: "bi.vertical", + bgap: 15, + items: [ + { + type: "bi.vertical_adapt", + items: [ + { + type: "bi.layout", + width: WIDTH + }, { + type: "bi.label", + textAlign: "left", + cls: "dec-font-weight-bold", + text: "extraAttr1:", + width: 100 + }, { + type: "bi.editor", + ref: function (_ref) { + self.extraAttr1 = _ref; + }, + width: 400, + height: 24, + watermark: "", + value: o.configs.extraAttr1 + } + ] + }, { + type: "bi.htape", + height: 300, + items: [ + { + type: "bi.layout", + width: WIDTH + }, { + type: "bi.vertical", + items: [ + { + type: "bi.label", + textAlign: "left", + cls: "dec-font-weight-bold", + text: "extraAttr2:" + } + ], + width: 100 + }, { + type: "bi.textarea_editor", + cls: "bi-border", + ref: function (_ref) { + self.extraAttr2 = _ref; + }, + width: 400, + height: 300, + watermark: "", + value: o.configs.extraAttr2 + } + ] + }, { + type: "bi.htape", + height: 300, + items: [ + { + type: "bi.layout", + width: WIDTH + }, { + type: "bi.vertical", + items: [ + { + type: "bi.label", + textAlign: "left", + cls: "dec-font-weight-bold", + text: "extraAttr3:" + } + ], + width: 100 + }, { + type: "bi.text_value_combo", + ref: function (_ref) { + self.extraAttr3 = _ref; + }, + items: [ + { + text: "1", + value: "1" + }, { + text: "2", + value: "2" + } + ], + width: 400, + value: o.configs.extraAttr3 + } + ] + } + ] + + }; + }, + + getValue: function () { + return { + extraAttr1: this.extraAttr1.getValue(), + extraAttr2: this.extraAttr2.getValue(), + extraAttr3: this.extraAttr3.getValue()[0] + }; + } +}); +BI.shortcut("dec.plugin.custom_authentication", Demo); \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/decision/passport/locale/passport.properties b/src/main/resources/com/fr/plugin/decision/passport/locale/passport.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/com/fr/plugin/decision/passport/locale/passport_zh_CN.properties b/src/main/resources/com/fr/plugin/decision/passport/locale/passport_zh_CN.properties new file mode 100644 index 0000000..e69de29