三、深入了解
  该插件从2011年10月发布1.1.2版本后不再维护了,因此会有一些小问题,但不影响使用,比如在分配角色后点击保存按钮时有可能会发生异常,浏览器点击后退按钮后重新提交可以操作成功。
  另外如果配置失败导致不能登录,可以通过修改配置文件恢复初始设置。
  首先了解一下配置文件。
  进入jenkins安装目录,用户配置信息和角色配置信息都以配置文件的形式存储。

  上图中users目录存放了各个用户的配置信息,每个用户都会创建与用户名相同的文件夹,文件夹中包含config.xml文件,配置示例如下:
<?xml version='1.0' encoding='UTF-8'?>
<user>
<fullName>admin</fullName>
<properties>
<jenkins.security.ApiTokenProperty>
<apiToken>EfowsOP9H5arYxMmuFrbPjjITgu/fjtvHib5okFJ9DmPTu/088cvHxlE9RHwVv+S</apiToken>
</jenkins.security.ApiTokenProperty>
<hudson.model.MyViewsProperty>
<views>
<hudson.model.AllView>
<owner class="hudson.model.MyViewsProperty" reference="http://www.cnblogs.com/.."/>
<name>All</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
</hudson.model.AllView>
</views>
</hudson.model.MyViewsProperty>
<hudson.search.UserSearchProperty>
<insensitiveSearch>false</insensitiveSearch>
</hudson.search.UserSearchProperty>
<hudson.security.HudsonPrivateSecurityRealm_-Details>
<passwordHash>uAEYii:02e0cd0d78abf90e42b28e7d3d4fe64776ae8fa9500e379f2598cc65e1b0fb70</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>
<hudson.tasks.Mailer_-UserProperty>
<emailAddress>gaoliang@esrichina.com.cn</emailAddress>
</hudson.tasks.Mailer_-UserProperty>
</properties>
</user>
  角色配置在$Jenkins_home/config.xml文件中,示例如下:
<useSecurity>true</useSecurity>
<authorizationStrategy class="com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy">
<roleMap type="globalRoles">
<role name="admin" pattern=".*">
<permissions>
<permission>hudson.model.Hudson.Read</permission>
<permission>hudson.model.Hudson.Administer</permission>
<permission>hudson.model.View.Delete</permission>
<permission>hudson.model.Computer.Create</permission>
<permission>hudson.model.Computer.Delete</permission>
<permission>hudson.model.Hudson.RunScripts</permission>
<permission>hudson.model.View.Read</permission>
<permission>hudson.model.Run.Update</permission>
<permission>hudson.model.Item.Workspace</permission>
<permission>hudson.model.Computer.Connect</permission>
<permission>hudson.model.Computer.Configure</permission>
<permission>hudson.model.Item.Cancel</permission>
<permission>hudson.model.Item.Configure</permission>
<permission>hudson.model.Item.Discover</permission>
<permission>hudson.model.Item.Create</permission>
<permission>hudson.model.View.Configure</permission>
<permission>hudson.model.Computer.Disconnect</permission>
<permission>hudson.model.Item.Delete</permission>
<permission>hudson.model.Item.Read</permission>
<permission>hudson.model.Item.Build</permission>
<permission>hudson.model.Run.Delete</permission>
<permission>hudson.model.View.Create</permission>
<permission>hudson.scm.SCM.Tag</permission>
</permissions>
<assignedSIDs>
<sid>admin</sid>
</assignedSIDs>
</role>
<role name="anonymous" pattern=".*">
<permissions>
<permission>hudson.model.Hudson.Read</permission>
</permissions>
<assignedSIDs>
<sid>anonymous</sid>
</assignedSIDs>
</role>
</roleMap>
<roleMap type="projectRoles">
<role name="Online Program" pattern="GeoQPortal|GeoQUserPortal">
<permissions>
<permission>hudson.model.Item.Read</permission>
<permission>hudson.model.Item.Build</permission>
<permission>hudson.model.Run.Delete</permission>
<permission>hudson.model.Item.Workspace</permission>
<permission>hudson.model.Run.Update</permission>
<permission>hudson.scm.SCM.Tag</permission>
<permission>hudson.model.Item.Cancel</permission>
<permission>hudson.model.Item.Discover</permission>
</permissions>
<assignedSIDs>
<sid>caox</sid>
<sid>wangwh</sid>
<sid>yuh</sid>
<sid>chenjj</sid>
<sid>lim</sid>
<sid>zhangy</sid>
</assignedSIDs>
</role>
<role name="test" pattern="Compress">
<permissions>
<permission>hudson.model.Item.Delete</permission>
<permission>hudson.model.Item.Read</permission>
<permission>hudson.model.Item.Build</permission>
<permission>hudson.model.Run.Delete</permission>
<permission>hudson.model.Item.Workspace</permission>
<permission>hudson.model.Run.Update</permission>
<permission>hudson.scm.SCM.Tag</permission>
<permission>hudson.model.Item.Cancel</permission>
<permission>hudson.model.Item.Configure</permission>
<permission>hudson.model.Item.Discover</permission>
</permissions>
<assignedSIDs>
<sid>wangwh</sid>
</assignedSIDs>
</role>
</roleMap>
</authorizationStrategy>
<securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
<disableSignup>false</disableSignup>
<enableCaptcha>false</enableCaptcha>
</securityRealm>
  如果发生用户不能登录的情况,可以尝试以下几种方法解决
  1、方法1
  删除用户相关的目录
  修改$Jenkins_home/config.xml文件:<useSecurity>false</useSecurity>
  删除authorizationStrategy、securityRealm节点
  重新启动Jenkins
  使用该方法将删除Jenkins的权限管理,恢复成为初始状态。
  2、方法2
  修改$Jenkins_home/config.xml文件,修改授权方式为系统自带的安全矩阵方式
  authorizationStrategy节点class属性修改为hudson.security.GlobalMatrixAuthorizationStrategy
  配置示例如下,该示例是分配给admin用户所有权限
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.GlobalMatrixAuthorizationStrategy">
<permission>hudson.model.Computer.Configure:admin</permission>
<permission>hudson.model.Computer.Connect:admin</permission>
<permission>hudson.model.Computer.Create:admin</permission>
<permission>hudson.model.Computer.Delete:admin</permission>
<permission>hudson.model.Computer.Disconnect:admin</permission>
<permission>hudson.model.Hudson.Administer:admin</permission>
<permission>hudson.model.Hudson.Read:admin</permission>
<permission>hudson.model.Hudson.Read:anonymous</permission>
<permission>hudson.model.Hudson.RunScripts:admin</permission>
<permission>hudson.model.Item.Build:admin</permission>
<permission>hudson.model.Item.Cancel:admin</permission>
<permission>hudson.model.Item.Configure:admin</permission>
<permission>hudson.model.Item.Create:admin</permission>
<permission>hudson.model.Item.Delete:admin</permission>
<permission>hudson.model.Item.Discover:admin</permission>
<permission>hudson.model.Item.Read:admin</permission>
<permission>hudson.model.Item.Workspace:admin</permission>
<permission>hudson.model.Run.Delete:admin</permission>
<permission>hudson.model.Run.Update:admin</permission>
<permission>hudson.model.View.Configure:admin</permission>
<permission>hudson.model.View.Create:admin</permission>
<permission>hudson.model.View.Delete:admin</permission>
<permission>hudson.model.View.Read:admin</permission>
<permission>hudson.scm.SCM.Tag:admin</permission>
</authorizationStrategy>
<securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
<disableSignup>false</disableSignup>
<enableCaptcha>false</enableCaptcha>
</securityRealm>
  重新启动Jenkins
  使用该方法Jenkins将恢复为安全矩阵方式授权。