modify auth to chaincode

parent e0ae72a9
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="de83b181-e854-4be8-81f5-73a2fdb02762" name="Default Changelist" comment=""> <list default="true" id="de83b181-e854-4be8-81f5-73a2fdb02762" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gongxianghui/gongxianghui.go" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go" beforeDir="false" afterPath="$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui_test.go" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -12,11 +13,73 @@ ...@@ -12,11 +13,73 @@
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300" /> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="579">
<caret line="544" column="21" lean-forward="true" selection-start-line="544" selection-start-column="21" selection-end-line="544" selection-end-column="21" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/go/src/builtin/builtin.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="664">
<caret line="259" column="5" selection-start-line="259" selection-start-column="5" selection-end-line="259" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/go/src/fmt/errors.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="295">
<caret line="16" column="5" selection-start-line="16" selection-start-column="5" selection-end-line="16" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/go/src/encoding/json/decode.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2352">
<caret line="94" column="5" selection-start-line="94" selection-start-column="5" selection-end-line="94" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1175">
<caret line="16" column="26" selection-start-line="16" selection-start-column="26" selection-end-line="16" selection-end-column="26" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/go/src/time/time.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="32116">
<caret line="1150" column="14" selection-start-line="1150" selection-start-column="14" selection-end-line="1150" selection-end-column="14" />
</state>
</provider>
</entry>
</file>
</leaf>
</component> </component>
<component name="FindInProjectRecents"> <component name="FindInProjectRecents">
<findStrings> <findStrings>
<find>user</find> <find>user</find>
<find>stub.GetState</find>
<find>stub.PutState</find>
</findStrings> </findStrings>
</component> </component>
<component name="GOROOT" path="/usr/local/go" /> <component name="GOROOT" path="/usr/local/go" />
...@@ -34,6 +97,7 @@ ...@@ -34,6 +97,7 @@
<option value="$PROJECT_DIR$/github.com/gongxianghui_test/gongxianghui_test.go" /> <option value="$PROJECT_DIR$/github.com/gongxianghui_test/gongxianghui_test.go" />
<option value="$PROJECT_DIR$/github.com/gongxianghui/gongxianghui.go" /> <option value="$PROJECT_DIR$/github.com/gongxianghui/gongxianghui.go" />
<option value="$PROJECT_DIR$/github.com/gongxianghui_test/gongxianghui.go" /> <option value="$PROJECT_DIR$/github.com/gongxianghui_test/gongxianghui.go" />
<option value="$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui_test.go" />
<option value="$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go" /> <option value="$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go" />
</list> </list>
</option> </option>
...@@ -50,6 +114,7 @@ ...@@ -50,6 +114,7 @@
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes>
<pane id="Scope" />
<pane id="ProjectPane"> <pane id="ProjectPane">
<subPane> <subPane>
<expand> <expand>
...@@ -57,6 +122,31 @@ ...@@ -57,6 +122,31 @@
<item name="chaincode" type="b2602c69:ProjectViewProjectNode" /> <item name="chaincode" type="b2602c69:ProjectViewProjectNode" />
<item name="chaincode" type="462c0819:PsiDirectoryNode" /> <item name="chaincode" type="462c0819:PsiDirectoryNode" />
</path> </path>
<path>
<item name="chaincode" type="b2602c69:ProjectViewProjectNode" />
<item name="chaincode" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="chaincode" type="b2602c69:ProjectViewProjectNode" />
<item name="chaincode" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="github.com" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="chaincode" type="b2602c69:ProjectViewProjectNode" />
<item name="chaincode" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="github.com" type="462c0819:PsiDirectoryNode" />
<item name="gongxianghui" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="chaincode" type="b2602c69:ProjectViewProjectNode" />
<item name="chaincode" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="github.com" type="462c0819:PsiDirectoryNode" />
<item name="gongxianghui_auth" type="462c0819:PsiDirectoryNode" />
</path>
<path> <path>
<item name="chaincode" type="b2602c69:ProjectViewProjectNode" /> <item name="chaincode" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" /> <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
...@@ -65,7 +155,6 @@ ...@@ -65,7 +155,6 @@
<select /> <select />
</subPane> </subPane>
</pane> </pane>
<pane id="Scope" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
...@@ -91,7 +180,7 @@ ...@@ -91,7 +180,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="RunManager" selected="Go Test.TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test"> <component name="RunManager" selected="Go Test.TestGXHDataPutAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth">
<configuration name="TestGXH in github.com/hyperledger/chaincode/github.com/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true"> <configuration name="TestGXH in github.com/hyperledger/chaincode/github.com/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="chaincode" /> <module name="chaincode" />
<working_directory value="$PROJECT_DIR$/github.com/gongxianghui" /> <working_directory value="$PROJECT_DIR$/github.com/gongxianghui" />
...@@ -114,34 +203,34 @@ ...@@ -114,34 +203,34 @@
<pattern value="^TestGXHDataPutAuth$" /> <pattern value="^TestGXHDataPutAuth$" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/github.com/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true"> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="chaincode" /> <module name="chaincode" />
<working_directory value="$PROJECT_DIR$/github.com/gongxianghui" /> <working_directory value="$PROJECT_DIR$/src/github.com/gongxianghui_auth" />
<framework value="gotest" /> <framework value="gotest" />
<kind value="PACKAGE" /> <kind value="PACKAGE" />
<package value="github.com/hyperledger/chaincode/github.com/gongxianghui" /> <package value="github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" />
<directory value="$PROJECT_DIR$/" /> <directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" /> <filePath value="$PROJECT_DIR$/" />
<pattern value="^TestGXHSchema$" /> <pattern value="^TestGXHDataPutAuth$" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true"> <configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="chaincode" /> <module name="chaincode" />
<working_directory value="$PROJECT_DIR$/gongxianghui" /> <working_directory value="$PROJECT_DIR$/github.com/gongxianghui_test" />
<framework value="gotest" /> <framework value="gotest" />
<kind value="PACKAGE" /> <kind value="PACKAGE" />
<package value="github.com/hyperledger/chaincode/gongxianghui" /> <package value="github.com/hyperledger/chaincode/github.com/gongxianghui_test" />
<directory value="$PROJECT_DIR$/" /> <directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" /> <filePath value="$PROJECT_DIR$/" />
<pattern value="^TestGXHSchema$" /> <pattern value="^TestGXHSchemaAuth$" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true"> <configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="chaincode" /> <module name="chaincode" />
<working_directory value="$PROJECT_DIR$/github.com/gongxianghui_test" /> <working_directory value="$PROJECT_DIR$/src/github.com/gongxianghui_auth" />
<framework value="gotest" /> <framework value="gotest" />
<kind value="PACKAGE" /> <kind value="PACKAGE" />
<package value="github.com/hyperledger/chaincode/github.com/gongxianghui_test" /> <package value="github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" />
<directory value="$PROJECT_DIR$/" /> <directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" /> <filePath value="$PROJECT_DIR$/" />
<pattern value="^TestGXHSchemaAuth$" /> <pattern value="^TestGXHSchemaAuth$" />
...@@ -149,55 +238,56 @@ ...@@ -149,55 +238,56 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Go Test.TestGXHDataPutAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" />
<item itemvalue="Go Test.TestGXHSchemaAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" />
<item itemvalue="Go Test.TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" /> <item itemvalue="Go Test.TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" />
<item itemvalue="Go Test.TestGXHSchemaAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" /> <item itemvalue="Go Test.TestGXHSchemaAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" />
<item itemvalue="Go Test.TestGXH in github.com/hyperledger/chaincode/github.com/gongxianghui" /> <item itemvalue="Go Test.TestGXH in github.com/hyperledger/chaincode/github.com/gongxianghui" />
<item itemvalue="Go Test.TestGXHSchema in github.com/hyperledger/chaincode/github.com/gongxianghui" />
<item itemvalue="Go Test.TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
<component name="TestHistory"> <component name="TestHistory">
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 11h 58m 38s.xml"> <history-entry file="TestGXHSchemaAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 08m 13s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 36m 05s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 09m 18s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 36m 55s.xml"> <history-entry file="TestGXHSchemaAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 10m 13s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 37m 25s.xml"> <history-entry file="TestGXHSchemaAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 16m 19s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 38m 00s.xml"> <history-entry file="TestGXHSchemaAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 16m 56s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 39m 54s.xml"> <history-entry file="TestGXHSchemaAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 18m 19s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 40m 19s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 18m 43s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 40m 45s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 19m 40s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 16h 14m 06s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 20m 06s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 18h 22m 13s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_src_github_com_gongxianghui_auth - 2020.02.29 at 22h 20m 41s.xml">
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/src/github.com/gongxianghui_auth" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="71" y="32" width="2489" height="1568" extended-state="6" /> <frame x="71" y="31" width="2489" height="1569" extended-state="6" />
<editor active="true" />
<layout> <layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.21466611" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.21701603" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" /> <window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32962447" /> <window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.32909605" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39986092" /> <window_info anchor="bottom" id="Debug" order="3" weight="0.39986092" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
...@@ -206,7 +296,7 @@ ...@@ -206,7 +296,7 @@
<window_info anchor="bottom" id="Version Control" order="8" /> <window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Database Changes" order="9" /> <window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Statistic" order="10" /> <window_info anchor="bottom" id="Statistic" order="10" />
<window_info anchor="bottom" id="Terminal" order="11" visible="true" weight="0.31223923" /> <window_info anchor="bottom" id="Terminal" order="11" weight="0.31223923" />
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" /> <window_info anchor="bottom" id="Event Log" order="12" side_tool="true" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
...@@ -218,6 +308,18 @@ ...@@ -218,6 +308,18 @@
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go</url>
<line>529</line>
<properties />
<option name="timeStamp" value="22" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/gongxianghui/schema.go" /> <entry file="file://$PROJECT_DIR$/gongxianghui/schema.go" />
<entry file="file://$PROJECT_DIR$/gongxianghui/deposit.go" /> <entry file="file://$PROJECT_DIR$/gongxianghui/deposit.go" />
...@@ -244,13 +346,6 @@ ...@@ -244,13 +346,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file:///usr/local/go/src/fmt/errors.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="211">
<caret line="16" column="5" selection-start-line="16" selection-start-column="5" selection-end-line="16" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/crypto/x509/pkix/pkix.go"> <entry file="file:///usr/local/go/src/crypto/x509/pkix/pkix.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state> <state>
...@@ -279,52 +374,59 @@ ...@@ -279,52 +374,59 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui_auth/gongxianghui_test.go"> <entry file="file://$PROJECT_DIR$/github.com/gongxianghui_auth/gongxianghui_test.go" />
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui/gongxianghui_test.go" />
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui/gongxianghui.go" />
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui_auth/gongxianghui.go" />
<entry file="file://$PROJECT_DIR$/../fabric/core/chaincode/shim/interfaces.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1276"> <state relative-caret-position="880">
<caret line="164" column="70" selection-start-line="164" selection-start-column="70" selection-end-line="164" selection-end-column="70" /> <caret line="44" column="4" selection-start-line="44" selection-start-column="4" selection-end-line="44" selection-end-column="4" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui/gongxianghui_test.go"> <entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file:///usr/local/go/src/encoding/json/decode.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="462"> <state relative-caret-position="2352">
<caret line="37" selection-start-line="37" selection-end-line="37" /> <caret line="94" column="5" selection-start-line="94" selection-start-column="5" selection-end-line="94" selection-end-column="5" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui/gongxianghui.go"> <entry file="file:///usr/local/go/src/time/time.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="519"> <state relative-caret-position="32116">
<caret line="90" column="83" selection-start-line="90" selection-start-column="78" selection-end-line="90" selection-end-column="83" /> <caret line="1150" column="14" selection-start-line="1150" selection-start-column="14" selection-end-line="1150" selection-end-column="14" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui_auth/gongxianghui.go"> <entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-7612"> <state relative-caret-position="-1175">
<caret line="107" column="83" selection-start-line="107" selection-start-column="83" selection-end-line="107" selection-end-column="83" /> <caret line="16" column="26" selection-start-line="16" selection-start-column="26" selection-end-line="16" selection-end-column="26" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui_test.go"> <entry file="file:///usr/local/go/src/builtin/builtin.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418"> <state relative-caret-position="664">
<caret line="107" column="4" selection-start-line="107" selection-start-column="4" selection-end-line="119" selection-end-column="66" /> <caret line="259" column="5" selection-start-line="259" selection-start-column="5" selection-end-line="259" selection-end-column="5" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go"> <entry file="file:///usr/local/go/src/fmt/errors.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="396"> <state relative-caret-position="295">
<caret line="26" column="61" selection-start-line="26" selection-start-column="4" selection-end-line="26" selection-end-column="61" /> <caret line="16" column="5" selection-start-line="16" selection-start-column="5" selection-end-line="16" selection-end-column="5" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/../fabric/core/chaincode/shim/interfaces.go"> <entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="880"> <state relative-caret-position="579">
<caret line="44" column="4" selection-start-line="44" selection-start-column="4" selection-end-line="44" selection-end-column="4" /> <caret line="544" column="21" lean-forward="true" selection-start-line="544" selection-start-column="21" selection-end-line="544" selection-end-column="21" />
</state> </state>
</provider> </provider>
</entry> </entry>
......
...@@ -8,29 +8,39 @@ import ( ...@@ -8,29 +8,39 @@ import (
"fmt" "fmt"
"github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer" pb "github.com/hyperledger/fabric/protos/peer"
"time"
) )
type GXHCC struct { type GXHCC struct {
} }
//type Schema struct { type AuthGroup struct {
//} Users map[string]int64 `json:"users"` //用户组权限,默认使用用户组。我们使用形如:“User1”:timestamp. key 表示用户或者角色,value 表示有效时间。我们使用格林威治时间时间戳
Roles map[string]int64 `json:"roles"` //角色组权限,
}
type Auth struct {
Read AuthGroup `json:"read"` // 字段的读权限,“”,不存在权限,
Write AuthGroup `json:"write"`//字段的写权限
}
type SchemaParameters struct { type SchemaParameters struct {
Value interface{} //默认值 这里特别说明一下如果这里是backUp 字段,我们不进行更深一步的校验,包括格式 Value interface{} `json:"val"`//默认值 这里特别说明一下如果这里是backUp 字段,我们不进行更深一步的校验,包括格式
Read []string // 字段的读权限,“”,不存在权限, PAuth Auth `json:"auth"`
Write []string //字段的写权限
} }
type Schema struct { type Schema struct {
Parameters map[string]SchemaParameters Fields map[string]SchemaParameters `json:"fields"`
SchemaWrite []string //schema 的写权限,主要是用在 schema update 部分 SchemaAuth Auth `json:"schema_auth"`//schema 的写权限,主要是用在 schema update 部分
Read []string SAuth Auth `json:"auth"`
Write []string
} }
var ( var (
defValue = "***" //查询用户权限不足的情况下默认返回值 defValue = "***" //查询用户权限不足的情况下默认返回值
PREFIX = "GXH"
IsUsers = false //是否启用用户权限,false 表示启用Roles
) )
// Init does nothing for this cc // Init does nothing for this cc
...@@ -89,7 +99,7 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -89,7 +99,7 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) < 2 { if len(args) < 2 {
return "", fmt.Errorf("Expected more than 2 parameters to function put!") return "", fmt.Errorf("Expected more than 2 parameters to function put!")
} }
var Result []map[string]interface{} var PutDatas []map[string]interface{}
commonName, err := getCertificateCommonName(stub) commonName, err := getCertificateCommonName(stub)
if err != nil { if err != nil {
return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err) return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err)
...@@ -102,13 +112,13 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -102,13 +112,13 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if err := json.Unmarshal([]byte(result), &schema); err != nil { if err := json.Unmarshal([]byte(result), &schema); err != nil {
return "", fmt.Errorf("json Unmarshal schemaRes err: %s ", err) return "", fmt.Errorf("json Unmarshal schemaRes err: %s ", err)
} }
if !authorityCheck(schema.Write, commonName) { if ok,err := authorityCheck(schema.SAuth.Write, commonName);!ok {
return "", fmt.Errorf("The current user does not have write permission to %s ", args[0]) return "", fmt.Errorf("write %s table fail,err: %s ", args[0],err)
} }
if err := json.Unmarshal([]byte(args[1]), &Result); err != nil { if err := json.Unmarshal([]byte(args[1]), &PutDatas); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json array, err:%s", err) return "", fmt.Errorf("parameters Unmarshal fail,args string not json array, err:%s", err)
} }
for k, mapres := range Result { for k, mapres := range PutDatas {
Id, ok := mapres["id"] Id, ok := mapres["id"]
if !ok { if !ok {
return "", fmt.Errorf("The id field must exist ") return "", fmt.Errorf("The id field must exist ")
...@@ -119,11 +129,11 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -119,11 +129,11 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
//else if result != nil { //else if result != nil {
// return "", fmt.Errorf("%s data already exist", args[0]+Id.(string)) // return "", fmt.Errorf("%s data already exist", args[0]+Id.(string))
//} //}
if !SchemaCheck(schema.Parameters, mapres) { if !SchemaCheck(schema.Fields, mapres) {
return "", fmt.Errorf("SchemaCheck fail,args index %d string doesn't match %s format", k, args[0]) return "", fmt.Errorf("SchemaCheck fail,args index %d string doesn't match %s format", k, args[0])
} }
putDate, _ := json.Marshal(mapres) putDate, _ := json.Marshal(mapres)
if err := stub.PutState(args[0]+Id.(string), putDate); err != nil { if err := stub.PutState(PREFIX+"_"+args[0]+"_"+Id.(string), putDate); err != nil {
return "", fmt.Errorf("PutState fail, err :%s", err) return "", fmt.Errorf("PutState fail, err :%s", err)
} }
} }
...@@ -149,33 +159,33 @@ func update(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -149,33 +159,33 @@ func update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if err := json.Unmarshal([]byte(schemaRes), &schema); err != nil { if err := json.Unmarshal([]byte(schemaRes), &schema); err != nil {
return "", fmt.Errorf("json Unmarshal schemaRes err: %s ", err) return "", fmt.Errorf("json Unmarshal schemaRes err: %s ", err)
} }
var mapResult map[string]interface{} var Updata map[string]interface{}
var allMap map[string]interface{} var allMap map[string]interface{}
if err := json.Unmarshal([]byte(args[1]), &mapResult); err != nil { if err := json.Unmarshal([]byte(args[1]), &Updata); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err) return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err)
} }
Id, ok := mapResult["id"] Id, ok := Updata["id"]
if !ok { if !ok {
return "", fmt.Errorf("The id field must exist ") return "", fmt.Errorf("The id field must exist ")
} }
if !authorityCheck(schema.Write, commonName) { if ok ,_ := authorityCheck(schema.SAuth.Write, commonName);!ok {
if ok, err := parsauthorityCheck(schema.Parameters, mapResult, commonName); !ok { if ok, err := parsauthorityCheck(schema.Fields, Updata, commonName); !ok {
return "", fmt.Errorf("parsauthorityCheck err: %s", err) return "", fmt.Errorf("parsauthorityCheck err: %s", err)
} }
} }
result, err := stub.GetState(args[0] + Id.(string)) result, err := stub.GetState(PREFIX+"_"+args[0]+"_"+Id.(string))
if err != nil || result == nil { if err != nil || result == nil {
return "", fmt.Errorf("GetState data fail,please check your parameters ") return "", fmt.Errorf("GetState data fail,please check your parameters ")
} }
if err := json.Unmarshal(result, &allMap); err != nil { if err := json.Unmarshal(result, &allMap); err != nil {
return "", fmt.Errorf("result parameters Unmarshal fail err:%s ", err) return "", fmt.Errorf("result parameters Unmarshal fail err:%s ", err)
} }
if err := Deassign(mapResult, allMap); err != nil { if err := Deassign(Updata, allMap); err != nil {
return "", err return "", err
} }
resultByte, _ := json.Marshal(allMap) resultByte, _ := json.Marshal(allMap)
if err := stub.PutState(args[0]+Id.(string), resultByte); err != nil { if err := stub.PutState(PREFIX+"_"+args[0]+"_"+Id.(string), resultByte); err != nil {
return "", fmt.Errorf("updateState date fail, err :%s ", err) return "", fmt.Errorf("updateState date fail, err :%s ", err)
} }
return fmt.Sprintf("%s update data success!", args[0]), nil return fmt.Sprintf("%s update data success!", args[0]), nil
...@@ -201,7 +211,7 @@ func get(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -201,7 +211,7 @@ func get(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if !ok { if !ok {
return "", fmt.Errorf("The id field must exist ") return "", fmt.Errorf("The id field must exist ")
} }
result, err := stub.GetState(args[0] + Id.(string)) result, err := stub.GetState(PREFIX+"_"+args[0]+"_"+Id.(string))
if err != nil || result == nil { if err != nil || result == nil {
return "", fmt.Errorf("GetState data fail,please check your parameters ") return "", fmt.Errorf("GetState data fail,please check your parameters ")
} }
...@@ -216,8 +226,8 @@ func get(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -216,8 +226,8 @@ func get(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if err := json.Unmarshal(result, &mapResult); err != nil { if err := json.Unmarshal(result, &mapResult); err != nil {
return "", fmt.Errorf(" Unmarshal fail,result err: %s", err) return "", fmt.Errorf(" Unmarshal fail,result err: %s", err)
} }
if !authorityCheck(schema.Read, commonName) { if ok,_:= authorityCheck(schema.SAuth.Read, commonName);!ok {
if filteredData, err := dataFilter(schema.Parameters, mapResult, commonName); err != nil { if filteredData, err := dataFilter(schema.Fields, mapResult, commonName); err != nil {
return "", fmt.Errorf(" dataFilter fail, err: %s", err) return "", fmt.Errorf(" dataFilter fail, err: %s", err)
} else { } else {
result, _ := json.Marshal(filteredData) result, _ := json.Marshal(filteredData)
...@@ -313,7 +323,7 @@ func SchemaProcess(args []string, stub shim.ChaincodeStubInterface) (string, err ...@@ -313,7 +323,7 @@ func SchemaProcess(args []string, stub shim.ChaincodeStubInterface) (string, err
case "update": case "update":
return schema.update(args[1:], stub) return schema.update(args[1:], stub)
case "get": case "get":
return schema.get(args[1], stub) return schema.getSchema(args[1], stub)
default: default:
return "", fmt.Errorf(fmt.Sprintf("Unsupported schema function of %s", args[0])) return "", fmt.Errorf(fmt.Sprintf("Unsupported schema function of %s", args[0]))
...@@ -338,7 +348,7 @@ func (this *Schema) put(args []string, stub shim.ChaincodeStubInterface) (string ...@@ -338,7 +348,7 @@ func (this *Schema) put(args []string, stub shim.ChaincodeStubInterface) (string
if err := json.Unmarshal([]byte(args[1]), &schema); err != nil { if err := json.Unmarshal([]byte(args[1]), &schema); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err) return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err)
} else { } else {
if backupValue, ok := schema.Parameters["backup"]; ok { if backupValue, ok := schema.Fields["backup"]; ok {
if _,ok := backupValue.Value.(map[string]interface{}); !ok { if _,ok := backupValue.Value.(map[string]interface{}); !ok {
return "", fmt.Errorf("parameters Unmarshal fail,extra string not json string,err: %s", err) return "", fmt.Errorf("parameters Unmarshal fail,extra string not json string,err: %s", err)
} }
...@@ -349,15 +359,15 @@ func (this *Schema) put(args []string, stub shim.ChaincodeStubInterface) (string ...@@ -349,15 +359,15 @@ func (this *Schema) put(args []string, stub shim.ChaincodeStubInterface) (string
//} //}
} }
} }
_, ok := schema.Parameters["id"] _, ok := schema.Fields["id"]
if !ok { if !ok {
return "", fmt.Errorf("The id field must exist ") return "", fmt.Errorf("The id field must exist ")
} }
if value, _ := stub.GetState(args[0]); value != nil { if value, _ := stub.GetState(PREFIX+"_"+args[0]); value != nil {
return "", fmt.Errorf("the parameter %s already exists and cannot be added", args[0]) return "", fmt.Errorf("the parameter %s already exists and cannot be added", args[0])
} }
putDate, _ := json.Marshal(schema) //处理重复字段 putDate, _ := json.Marshal(schema) //处理重复字段
if err := stub.PutState(args[0], putDate); err != nil { if err := stub.PutState(PREFIX+"_"+args[0], putDate); err != nil {
return "", fmt.Errorf("PutState fail,err: %s", err) return "", fmt.Errorf("PutState fail,err: %s", err)
} }
return fmt.Sprintf("%s schema put success!", args[0]), nil return fmt.Sprintf("%s schema put success!", args[0]), nil
...@@ -377,17 +387,17 @@ func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (str ...@@ -377,17 +387,17 @@ func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (str
if err := json.Unmarshal([]byte(args[1]), &schema); err != nil { if err := json.Unmarshal([]byte(args[1]), &schema); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err) return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err)
} else { } else {
if backupValue, ok := schema.Parameters["backup"]; ok { //保证backup 对应的参数格式为map[string]interface{} if backupValue, ok := schema.Fields["backup"]; ok { //保证backup 对应的参数格式为map[string]interface{}
if _,ok := backupValue.Value.(map[string]interface{}); !ok { if _,ok := backupValue.Value.(map[string]interface{}); !ok {
return "", fmt.Errorf("parameters Unmarshal fail,extra string not json string,err: %s", err) return "", fmt.Errorf("parameters Unmarshal fail,extra string not json string,err: %s", err)
} }
} }
} }
_, ok := schema.Parameters["id"] _, ok := schema.Fields["id"]
if !ok { if !ok {
return "", fmt.Errorf("The id field must exist ") return "", fmt.Errorf("The id field must exist ")
} }
result, err := stub.GetState(args[0]) result, err := stub.GetState(PREFIX+"_"+args[0])
if err != nil || result == nil { if err != nil || result == nil {
return "", fmt.Errorf("%s schema data doesn't exist,please check your parameters ",args[0]) return "", fmt.Errorf("%s schema data doesn't exist,please check your parameters ",args[0])
} }
...@@ -399,10 +409,10 @@ func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (str ...@@ -399,10 +409,10 @@ func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (str
if err != nil { if err != nil {
return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err) return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err)
} }
if !authorityCheck(schema.SchemaWrite,commonName){ if ok,err := authorityCheck(schema.SchemaAuth.Write,commonName);!ok{
return "", fmt.Errorf("The current user does not have update permission to %s schema ", args[0]) return "", fmt.Errorf("update %s schema fail,err: %s ",args[0],err)
} }
if err = stub.PutState(args[0], []byte(args[1]));err != nil{ if err = stub.PutState(PREFIX+"_"+args[0], []byte(args[1]));err != nil{
return "", fmt.Errorf("%s schema data PutState fail,please try again ",args[0]) return "", fmt.Errorf("%s schema data PutState fail,please try again ",args[0])
} }
return fmt.Sprintf("%s schema update success!", args[0]), err return fmt.Sprintf("%s schema update success!", args[0]), err
...@@ -410,10 +420,28 @@ func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (str ...@@ -410,10 +420,28 @@ func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (str
} }
func (this *Schema) get(args string, stub shim.ChaincodeStubInterface) (string, error) { func (this *Schema) get(args string, stub shim.ChaincodeStubInterface) (string, error) {
result, err := stub.GetState(args) result, err := stub.GetState(PREFIX+"_"+args)
if err != nil || result == nil {
return "", fmt.Errorf("GetSchema data fail,please check your parameters ")
}
return string(result), nil
}
func (this *Schema) getSchema(args string, stub shim.ChaincodeStubInterface)(string, error) {
result, err := stub.GetState(PREFIX+"_"+args)
if err != nil || result == nil { if err != nil || result == nil {
return "", fmt.Errorf("GetSchema data fail,please check your parameters ") return "", fmt.Errorf("GetSchema data fail,please check your parameters ")
} }
if err := json.Unmarshal(result, this); err != nil {
return "", fmt.Errorf("SchemaData Unmarshal fail, err: %s", err)
}
commonName, err := getCertificateCommonName(stub)
if err != nil {
return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err)
}
if ok,err := authorityCheck(this.SchemaAuth.Read,commonName);!ok{
return "",fmt.Errorf("get %s schema fail,err: %s", args,err)
}
return string(result), nil return string(result), nil
} }
...@@ -458,8 +486,8 @@ func parsauthorityCheck(schema map[string]SchemaParameters, checkmap map[string] ...@@ -458,8 +486,8 @@ func parsauthorityCheck(schema map[string]SchemaParameters, checkmap map[string]
// } // }
// } // }
//} else { //} else {
if !authorityCheck(schemaV.Write, commonName) { if ok,err := authorityCheck(schemaV.PAuth.Write, commonName);!ok {
return false, fmt.Errorf("%s field permission check does not match", k) return false, fmt.Errorf("%s field permission check does not match, err: %s ", k,err)
} }
//} //}
} }
...@@ -480,7 +508,7 @@ func dataFilter(schema map[string]SchemaParameters, checkmap map[string]interfac ...@@ -480,7 +508,7 @@ func dataFilter(schema map[string]SchemaParameters, checkmap map[string]interfac
if _, ok := v.(map[string]interface{}); !ok { if _, ok := v.(map[string]interface{}); !ok {
return nil, fmt.Errorf("Update data parameter mismatch with schema structure! ") return nil, fmt.Errorf("Update data parameter mismatch with schema structure! ")
} }
if !authorityCheck(schemaV.Read, commonName) { if ok,_ := authorityCheck(schemaV.PAuth.Read, commonName);!ok {
checkmap[k] = defValue checkmap[k] = defValue
} }
//else { //else {
...@@ -489,7 +517,7 @@ func dataFilter(schema map[string]SchemaParameters, checkmap map[string]interfac ...@@ -489,7 +517,7 @@ func dataFilter(schema map[string]SchemaParameters, checkmap map[string]interfac
// } // }
//} //}
} else { } else {
if !authorityCheck(schemaV.Read, commonName) { if ok,_ := authorityCheck(schemaV.PAuth.Read, commonName);!ok {
checkmap[k] = defValue checkmap[k] = defValue
} }
} }
...@@ -498,16 +526,26 @@ func dataFilter(schema map[string]SchemaParameters, checkmap map[string]interfac ...@@ -498,16 +526,26 @@ func dataFilter(schema map[string]SchemaParameters, checkmap map[string]interfac
return checkmap, nil return checkmap, nil
} }
func authorityCheck(authority []string, commonName string) bool { func authorityCheck(authority AuthGroup, commonName string) (bool,error) {
if len(authority) == 0 { var auths map[string]int64
return true if IsUsers {
} auths = authority.Users
for _, v := range authority { }else{
if v == commonName { auths = authority.Roles
return true }
if len(auths) == 0 {
return true,nil
}
for k, v := range auths {
if k == commonName {
if v == 0 || v > time.Now().Unix(){
return true,nil
}else{
return false,fmt.Errorf("%s user permission period ",commonName)
}
} }
} }
return false return false,fmt.Errorf("%s user does not have permission",commonName)
} }
......
...@@ -7,111 +7,39 @@ import ( ...@@ -7,111 +7,39 @@ import (
) )
var schema = `{"Parameters":{"Alinkman":{"Value":"Alinkman","Read":"","Write":""},"Amob":{"Value":"Amob","Read":"","Write":""}, var schema = `{"fields":{"alinkman":{"val":"Alinkman","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
"Aname":{"Value":"Aname","Read":"","Write":""},"Atype":{"Value":"Atype","Read":"","Write":""},"Backup":{"Value":[{"Value":"1", {"admin":1582972202}}}},"amob":{"val":"Amob","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
"Read":"","Write":""},{"Value":"Aname","Read":"","Write":""},{"Value":"Atype","Read":"","Write":""},{"Value":"Alinkman","Read":"","Write":""}], {"admin":1582972202}}}},"aname":{"val":"Aname","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
"Read":"","Write":""},"id":{"Value":"1","Read":"","Write":""}},"Read":"","Write":"","ParametersRead":true,"ParametersWrite":true}` {"admin":1582972202}}}},"atype":{"val":"Atype","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
{"admin":1582972202}}}},"backup":{"val":{"aname":"Aname","atype":"Atype"},"auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":
func TestGXHCC(t *testing.T) { {"admin":0},"roles":{"admin":1582972202}}}},"id":{"val":"1","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
cc := new(GXHCC) {"admin":1582972202}}}}},"schema_auth":{"read":{"users":null,"roles":null},"write":{"users":{"admin":0},"roles":{"admin":1582972202}}},"auth":{"read":{"users":
stub := shim.NewMockStub("GXHCC",cc) {"admin":0},"roles":{"admin":0}},"write":{"users":{"admin":0},"roles":{"admin":1582972202}}}}
response:= stub.MockInit("init",nil) `
fmt.Println(string(response.Payload)) var schema2 = `{"fields":{"alinkman":{"val":"Alinkman","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
input := `{"aname":"alibusi","aname":"alibus","atype":"type","alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"","aader":"aader","amob":"1234567890"}}` {"admin":1582972202}}}},"amob":{"val":"Amob","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
responseByPut := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(input)}) {"admin":1582972202}}}},"aname":{"val":"Aname","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPut.Status,responseByPut.Message,string(responseByPut.Payload)) {"admin":1582972202}}}},"atype":{"val":"Atype","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(input)}) {"admin":1582972202}}}},"backup":{"val":{"aname":"Aname","atype":"Atype"},"auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":
fmt.Printf("Invoke status %d,message %s and payload %s \n",responseByget.Status,responseByget.Message,string(responseByget.Payload)) {"admin":0},"roles":{"admin":1582972202}}}},"id":{"val":"1","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
return {"admin":1582972202}}}}},"schema_auth":{"read":{"users":null,"roles":null},"write":{"users":{"admin":0},"roles":{"admin":1582972202}}},"auth":{"read":{"users":
input2 := `{"id":"1","aname":"aaa","atype":"aaa","alinkman":"cc","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"aaa","aader":"aader","amob":"1234567890"}}` {"admin":0},"roles":{"admin":0}},"write":{"users":{"admin":0},"roles":{"admin":0}}}}
responseByPut2 := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(input2)}) `
fmt.Printf("Invoke22 status %d,message %s and payload %s\n",responseByPut2.Status,responseByPut2.Message,string(responseByPut2.Payload))
responseByget2 := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke22 status %d,message %s and payload %s",responseByget2.Status,responseByget2.Message,string(responseByget2.Payload))
}
func TestGXHSchema(t *testing.T){
input := `{"id":"1","aname":"alibusi","aname":"alibus","atype":"type","alinkman":"","aader":"aader",
"amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"",
"aader":"aader","amob":"1234567890"}}`
inputarrary := `[{"id":"1","aname":"alibusi","atype":"type","alinkman":"",
"aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890"}},{"id":"2","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890"}}]`
update := `{"alinkman":"张三","id":"1","backup":{}}`
cc := new(GXHCC)
stub := shim.NewMockStub("GXHCC",cc)
response:= stub.MockInit("init",nil)
fmt.Println("MockInit Payload: ",string(response.Payload))
fmt.Println()
fmt.Println("========================================invoke schema put============================================")
fmt.Println()
fmt.Println()
responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(input)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
responseByGet := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")})
fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByGet.Status,responseByGet.Message,string(responseByGet.Payload))
fmt.Println()
fmt.Println("========================================invoke data put============================================")
fmt.Println()
fmt.Println()
responseByPut := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(inputarrary)})
fmt.Printf("Invoke status %d,message %s ,and payload %s\n",
responseByPut.Status,responseByPut.Message,string(responseByPut.Payload))
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget.Status,responseByget.Message,string(responseByget.Payload))
fmt.Println()
fmt.Println("========================================invoke data update============================================")
fmt.Println()
fmt.Println()
responseByUpdate := stub.MockInvoke("invoke1",[][]byte{[]byte("update"), []byte("alibusi"),[]byte(update)})
fmt.Printf("Invoke status %d,message %s ,and payload %s\n",
responseByUpdate.Status,responseByUpdate.Message,string(responseByUpdate.Payload))
responseByget2 := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget2.Status,responseByget2.Message,string(responseByget2.Payload))
//inputfail := `{"id":"2","atype":"type","alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"","aader":"aader","amob":"1234567890"}}`
//fmt.Println()
//fmt.Println("========================================fail input data============================================")
//
//
//responseByPutfail := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(inputfail)})
//fmt.Printf("Invoke status %d,message %s and payload %s\n",
// responseByPutfail.Status,responseByPutfail.Message,string(responseByPutfail.Payload))
//responseBygetfail := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
//fmt.Printf("Invoke status %d,message %s and payload %s \n",
// responseBygetfail.Status,responseBygetfail.Message,string(responseBygetfail.Payload))
}
var schema3 = `{"fields":{"alinkman":{"val":"Alinkman","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
{"admin":1582972202}}}},"amob":{"val":"Amob","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
{"admin":1582972202}}}},"aname":{"val":"Aname","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
{"admin":1582972202}}}},"atype":{"val":"Atype","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
{"admin":1582972202}}}},"backup":{"val":{"aname":"Aname","atype":"Atype"},"auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":
{"admin":0},"roles":{"admin":1582972202}}}},"id":{"val":"1","auth":{"read":{"users":{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":
{"admin":1582972202}}}}},"schema_auth":{"read":{"users":null,"roles":null},"write":{"users":{"admin":0},"roles":{"admin":1582972202}}},"auth":{"read":{"users":
{"admin":0},"roles":{"admin":1582972202}},"write":{"users":{"admin":0},"roles":{"admin":0}}}}
`
/* /*
以下部分是增加权限内容的测试 以下部分是增加权限内容的测试
*/ */
var ( var (
authInput = `{"Parameters":{"alinkman":{"Value":"Alinkman","Read":["user"],"Write":["admin"]},"amob":{"Value":"Amob","Read":[],"Write":[]},"aname":
{"Value":"Aname","Read":["admin"],"Write":["admin"]},"atype":{"Value":"Atype","Read":["admin"],"Write":["admin"]},"backup":{"Value":{"aname":
{"Value":"Aname","Read":["admin"],"Write":["admin"]},"atype":{"Value":"Atype","Read":["admin"],"Write":["admin"]}},"Read":["admin"],"Write":["admin"]},
"id":{"Value":"1","Read":[],"Write":[]}},"Read":[],"Write":["user"]}
`
inputUpdate = `{"id":"1","aname":"alibusi","atype":"newtype","alinkman":"newalinkman", inputUpdate = `{"id":"1","aname":"alibusi","atype":"newtype","alinkman":"newalinkman",
"amob":"new1234567890","backup":{"aname":"alibusi","atype":"type"}}` "amob":"new1234567890","backup":{"aname":"alibusi","atype":"type"}}`
...@@ -127,12 +55,23 @@ func TestGXHSchemaAuth(t *testing.T){ ...@@ -127,12 +55,23 @@ func TestGXHSchemaAuth(t *testing.T){
fmt.Println("========================================invoke schema put============================================") fmt.Println("========================================invoke schema put============================================")
fmt.Println() fmt.Println()
fmt.Println() fmt.Println()
responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(authInput)}) responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(schema)})
fmt.Printf("Invoke status %d,message %s and payload %s\n", fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload)) responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
fmt.Println()
fmt.Println("========================================invoke schema get============================================")
fmt.Println()
fmt.Println()
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")}) responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n", fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget.Status,responseByget.Message,string(responseByget.Payload)) responseByget.Status,responseByget.Message,string(responseByget.Payload))
fmt.Println()
fmt.Println("========================================invoke schema update============================================")
fmt.Println()
fmt.Println()
responseByupdate := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("update"),[]byte("alibusi"),[]byte(schema)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByupdate.Status,responseByupdate.Message,string(responseByupdate.Payload))
} }
...@@ -144,7 +83,8 @@ func TestGXHDataPutAuth(t *testing.T){ ...@@ -144,7 +83,8 @@ func TestGXHDataPutAuth(t *testing.T){
fmt.Println("========================================invoke schema put============================================") fmt.Println("========================================invoke schema put============================================")
fmt.Println() fmt.Println()
fmt.Println() fmt.Println()
responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(authInput)}) responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(schema3)})
//使用schema 数据测试过期时间err,schema right data,使用schema3 测试读取字段时的过滤
fmt.Printf("Invoke status %d,message %s and payload %s\n", fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload)) responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")}) responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment