关于alfresco代码跟踪之security服务.doc

上传人:laozhun 文档编号:2386618 上传时间:2023-02-17 格式:DOC 页数:63 大小:458.50KB
返回 下载 相关 举报
关于alfresco代码跟踪之security服务.doc_第1页
第1页 / 共63页
关于alfresco代码跟踪之security服务.doc_第2页
第2页 / 共63页
关于alfresco代码跟踪之security服务.doc_第3页
第3页 / 共63页
关于alfresco代码跟踪之security服务.doc_第4页
第4页 / 共63页
关于alfresco代码跟踪之security服务.doc_第5页
第5页 / 共63页
点击查看更多>>
资源描述

《关于alfresco代码跟踪之security服务.doc》由会员分享,可在线阅读,更多相关《关于alfresco代码跟踪之security服务.doc(63页珍藏版)》请在三一办公上搜索。

1、1 安全的实现安全wiki安全的保证时机是在调用public services的时候实施的,访问控制是通过元数据而不是硬编码实现的,就是通过使用acegi和aop实现的。安全控制可以基于 :方法访问;提供给方法的参数;以及调用方法返回值。安全是通过一下五个关键服务完成的。the Authentication Service、the Authority Service、the Ownable Service、the Permission Service、the Person Service。访问控制通过检查当前用户授予的authority所拥有的permission和permission gro

2、up允许或者禁止人员执行操作一个特定对象的方法。例如NodeService bean readProperties方法在调用方法之前检查当前用户是否有读当前节点的属性的访问权限。在SearchService服务中,查询的结果值返回用户有read permission权限的节点(对返回结果进行过滤)。对公共服务的访问控制定义在 public-services-context.xml,每个服务都定义一个方法interceptor bean实现对方法调用的安全控制,通常这些定义在public-services-security-context.xml。1.1 定义方法级别的安全在public-ser

3、vices-security-context.xml 中定义了支持基于acegi的security around method invocation。这个配置了两个alfresco特定的bean:一个voter可以基于对于当前操作参数授予当前用户的permission的方法调用,一个after invocation provider用来为返回值加上安全。方法访问按照普通的acegi方式定义,但是附加一些内容。一下?代表authority,#代表方法参数索引 *前置判断是如下形式:ACL_METHOD.? Access to the method is restricted to those w

4、ith the given authority in alfresco. This could be a user name or group. Dynamic authorities are not supported ACL_NODE.#.* Access control is restricted to users who have the the specified permission for the node on the identified argument. If the argument is a NodeRef it will be used; if it is a St

5、oreRef then the root node for the store will be used; if it is a ChildAssociationRef then the child node will be used. ACL_PARENT.#.* Access control is restricted to users who have the the specified permission for the parent of the node on the identified argument. If the argument is a NodeRef the pa

6、rent of the node will be used; if it is a ChildAssociationRef then the parent node will be used. ROLE_. Check for an acegi authority starting with ROLE_ GROUP_. Check for an acegi authority starting with GROUP_ If more than one ACL_NODE.#.* or ACL_PARENT.#.* entry is present then all the permissions

7、 must be available for the method to execute. 后置判断采取如下形式:AFTER_ACL_NODE.* Similar to ACL_NODE.#.* but the restriction applies to the return argument. The supported return types are ChildAssociationRef, FileInfo, NodeRef, StoreRef, ResultSet; Collections and arrays of StoreRef, NodeRef, ChildAssociat

8、ionRef, and FileInfo. AFTER_ACL_PARENT.* Similar to ACL_PARENT.#.* but the restriction applies to the return argument. The supported return types are ChildAssociationRef, FileInfo, NodeRef, StoreRef, ResultSet; Collections and arrays of StoreRef, NodeRef, ChildAssociationRef, and FileInfo. 2 authent

9、ication服务。1. alfresco把认证了的用户信息acegi的authentication对象放入当前线程,这样就不用在认证了。在认证之后会返回给客户端一个ticket,每次调用的时候只需要和当前线程的authentication进行比较,不需要在进行认证一次浪费资源;如果当前线程没有authentication信息的时候才会调用认证组件进行认证;2. 对于用户authentication信息以及生成的ticket信息都会放入缓存中,ticket是根据用户名以及一些其他的用户信息生成的,这样保证不会url假冒;3. 如果对authentication是怎么存在线程里面不理解的,可以参

10、考acegi的context以及contextholder部分;4. 由于很多操作,对与当前线程绑定的authentication人来说是无权做的,所以要更改authentication信息,从而使用具有更高权限的人来做,这个就是 String currentUser = AuthenticationUtil.getRunAsUser();AuthenticationUtil.setRunAsUser(currentUser);的用处,如果不理解,可以看看acegirunasmanager一部分内容。2.1 子系统说明从alfresco3开始认证部分是用来subsystem(子系统)的概念,认

11、证系统是由子系统完成的。在alfresco中由于安全部分使用了acegi,所以认证的处理也包含两部分内容,一部分是用于提供acegi的authenticationManager,另外一部分就是认证服务的接口authenticationservice,这两部分的底层代码相同,都是使用了subsystem。但是subsystem的实现不同,authenticationservice使用了 localAuthenticationService 属性指名了使用localAuthenticationService,这个从repository库进行认证。而在authenticationDao中(用于ace

12、gi的authenticationManager)没有配置sourceBeanName属性,这是因为在经过authenticationservice认证后,在acegi安全判断的过程就不需要认证了。2.2 总图2.3 关于authenticationService2.3.1 用户登录 这部分使用jsp页面来完成的,用户进入系统后的首页为context/index.jsp。/ get the start location as configured by the web-client configWebApplicationContext context = WebApplicationCont

13、extUtils.getRequiredWebApplicationContext(session.getServletContext();ConfigService configService = (ConfigService)context.getBean(webClientConfigService);ClientConfigElement configElement = (ClientConfigElement)configService.getGlobalConfig().getConfigElement(client);String location = configElement

14、.getInitialLocation();AuthenticationService authService = (AuthenticationService)context.getBean(AuthenticationService);/ override with the users preference if they have oneUser user = (User)session.getAttribute(AuthenticationHelper.AUTHENTICATION_USER);if (user != null) UserTransaction tx = (Transa

15、ctionService)context.getBean(TransactionService).getUserTransaction(); tx.begin();try authService.validate(user.getTicket(); / ensure construction of the FacesContext before attemping a service call FacesContext fc = FacesHelper.getFacesContext(request, response, application); String preference = (S

16、tring)PreferencesService.getPreferences(fc).getValue(start-location); if (preference != null) location = preference; mit(); catch (AuthenticationException authErr) try tx.rollback(); catch (Throwable tex) / expired ticket AuthenticationService unpAuth = (AuthenticationService)context.getBean(authent

17、icationService); unpAuth.invalidateTicket(unpAuth.getCurrentTicket(); unpAuth.clearCurrentSecurityContext(); catch (Throwable e) try tx.rollback(); catch (Throwable tex) elseUserTransaction tx = (TransactionService)context.getBean(TransactionService).getUserTransaction(); tx.begin();try authService.

18、authenticateAsGuest();PersonService personService = (PersonService)context.getBean(personService); NodeRef guestRef = personService.getPerson(PermissionService.GUEST_AUTHORITY); user = new User(authService.getCurrentUserName(), authService.getCurrentTicket(), guestRef); session.setAttribute(Authenti

19、cationHelper.AUTHENTICATION_USER, user); / ensure construction of the FacesContext before attemping a service call FacesContext fc = FacesHelper.getFacesContext(request, response, application); String preference = (String)PreferencesService.getPreferences(session).getValue(start-location); if (prefe

20、rence != null) location = preference; session.removeAttribute(AuthenticationHelper.AUTHENTICATION_USER); mit(); catch (Throwable e) try tx.rollback(); catch (Throwable tex) if (request.getMethod().equalsIgnoreCase(GET) if (NavigationBean.LOCATION_MYALFRESCO.equals(location) / Clear previous location

21、 - Fixes the issue ADB-61 FacesContext fc = FacesHelper.getFacesContext(request, response, application); if (fc != null) NavigationBean navigationBean = (NavigationBean)FacesHelper.getManagedBean(fc, NavigationBean); if (navigationBean != null) navigationBean.setLocation(null); navigationBean.setToo

22、lbarLocation(null); / Send redirect response.sendRedirect(request.getContextPath() + /faces/jsp/dashboards/container.jsp); else response.sendRedirect(request.getContextPath() + /faces/jsp/browse/browse.jsp); / route WebDAV requestselse if (request.getMethod().equalsIgnoreCase(PROPFIND) | request.get

23、Method().equalsIgnoreCase(OPTIONS) response.sendRedirect(request.getContextPath() + /webdav/);这段代码不难理解了就是获取到公共服务的AuthenticationService authService = (AuthenticationService)context.getBean(AuthenticationService);注意这里bean的名字是大写” AuthenticationService”,这个bean的定义位于public-service-context.xml,是一个公共服务。因为这个

24、服务是使用了aop对authenticationService服务(定义在authentication-context.xml中)的封装2.3.2 公共服务定义公共服务定义如下:位于配置文件public- services -context.xml org.alfresco.service.cmr.security.AuthenticationService 2.3.3 关于目标target这个步骤是使用配置服务读取webclient的配置信息决定哪些文件支持在线编辑。配置文件位于authentication-services-context.xml。 localAuthenticationS

25、ervice 这里使用了子系统SubsystemChainingAuthenticationService,这里的applicationContextManager为Authentication。认证接口有3个实现,一个是基本的实现,另外一个是对基本实现的链式包装,第三个就是使用链式子系统对认证进行包装。这个链式子系统在提供更改认证的方法的时候就是使用sourceBeanName配置的bean名字也就是名字为localAuthenticationService的bean配置的实现。对于链式认证则包含localAuthenticationService于其它配置的bean。默认使用的是alfre

26、scoNtlm下的localAuthenticationService,其实使用的就是存储库进行认证。2.3.4 截断器2.3.4.1 AuthenticationService_transaction事物截断器,很好理解了。定义如下:位于配置文件public- services -context.xml PROPAGATION_NOT_SUPPORTED, readOnly PROPAGATION_NOT_SUPPORTED, readOnly PROPAGATION_NOT_SUPPORTED, readOnly PROPAGATION_NOT_SUPPORTED, readOnly PR

27、OPAGATION_NOT_SUPPORTED, readOnly PROPAGATION_NOT_SUPPORTED, readOnly $server.transaction.mode.default 2.3.4.2 AuditMethodInterceptor审计追踪截断器,也很好理解了。定义如下:位于配置文件public-service-context.xml false 2.3.4.3 exceptionTranslator异常处理截断器,也很好理解了。定义如下:位于配置文件public- services -context.xml false 2.3.4.4 Authenticat

28、ionService_security这个截断器类使用的是net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor这个截断器,如果不懂可以看acegi的文档,这个截断器是acegi的安全截断器,用到了authenticationManager、accessDecisionManager、afterInvocationManager等所有构成安全部分的组件。因为在认证服务中不仅是包含了获取用户认证信息的操作,还包括了创建认证、更新认证、设置认证、删除深证、封禁/解禁认证、等这些只有管理员才能做的操作,所

29、以这个截断器是保证这些操作只有ACL_METHOD.ROLE_ADMINISTRATOR权限的人才能操作。定义如下:位于配置文件public-services-security-context.xml org.alfresco.service.cmr.security.AuthenticationService.createAuthentication=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.updateAuthentication=ACL_ALLOW org.a

30、lfresco.service.cmr.security.AuthenticationService.setAuthentication=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.deleteAuthentication=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.setAuthenticationEnabled=ACL_METHOD.RO

31、LE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.getAuthenticationEnabled=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.authenticationExists=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.getCurren

32、tUserName=ACL_ALLOW org.alfresco.service.cmr.security.AuthenticationService.invalidateUserSession=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.invalidateTicket=ACL_ALLOW org.alfresco.service.cmr.security.AuthenticationService.getCurrentTicket=ACL_ALLOW org.al

33、fresco.service.cmr.security.AuthenticationService.clearCurrentSecurityContext=ACL_ALLOW org.alfresco.service.cmr.security.AuthenticationService.isCurrentUserTheSystemUser=ACL_ALLOW org.alfresco.service.cmr.security.AuthenticationService.guestUserAuthenticationAllowed=ACL_ALLOW org.alfresco.service.c

34、mr.security.AuthenticationService.getDomains=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.getDomainsThatAllowUserCreation=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.getDomainsThatAllowUserDeletion=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthenticationService.getDomiansThatAllowUserPasswordChanges=ACL_METHOD.ROLE_ADMINISTRATOR 2.4 关于acegi authenticationManager2.4.1 配置文件位于authentication-services-cont

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号