單點登入之cas整合sonar的配置方法詳解

大雄45發表於2022-04-11
導讀 這篇文章主要介紹了單點登入之cas整合sonar的相關知識,本文透過示例程式碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑑價值,需要的朋友可以參考下
一、修改 sonar 配置 conf/sonar.properties

修改 sonar 配置檔案 conf/sonar.properties:

sonar.security.realm = cas                                                                                                                                                                                                                                                                            
sonar.authenticator.createUsers = true                                                                                                              
#sonar.cas.forceCasLogin = true                                                                                                                     
sonar.cas.protocol = cas3                                                                                                                           
sonar.cas.casServerUrlPrefix = http://192.168.1.58:8080/cas                                                                                         
sonar.cas.casServerLoginUrl = http://192.168.1.58:8080/cas/login                                                                    
sonar.cas.casServerLogoutUrl = http://192.168.1.58:8080/cas/logout                                                                  
sonar.cas.sonarServerUrl = http://192.168.1.35:9200                                              
sonar.cas.urlAfterCasRedirectCookieMaxAgeSeconds = 300            
sonar.cas.sessionStorePath = /opt/sonarqube/data/sonarcas/sessionstore        
sonar.cas.sessionStore.cleanUpIntervalInSeconds = 1800                                    
                                                                                               
# Specifies whether gateway=true should be sent to the CAS server. Default is false.                                                
# sonar.cas.sendGateway                                                                       
                                                                                     
# Specifies how SonarQube groups should be replicated. A value of "CAS" always overwrites the user's local groups with                     
# the group provided by CAS upon UI log-in. The user's local groups will be untouched, f. i. with the value "sonarqube".
# Defaults to "CAS".                                                                                                    
sonar.cas.groupReplication = CAS                                                                                                   
sonar.cas.rolesAttributes = groups                                                                                      
sonar.cas.fullNameAttribute = displayName                                                                               
sonar.cas.eMailAttribute = mail                                                                                                                    
sonar.cas.saml11.toleranceMilliseconds = 1000                                                                           
sonar.cas.disableCertValidation = true
二、下載外掛 sonar-cas-plugin

下載外掛 sonar-cas-plugin,將外掛複製至 sonar 的 extentions/plugins 目錄下,並重啟 sonar 服務。

下載連結:

單點登入之cas整合sonar的配置方法詳解單點登入之cas整合sonar的配置方法詳解

三、修改 cas 配置檔案 application.yml

修改 cas 配置檔案 application.yml,修改內容如下:

# Application properties that need to be
# embedded within the web application can be included here
cas:
  authn:
    jdbc:
      query:
      - dialect: org.hibernate.dialect.MySQLDialect
        driverClass: com.mysql.jdbc.Driver
        fieldPassword: password
        password: 'xxxxxx'
        sql: select * from user where user_name=?
        url: jdbc:mysql://192.168.1.32:3306/cas?useUnicode=true&characterEncoding=utf-8&useSSL=false
        user: root
  serviceRegistry:
    initFromJson: true
  tgc:
    secure: false
四、修改 cas 配置檔案 HTTPSandIMAPS-10000001.json

新增 cas/WEB-INF/classes/services/HTTPSandIMAPS-10000001.json 檔案,新增 http 支援:

{
  "@class" : "org.apereo.cas.services.RegexRegisteredService",
  "serviceId" : "^(https?|http?|imaps?)://.*",
  "name" : "All",
  "id" : 10000000,
  "description" : "This service definition authorizes all application urls that support HTTPS and IMAPS protocols.",
  "evaluationOrder" : 10000,
  "proxyPolicy" : {
    "@class" : "org.apereo.cas.services.RegexMatchingRegisteredServiceProxyPolicy",
    "pattern" : "^(https?|http?|imaps?)://.*"
  },
  "usernameAttributeProvider" : {
    "@class" : "org.apereo.cas.services.DefaultRegisteredServiceUsernameProvider"
  },
  "attributeReleasePolicy" : {
    "@class" : "org.apereo.cas.services.ReturnAllAttributeReleasePolicy"
  }
}

到此這篇關於單點登入之cas整合sonar的文章就介紹到這了。

原文來自:

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69955379/viewspace-2886397/,如需轉載,請註明出處,否則將追究法律責任。

相關文章