1. 程式人生 > >解決SSO客戶端驗證錯誤String index out of range

解決SSO客戶端驗證錯誤String index out of range

看控臺的資訊是客戶端進行ticket的時候出錯了報錯資訊如下:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1911)
at org.jasig.cas.client.validation.Cas20ServiceTicketValidator.extractCustomAttributes(Cas20ServiceTicketValidator.java:145)
at org.jasig.cas.client.validation.Cas20ServiceTicketValidator.parseResponseFromServer(Cas20ServiceTicketValidator.java:98)


然後檢視原始碼發現是解析伺服器返回回來的資料出錯了,然後debug斷點檢視是他在每個<cas:xxx>裡面的value多了一個/n所以讀導致屬性值頁給讀取了。導致leftpos和rightpos都是-1,所以就報錯了,我想了好多一開始,什麼版本啊(也是剛入門這個東西),最後發現了問題,在服務端返給客戶端資料的時候是xml,也就是頁面,這個頁面是自己寫的。

 String attributesText = xml.substring(pos1 + 16, pos2);
/*     */ 
/* 134 */     Map attributes = new HashMap();
/* 135 */     BufferedReader br = new BufferedReader(new StringReader(attributesText));
/*     */ 
/*     */ 
/* 138 */     List attributeNames = new ArrayList();
/*     */     try {
/* 140 */       while ((line = br.readLine()) != null)      {        String line;
/* 141 */         String trimmedLine = line.trim();
/* 142 */         if (trimmedLine.length() > 0) {
/* 143 */           int leftPos = trimmedLine.indexOf(":");
/* 144 */           int rightPos = trimmedLine.indexOf(">");
/* 145 */           attributeNames.add(trimmedLine.substring(leftPos + 1, rightPos));
/*     */         }
/*     */       }
/* 148 */       br.close();
/*     */     }

我就找到了這個頁面發現他在頁面上key和value之間換行了,果斷髮現問題,把換行刪除,就不會多一個/n了,問題解決

<c:forEach items="${assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.attributes}"
var="attr">
<cas:${attr.key}>
${attr.value}
</cas:${attr.key}>
</c:forEach>


修改後

<c:forEach items="${assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.attributes}"
var="attr">
<cas:${attr.key}>${attr.value}</cas:${attr.key}>
</c:forEach>
</cas:attributes>


相關推薦

解決SSO客戶驗證錯誤String index out of range

看控臺的資訊是客戶端進行ticket的時候出錯了報錯資訊如下: java.lang.StringIndexOutOfBoundsException: String index out of range: -1at java.lang.String.substring(Str

MacOS 安裝MysqlDB 問題解決方案( 解決 IndexError: string index out of range

pip install MySQL-python時報錯如下: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/wk/541xl0m91gj7562sn0ddpjg9k8mh7p/T/pip

Spring Boot 啟動報錯 Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 37

work 結果 frame getc director inf 中文 getclass post 使用命令 java -jar springBoot.jar 啟動項目,結果報錯如下: Exception in thread "main" java.lang.String

java.lang.StringIndexOutOfBoundsException: String index out of range: -1

字串擷取下標越界   出錯程式碼 @GetMapping("/edit") //@RequiresPermissions("erp:enquirySheet:edit") public String edit( String enquiryNo,Model model){

java.lang.StringIndexOutOfBoundsException: String index out of range: 1

筆者原始碼如下: package javaPractice; import java.util.*; public class TestScanner { public static void main(String[] args) { Scanner sc = ne

trim()與String index out of range: 0

當使用trim()處理字串後,發現 String index out of range: 0報錯? 而且覺得程式碼無懈可擊?一時想不出來什麼時候會為空? 注意特殊情況處理的字元元素都是空格,eg:"        "。空格

關於hibernate查詢資料時報錯java.lang.StringIndexOutOfBoundsException: String index out of range: 0

今天學習struts2框架,重寫登入頁面,在登入時碰到這個問題,久久不能解決,後來用度娘一查,果斷出結果。 原文地址: 答案如下: 報錯:java.lang.StringIndexOutOfBoundsException: String index out of

Mybatis異常解決之:java.sql.SQLException: Parameter index out of range

mybatis使用過程中遇到下面一個異常: org.springframework.dao.TransientDataAccessResourceException: ### Error querying database. Cause: java.sql.SQLException: Param

String index out of range: -824264796 不明的原因導致驅動程式造成失敗,請回報這個例外。

報錯 2018-08-27 11:26:57.307 ERROR 7188 --- [eate-1016098114] com.alibaba.druid.pool.DruidDataSource

Django集成Xadmin list index out of range報錯解決方案

ren get 報錯解決 != del pic 錯誤提示 djang .py return self.render(context) File "C:\Python36\lib\site-packages\django\template\defaulttags

Python常見錯誤:IndexError: list index out of range

spa bsp lis 遍歷字典 pan nbsp exe 字典 dex 用python寫腳本查詢字典時,在遍歷字典時循環到某一項時老是報錯 出現這種錯誤有兩種情況: 第1種可能情況 list[index]index超出範圍 第2種可能情況 list是空值就會出現 In

富文字編輯器圖片上傳失敗的BUG解決:IndexError:list index out of range

富文字編輯器圖片上傳失敗的BUG解決 問題原因 我們將通過Django上傳的圖片儲存到了FastDFS中,而儲存在FastDFS中的檔名沒有後綴名(.png/.jpg/.jif),而ckeditor在處理上傳的檔名按照有後綴名來處理,所以會出現bug錯誤 解決方法 找到虛擬

Parameter index out of range 錯誤

Parameter index out of range  錯誤 最近學ssm框架的時候,遇到了這個錯誤,找了半天的原因,最後發現原來是sql語句中多了一對單引號。傳入值的型別為String型別,就以為還要加引號以表示傳入的是字串,其實是錯的,還是初學對其還不太瞭解。 如下

python使用format出現tuple index out of range報錯的可能原因及解決

關於python 使用format格式化輸出時出現IndexError: tuple index outof range報錯的原因及解決方法 本人python小白,希望用部落格記錄下自己犯的錯誤供自己日後程式設計和大家程式設計中參考和防範。 上圖是本人變成時出

很有必要看,這篇 解決 IndexError: list index out of range

執行邏輯迴歸程式碼,遭遇bug:Traceback (most recent call last): File "D:/DTLFolder/paperTest/Paper_logistic regression.py", line 92, in <module>

mybatis中Parameter index out of range (1 > number of parameters, which is 0).

超出 myba dex 小白 轉載 tro index out mybatis Parameter index out of range (1 > number of parameters, which is 0).(參數索引超出範圍) 在mybatis裏面寫就是應該

list assignment index out of range

pen assign 指定 erro 位置 lis out nbsp -s 現象 m1=[]for i in xrange(n):m1[i]=1 報錯:IndexError: list assignment index out of range 分析 空數組不能直接指定位

python IndexError: list assignment index out of range

在進行list的操作時報 IndexError: list assignment index out of range 故障解釋:索引錯誤:列表的索引分配超出列範圍 原始碼: list=[] list[0]='a' 輸出: IndexError: list assignment in

java.sql.SQLException:Parameter index out of range (1>number of parameters, which is 0)

  執行根據某條件查詢資料,報錯如下:   網上搜索了下,說是mysql預查詢語句中的問號個數和傳入的引數個數不符。再看自己的mybatis程式碼: <if test="model != null and model != ''">

java.sql.SQLException: Parameter index out of range

最近一個物聯網專案中遇到了java.sql.SQLException: Parameter index out of range的個問題.記下來: 模糊查詢報錯: ​java.sql.SQLException: Parameter index out of range .... at