作者:AsReader
鏈接:https://www.zhihu.com/question/64845885/answer/1122345134
來源:知乎
0.前言
本文介紹了如何搭建Shibboleth,實現Shibboleth+Ldap的SSO解決方案
1.什么是Shibboleth
Shibboleth是一個基于標準的,實現組織內部或跨組織的網頁單點登錄的開源軟件包。它允許站點為處于私有保護方式下的受保護的在線資源做出被通知的認證決定。
Shibboleth軟件工具廣泛使用聯合的身份標準,主要是OASIS安全聲稱標記語言(SAML),來提供一個聯合單點登錄和屬性交換框架。一個用戶用他的組織的證書認證,組織(或IdP)傳送最少的必要的身份信息給SP實現認證決定。Shibboleth也提供擴展的隱私功能,允許一個用戶和他們的主站點來控制釋放給每一個應用的屬性。
Shibboleth項目作為一個Internet2中間件活動啟動于2000年,這年晚些時候該項目和OASIS SAML工作組的工作相聯系。Shibboleth1.0 于2003年發布,并快速被全世界的研究和教育機構使用。隨著2005年SAML2.0的發布,2006年Shibboleth2.0也發布,SAML標準升級到包含所有的多邊,由Shibboleth首創的元數據驅動方法。
Shibboleth作為開源軟件開發,在Apache 軟件許可證下發布。關于個別部件的更多信息可以在產品頁面看到。
2.安裝Shibboleth Identity Provider v3.2.1
- 切換成root
sudo su
2.下載Shibboleth Identity Provider v3.2.1
wget http://shibboleth.net/downloads/identity-provider/latest/shibboleth-identity-provider-3.2.1.tar.gz tar -xzvf shibboleth-identity-provider-3.2.1.tar.gz cd shibboleth-identity-provider-3.2.1
3.安裝Shibboleth Idenentity Provider:
sh-3.2# ./install.sh Source (Distribution) Directory (press <enter> to accept default): [/Users/zhaoyu.zhaoyu/Applications/shibboleth-identity-provider-3.3.2] Installation Directory: [/opt/shibboleth-idp] Hostname: [localhost.localdomain] testdomain.com SAML EntityID: [https://testdomain.com/idp/shibboleth] Attribute Scope: [localdomain] Backchannel PKCS12 Password: Re-enter password: Cookie Encryption Key Password: Re-enter password: Warning: /opt/shibboleth-idp/bin does not exist. Warning: /opt/shibboleth-idp/dist does not exist. Warning: /opt/shibboleth-idp/doc does not exist. Warning: /opt/shibboleth-idp/system does not exist. Warning: /opt/shibboleth-idp/webapp does not exist. Generating Signing Key, CN = testdomain.com URI = https://testdomain.com/idp/shibboleth ... ...done Creating Encryption Key, CN = testdomain.com URI = https://testdomain.com/idp/shibboleth ... ...done Creating Backchannel keystore, CN = testdomain.com URI = https://testdomain.com/idp/shibboleth ... ...done Creating cookie encryption key files... ...done Rebuilding /opt/shibboleth-idp/war/idp.war ... ...done BUILD SUCCESSFUL Total time: 1 minute 14 seconds
(from now "{idp.home}" == /opt/shibboleth-idp/)
4.導入 JST library (status界面會用到):
cd /opt/shibboleth-idp/edit-webapp/WEB-INF/lib wget https://build.shibboleth.net/nexus/service/local/repositories/thirdparty/content/javax/servlet/jstl/1.2/jstl-1.2.jar cd /opt/shibboleth-idp/bin ./build.sh -Didp.target.dir=/opt/shibboleth-idp
3.安裝指引
3.1 安裝apache tomcat 8
1.切換成root
sudo su -
2.修改tomcat的%{CATALINA_HOME}/conf/server.xml
將8080端口和8443端口的地方分別改成80和443
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
3.生成證書文件
[chengxu@local]keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "./tomcat.keystore" 輸入密鑰庫口令: 再次輸入新口令: 您的名字與姓氏是什么? [Unknown]: cheng 您的組織單位名稱是什么? [Unknown]: testdomain.com 您的組織名稱是什么? [Unknown]: testdomain.com 您所在的城市或區域名稱是什么? [Unknown]: 您所在的省/市/自治區名稱是什么? [Unknown]: 該單位的雙字母國家/地區代碼是什么? [Unknown]: CN=cheng, OU=testdomain.com, O=testdomain.com, L=Unknown, ST=Unknown, C=Unknown是否正確? [否]: 是 輸入 <tomcat> 的密鑰口令 (如果和密鑰庫口令相同, 按回車): 再次輸入新口令: [chengxu@local]
4.修改tomcat的%{CATALINA_HOME}/conf/server.xml,使支持https協議
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="/Users/chengxu/Shibboleth/tomcat/tomcat.keystore" keystorePass="xxx"/>
5.發布Idp Web Application到Tomcat 8 container
vim %{CATALINA_HOME}/conf/Catalina/localhost/idp.xml
<Context docBase="/opt/shibboleth-idp/war/idp.war" privileged="true" antiResourceLocking="false" swallowOutput="true"/>
4.配置host
vim /etc/host 127.0.0.1 testdomain.com
5.重啟tomcat
%{CATALINA_HOME}/bin/catalina.sh stop
%{CATALINA_HOME}/bin/catalina.sh start
6.檢測是否服務啟動正常
訪問https://testdomain/idp/status
或者/opt/shibboleth-idp/bin; ./status.sh
3.2 配置shibboleth連接ldap
編輯修改ldap.properties
vim /opt/shibboleth/conf/ldap.properties idp.authn.LDAP.authenticator = bindSearchAuthenticator idp.authn.LDAP.ldapURL = ldap://ldap.example.it:389 idp.authn.LDAP.useStartTLS = false idp.authn.LDAP.useSSL = false idp.authn.LDAP.baseDN = cn=Users,dc=example,dc=org idp.authn.LDAP.userFilter = (uid={user}) idp.authn.LDAP.bindDN = cn=admin,cn=Users,dc=example,dc=org idp.authn.LDAP.bindDNCredential = ###LDAP ADMIN PASSWORD###
6.修改shibboleth ldap配置
vim /opt/shibboleth/conf/services.xml 把 <value>%{idp.home}/conf/attribute-resolver.xml</value> 改為 <value>%{idp.home}/conf/attribute-resolver-full.xml</value>
vim /opt/shibboleth-idp/conf/attribute-resolver-full.xml 注釋掉下列代碼,如果已經注釋掉了就不動了(有些版本已經注釋了) <!-- <dc:StartTLSTrustCredential id="LDAPtoIdPCredential" xsi:type="sec:X509ResourceBacked"> <sec:Certificate>% {idp.attribute.resolver.LDAP.trustCertificates}</sec:Certificate> </dc:StartTLSTrustCredential> -->
重啟tomcat
7.獲取idp metadata.xml
https://testdomain.com/idp/shibboleth
注意metadata.xml文件中的validUntil屬性,如果過期了則修改為未來的某個時間點
4.小結
至此我們完成了Shibboleth與LDAP集成的安裝過程
下篇: 實現Shibboleth+Ldap到阿里云的單點登錄
來自:https://yq.aliyun.com/articles/350531?tdsourcetag=s_pcqq_aiomsg&do=login&accounttraceid=87b0f203-5d81-4cb7-a986-49615e3962e2&do=login&do=login
在C盤根目錄下建立以下批處理文件:
c:
cd C:\Program Files\Microvirt\MEmu
adb start-server
c:
cd C:\Android\Sdk\platform-tools
adb connect 127.0.0.1:21503
cd\
在命令提示符(管理員)下運行它就OK了。
flutter config --android-sdk 自己的android sdk路徑Android SDK默認的安裝地址為:
C:\Users\Administrator\AppData\Local\Android\SDK
現需要把它搬到 C:\Android\Sdk
操作如下:
1.把C:\Users\Administrator\AppData\Local\Android\SDK剪切復制到C:\Android\Sdk;
2.在FLutter sdk 目錄下運行如下命令:
flutter config --android-sdk C:\Android\Sdk
3.在環境變量中把ANDROID_HOME改為C:\Android\Sdk;
重啟,這樣就OK了。
https://baijiahao.baidu.com/s?id=1630789160989369444&wfr=spider&for=pc
安裝后還是無法聯網的,需要以下步驟才能聯網:
設置--》網絡和互聯網--》私人DNS -->把自動改為關閉
就能上網了。
===============CentOS 7.6================
1.查看系統時間
查看當前系統時間以及時區
結果是:
Mon Jul 8 09:23:31 UTC 2019
2.更改系統時間時區
timedatectl set-timezone Asia/Shanghai
3.再次查看
結果是:
Mon Jul 8 17:25:28 CST 2019
4.可以重啟后查看,防止重啟后失效
=======================
https://www.jianshu.com/p/d58dab805ca6
keytool -genkey -v -keystore ./key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
apk 輸出在:
C:\Users\Administrator\AndroidStudioProjects\flutter_app\build\app\outputs\apk\release
key.properties
storePassword=123456
keyPassword=123456
keyAlias=key
storeFile=C:/Users/Administrator/AndroidStudioProjects/flutter_app/key.jks
build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutter_app"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
//signingConfig signingConfigs.debug
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
解決辦法:
修改以下文件
C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_load_hook.c
增加以下代碼,到第一個#include前
#ifndef DELAYIMP_INSECURE_WRITABLE_HOOKS#define DELAYIMP_INSECURE_WRITABLE_HOOKS#endif
參考:
https://github.com/nodejs/node-gyp/issues/949
https://github.com/Automattic/node-canvas/issues/619
————————————————
版權聲明:本文為CSDN博主「Amatig」的原創文章,遵循CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/cooltigerkin/article/details/51807588
VS2015最高支持14393版本的SDK,之后的從15063起就必須要VS2017,很多人出現VS找不到rc.ex和cl.exe的問題,就是沒有安裝SDK或安裝了VS不支持的SDK版本;這個問題有人在知乎上提問過“如何將獨立安裝的win10SDK與vs2015建立聯系?“
VS2015不完全支持Win10的某些項目編譯,比如應用商店應用、1703、1709的驅動程序,但是VS2017太難用了,所以我還是堅持用2015
解決辦法:
卸載新版本WinSDK,安裝14393版本的SDK
或
卸載VS2015安裝VS2017
————————————————
版權聲明:本文為CSDN博主「樓頂上的貓」的原創文章,遵循CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_30113467/article/details/100013766
1.把 "Gateway": "/ip4/127.0.0.1/tcp/8080"修改為:"Gateway": "/ip4/0.0.0.0/tcp/8080",這樣本機就可以用192.168WEB訪問了。
2.把WINDOWS防火墻入站的8080端口打開,這樣在局域網就能訪問了。
在之前的博客中提到解決此問題的方法是進入mysql的命令窗口,執行set global show_compatibility_56=on;
但是該方法只能生效一次,當電腦重啟或者mysql服務重啟的時候,就得重新再設置一次,下面提供一個永久生效的方法,即不通過上述方法,而是修改mysql的配置文件,找到my.ini的配置文件,在文件的最后添加:show_compatibility_56 = 1 即可。
本人的my.ini的文件路徑是:C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
————————————————
版權聲明:本文為CSDN博主「讓愛遠行2015」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/u011065164/article/details/53393348
https://remix.ethereum.org/
http://remix.hubwiz.com/
https://ethereum.github.io/
最新內容會更新在主站深入淺出區塊鏈社區
原文鏈接:Web3與智能合約交互實戰
寫在前面
在最初學習以太坊的時候,很多人都是自己創建以太坊節點后,使用geth與之交互。這種使用命令行交互的方法雖然讓很多程序員感到興奮(黑客帝國的既視感?),但不可能指望普通用戶通過命令行使用Dapp。因此,我們需要一種友好的方式(比如一個web頁面)來與智能合約交互,于是問題的答案就是web3.js
。
Web3.js
Web3.js是以太坊官方的Javascript API,可以幫助智能合約開發者使用HTTP或者IPC與本地的或者遠程的以太坊節點交互。實際上就是一個庫的集合,主要包括下面幾個庫:
web3-eth
用來與以太坊區塊鏈和智能合約交互web3-shh
用來控制whisper協議與p2p通信以及廣播web3-bzz
用來與swarm協議交互web3-utils
包含了一些Dapp開發有用的功能
Web3與geth通信使用的是 JSON-RPC ,這是一種輕量級的RPC(Remote Procedure Call)協議,整個通信的模型可以抽象為下圖。

搭建測試鏈
在開發初期,我們并沒有必要使用真實的公鏈,為了開發效率,一般選擇在本地搭建測試鏈。在本文我們選擇的Ganache(在此之前使用的是testrpc,Ganache屬于它的升級版),一個圖形化測試軟件(也有命令行版本),可以一鍵在本地搭建以太坊區塊鏈測試環境,并且將區塊鏈的狀態通過圖形界面顯示出來,Ganache的運行界面如下圖所示。

從圖中可以看到Ganache會默認創建10個賬戶,監聽地址是http://127.0.0.1:7545
,可以實時看到Current Block
、Gas Price
、Gas Limit
等信息。
創建智能合約
目前以太坊官方全力支持的智能合約開發環境是Remix IDE,我們在合約編輯頁面編寫如下代碼:
pragma solidity ^0.4.21; contract InfoContract { string fName; uint age; function setInfo(string _fName, uint _age) public { fName = _fName; age = _age; } function getInfo() public constant returns (string, uint) { return (fName, age); } }
代碼很簡單,就是簡單的給name
和age
變量賦值與讀取,接下來切換到 run 的 tab 下,將Environment
切換成Web3 Provider
,并輸入我們的測試鏈的地址http://127.0.0.1:7545
,這里對這三個選項做一簡單說明:
Javascript VM
:簡單的Javascript虛擬機環境,純粹練習智能合約編寫的時候可以選擇Injected Web3
:連接到嵌入到頁面的Web3,比如連接到MetaMaskWeb3 Provider
:連接到自定義的節點,如私有的測試網絡。
如果連接成功,那么在下面的Account
的選項會默認選擇 Ganache 創建的第一個賬戶地址。接下來我們點擊Create
就會將我們的智能合約部署到我們的測試網中。接下來 Remix 的頁面不要關閉,在后面編寫前端代碼時還要用到合約的地址以及ABI
信息。
安裝Web3
在這之前,先在終端創建我們的項目:
> mkdir info > cd info
接下來使用 node.js 的包管理工具 npm 初始化項目,創建package.json
文件,其中保存了項目需要的相關依賴環境。
> npm init
一路按回車直到項目創建完成。最后,運行下面命令安裝web.js:
> npm install web3
注意: 在實際安裝過程中我發現web3在安裝完成后并沒有 /node_modules/web3/dist/we3.min.js
文件,這個問題在 issue#1041中有體現,但官方好像一直沒解決。不過可以在這里下載所需的文件,解壓后將dist
文件夾的內容拷貝到 /node_modules/web3
路徑下。
創建 UI
在項目目錄下創建index.html
,在這里我們將創建基礎的 UI,功能包括name
和age
的輸入框,以及一個按鈕,這些將通過 jQuery 實現:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" type="text/css" href="main.css"> <script src="./node_modules/web3/dist/web3.min.js"></script> </head> <body> <div class="container"> <h1>Info Contract</h1> <h2 id="info"></h2> <label for="name" class="col-lg-2 control-label">Name</label> <input id="name" type="text"> <label for="name" class="col-lg-2 control-label">Age</label> <input id="age" type="text"> <button id="button">Update Info</button> </div> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script> // Our future code here.. </script> </body> </html>
接下來需要編寫main.css
文件設定基本的樣式:
body { background-color:#F0F0F0; padding: 2em; font-family: 'Raleway','Source Sans Pro', 'Arial'; } .container { width: 50%; margin: 0 auto; } label { display:block; margin-bottom:10px; } input { padding:10px; width: 50%; margin-bottom: 1em; } button { margin: 2em 0; padding: 1em 4em; display:block; } #info { padding:1em; background-color:#fff; margin: 1em 0; }
使用Web3與智能合約交互
UI 創建好之后,在<script>
標簽中間編寫web.js
的代碼與智能合約交互。首先創建web3
實例,并與我們的測試環境連接:
<script> if (typeof web3 !== 'undefined') { web3 = new Web3(web3.currentProvider); } else { // set the provider you want from Web3.providers web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545")); } </script>
這段代碼是web3.js Github提供的樣例,意思是如果web3
已經被定義,那么就可以直接當作我們的 provider 使用。如果沒有定義,則我們手動指定 provider。
這里可能會存在疑問:為什么 web3 會被事先定義呢?實際上,如果你使用類似 MetaMask(一個 Chrome 上的插件,迷你型以太坊錢包)這樣的軟件,provider 就會被自動植入。
在上面代碼的基礎上,接下來設置默認的以太坊賬戶:
web3.eth.defaultAccount = web3.eth.accounts[0];
在上文中我們使用 Ganache 已經創建了 10 個賬戶了,這里我們選擇第一個賬戶當作默認賬戶。
接下來需要讓我們的web3
知道我們的合約是什么樣的,這里需要用到合約的 ABI(Application Binary Interface)。ABI
可以使我們調用合約的函數,并且從合約中獲取數據。
在上文中我們已經在 Remix 中創建了我們的合約,這時重新回到 Remix,在 Compile 的 tab 下我們點擊Details
出現的頁面中我們可以拷貝合約的ABI
,如下圖所示。

將其復制到代碼中:
var infoContract = web3.eth.contract(PASTE ABI HERE!);
接下來轉到 run 的tab,拷貝合約的地址,將其復制到下面的代碼中:
var info = InfoContract.at('PASTE CONTRACT ADDRESS HERE');
完成這些我們就可以調用合約中的函數了,下面我們使用 jQuery 與我們的合約進行交互:
info.getInfo(function(error, result){ if(!error) { $("#info").html(result[0]+' ('+result[1]+' years old)'); console.log(result); } else console.error(error); }); $("#button").click(function() { info.setInfo($("#name").val(), $("#age").val()); });
以上的代碼就簡單地實現了對合約中兩個函數的調用,分別讀取和顯示name
和age
變量。
到此我們就完成了全部的代碼,完整代碼可以在 InfoContract 中找到。在瀏覽器中打開index.html
測試效果如下圖(輸入名字和年齡后刷新)。

本文的作者是蓋蓋,他的微信公眾號: chainlab
參考文獻
☛ 深入淺出區塊鏈 - 系統學習區塊鏈,打造最好的區塊鏈技術博客。