Browse Source

demo

master
zhouping 6 years ago
commit
ad77be0941
  1. 5
      .gitignore
  2. 130
      build.xml
  3. 0
      lib/report/.gitkeep
  4. 22
      plugin.xml
  5. 18
      pom.xml
  6. 76
      src/main/java/com/fr/plugin/decision/passport/CustomPassport.java
  7. 66
      src/main/java/com/fr/plugin/decision/passport/CustomPassportBean.java
  8. 29
      src/main/java/com/fr/plugin/decision/passport/CustomPassportProvider.java
  9. 33
      src/main/java/com/fr/plugin/decision/passport/CustomWebResourceProvider.java
  10. 10
      src/main/java/com/fr/plugin/decision/passport/PluginLocaleFinderBridge.java
  11. 135
      src/main/resources/com/fr/plugin/decision/passport/js/demo.js
  12. 0
      src/main/resources/com/fr/plugin/decision/passport/locale/passport.properties
  13. 0
      src/main/resources/com/fr/plugin/decision/passport/locale/passport_zh_CN.properties

5
.gitignore vendored

@ -0,0 +1,5 @@
*.iml
.idea/
lib/report/*.jar
.DS_Store
.classpath

130
build.xml

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="plugin">
<!-- JDK路径,根据自己机器上实际位置修改-->
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8/Contents/Home"/>
<property name="libs" value="${basedir}/lib"/>
<property name="publicLibs" value=""/>
<property name="reportLibs" value="${basedir}/../webroot/WEB-INF/lib"/>
<property name="destLoc" value="."/>
<property name="classes" value="classes"/>
<xmlproperty file="${basedir}/plugin.xml"/>
<property name="current-version" value="${plugin.version}"/>
<!-- 插件版本-->
<property name="plugin-version" value="${current-version}"/>
<!-- 插件名字-->
<property name="plugin-name" value="custom-passport"/>
<property name="plugin-jar" value="fr-plugin-${plugin-name}-${plugin-version}.jar"/>
<target name="prepare">
<delete dir="${classes}"/>
<delete dir="fr-plugin-${plugin-name}-${plugin-version}"/>
<xmlproperty file="${basedir}/plugin.xml"/>
<delete dir="${destLoc}/${plugin.name}"/>
</target>
<path id="compile.classpath">
<fileset dir="${libs}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${publicLibs}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${reportLibs}">
<include name="**/*.jar"/>
</fileset>
</path>
<patternset id="resources4Jar">
<exclude name="**/.settings/**"/>
<exclude name=".classpath"/>
<exclude name=".project"/>
<exclude name="**/*.java"/>
<exclude name="**/*.db"/>
<exclude name="**/*.g"/>
<exclude name="**/package.html"/>
</patternset>
<target name="copy_resources">
<echo message="从${resources_from}拷贝图片,JS,CSS等资源文件"/>
<delete dir="tmp"/>
<copy todir="tmp">
<fileset dir="${resources_from}/src/main/resources">
<patternset refid="resources4Jar"/>
</fileset>
</copy>
<copy todir="${classes}">
<fileset dir="tmp"/>
</copy>
<delete dir="tmp"/>
</target>
<target name="compile_javas">
<echo message="编译${compile_files}下的Java文件"/>
<javac destdir="${classes}" debug="false" optimize="on" source="${source_jdk_version}"
target="${target_jdk_version}"
fork="true" memoryMaximumSize="512m" listfiles="false" srcdir="${basedir}"
executable="${compile_jdk_version}/bin/javac">
<src path="${basedir}/src/main/java"/>
<exclude name="**/.svn/**"/>
<compilerarg line="-encoding UTF8 "/>
<classpath refid="compile.classpath"/>
</javac>
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask">
<classpath refid="compile.classpath"/>
</taskdef>
<pretreatment baseDir="${basedir}"/>
</target>
<target name="jar_classes">
<echo message="打Jar包:${jar_name}"/>
<delete file="${basedir}/${jar_name}"/>
<jar jarfile="${basedir}/${jar_name}">
<fileset dir="${classes}">
</fileset>
</jar>
</target>
<target name="super_jar" depends="prepare">
<antcall target="copy_resources">
<param name="resources_from" value="${basedir}"/>
</antcall>
<antcall target="compile_javas">
<param name="source_jdk_version" value="1.6"/>
<param name="target_jdk_version" value="1.6"/>
<param name="compile_jdk_version" value="${jdk.home}"/>
<param name="compile_files" value="${basedir}/src"/>
</antcall>
<echo message="compile plugin success!"/>
<antcall target="jar_classes">
<param name="jar_name" value="${plugin-jar}"/>
</antcall>
<delete dir="${classes}"/>
</target>
<target name="jar" depends="super_jar">
<antcall target="zip"/>
</target>
<target name="zip">
<property name="plugin-folder" value="fr-plugin-${plugin-name}-${plugin-version}"/>
<echo message="----------zip files----------"/>
<mkdir dir="${plugin-folder}"/>
<copy todir="${plugin-folder}">
<fileset dir=".">
<include name="${plugin-jar}"/>
<include name="plugin.xml"/>
</fileset>
<fileset dir="${libs}">
<include name="*.jar"/>
<include name="*.dll"/>
</fileset>
</copy>
<zip destfile="${basedir}/${plugin-folder}.zip" basedir=".">
<include name="${plugin-folder}/*.jar"/>
<include name="${plugin-folder}/*.dll"/>
<include name="${plugin-folder}/plugin.xml"/>
</zip>
<move file="${plugin-folder}.zip" todir="${destLoc}/install"/>
</target>
</project>

0
lib/report/.gitkeep

22
plugin.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fr.plugin.passport</id>
<name><![CDATA[自定义认证方式示例]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>10.0~</env-version>
<jartime>2019-01-15</jartime>
<vendor>author</vendor>
<description><![CDATA[自定义认证方式示例]]></description>
<change-notes><![CDATA[
]]></change-notes>
<extra-core>
<LocaleFinder class="com.fr.plugin.decision.passport.PluginLocaleFinderBridge"/>
</extra-core>
<extra-decision>
<PassportProvider class="com.fr.plugin.decision.passport.CustomPassportProvider"/>
<WebResourceProvider class="com.fr.plugin.decision.passport.CustomWebResourceProvider"/>
</extra-decision>
<function-recorder class="com.fr.plugin.decision.passport.CustomPassportProvider"/>
</plugin>

18
pom.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fr.plugin</groupId>
<artifactId>starter</artifactId>
<version>10.0</version>
</parent>
<packaging>jar</packaging>
<artifactId>demo-custom-passport</artifactId>
<build>
<!---如果要更改调试插件,改这里的配置就可以了-->
<outputDirectory>${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.passport-1.0/classes</outputDirectory>
</build>
</project>

76
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<String> extraAttr1 = Holders.simple(StringUtils.EMPTY);
@Identifier("extraAttr2")
private Conf<String> extraAttr2 = Holders.simple(StringUtils.EMPTY);
@Identifier("extraAttr3")
private Conf<String> 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);
}
}

66
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<CustomPassport> {
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<CustomPassport> 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;
}
}

29
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<? extends PassportBean> classForPassportBean() {
return CustomPassportBean.class;
}
@Override
public Class<? extends Passport> classForPassportConfig() {
return CustomPassport.class;
}
}

33
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;
}
};
}
}

10
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";
}
}

135
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);

0
src/main/resources/com/fr/plugin/decision/passport/locale/passport.properties

0
src/main/resources/com/fr/plugin/decision/passport/locale/passport_zh_CN.properties

Loading…
Cancel
Save