前提
- CAS服务器安装完成(http://my.oschina.net/u/1264515/blog/181598)
- SONAR工具安装完成(http://my.oschina.net/u/1264515/blog/177862)
集成
- 插件下载
拷贝到extensions\plugins目录下
- 插件配置
conf/sonar.properties文件里添加如下参数
# this property must be set to true
sonar.authenticator.createUsers=true
# enable CAS plugin
sonar.security.realm=cas
# cas1, cas2 or saml11
sonar.cas.protocol=cas2
# Location of the CAS server login form, i.e. https://localhost:8443/cas/login
sonar.cas.casServerLoginUrl=http://localhost:8080/cas/login
# CAS server root URL, i.e. https://localhost:8443/cas
sonar.cas.casServerUrlPrefix=http://localhost:8080/cas
# Sonar server root URL, without ending slash
sonar.cas.sonarServerUrl=http://localhost:9000
# Optional CAS server logout URL. If set, sonar session will be deleted on CAS logout request.
#sonar.cas.casServerLogoutUrl=http://localhost:8080/cas/logout
# Specifies whether gateway=true should be sent to the CAS server. Default is false.
#sonar.cas.sendGateway=false
# The tolerance in milliseconds for drifting clocks when validating SAML 1.1 tickets.
# Note that 10 seconds should be more than enough for most environments that have NTP time synchronization.
# Default is 1000 milliseconds.
#sonar.cas.saml11.toleranceMilliseconds=1000
如果是基于sonar3.3版本之前,到此步骤已完成整合。
修复Sonar3.3版本后的兼容
这里有描述3.3版本后与CAS集成出现的问题http://jira.codehaus.org/browse/SONARPLUGINS/component/15492
情况是从首页点击登录按钮后可以跳转到CAS进行验证,但回调回来依旧还是没登录。这个问题引起的原因还是不清楚,比如
- session没有保存在cookie中
I replaced the java_servlets_store by a cookie_store in environment.rb and it works fine.
I guess the problem comes from jruby-rack.
- 升级了JRuby and Rails
下面是我们的解决办法,可能比较笨
- 修改SONAR登录按钮跳转地址
打开web/WEB-INF/app/views/layouts/_layout.html.erb, 修改第38行如下
<li><a href="<%= ApplicationController.root_context -%>/koala"><%= message('layout.login') -%></a></li>
注意:跳转链接中koala地址与你在第二步骤定义的跳转控制器定义的名称一致
- 添加一个跳转控制器
在web/WEB-INF/app/controllers/目录下添加文件:koala_controller.rb,内容如下
class KoalaController < ApplicationController
SECTION=Navigation::SECTION_CONFIGURATION
before_filter :admin_required, :except => ['new', 'signup', 'autocomplete']
skip_before_filter :check_authentication, :only => ['new', 'signup', 'autocomplete']
def index
redirect_back_or_default(home_url)
end
end