# **文件中心** 依赖关系 ![](https://box.kancloud.cn/6bedb50738156a0a03ce64e6a925804d_1739x684.png) ``` <!-- 资源服务器 --> <dependency> <groupId>com.open.capacity</groupId> <artifactId>security-core</artifactId> <version>${core.version}</version> </dependency> ``` 文件中心配置文件   支持阿里云oss,七牛oss两种配置 ``` aliyun:   oss:     access-key: LTAIMjvZWiXRuClW     accessKeySecret: YwJar7gkdZx3Q3Zk6TRuEAWaAz6n8y      endpoint: oss-cn-beijing.aliyuncs.com      bucketName: owenwangwen     domain: [https://owenwangwen.oss-cn-beijing.aliyuncs.com](https://owenwangwen.oss-cn-beijing.aliyuncs.com)qiniu:   oss:     access-key: owGiAWGn6DpU5zlrfLP4K9iQusahmspTW6PxRABW     accessKeySecret: 5CBWKFd1pP-OSiusd1Bvhokp-ih4i3bs2QA2r-U2     endpoint: [http://payo7kq4i.bkt.clouddn.com](http://payo7kq4i.bkt.clouddn.com)     bucketName: owenwangwen     ``` 文件存储配置 token校验redis配置 ``` spring:   application:     name: file-center   datasource:     dynamic:       enable: true     druid:       # JDBC 配置(驱动类自动从url的mysql识别,数据源类型自动识别)       core:         url: jdbc:mysql://127.0.0.1:3306/file\_center?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false         username: root         password: root         driver-class-name:  com.mysql.jdbc.Driver       log:         url: jdbc:mysql://127.0.0.1:3306/log-center?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false         username: root         password: root         driver-class-name:  com.mysql.jdbc.Driver   mybatis:   config-location: classpath:mybatis.cfg.xml   mapper-locations: classpath\*:com/central/\*\*/dao/\*.xml  security:   oauth2:     token:       store:         type: redis permit:   http\_urls:  /files-anon/\*\*  , /doc.html  ,/upload.html , /uploads.html ,/js/\*\* ,/document.html   oauth\_urls: /files-anon/\*\*  , /doc.html  ,/upload.html , /uploads.html ,/js/\*\* ,/document.html #设置最大超时时间 ribbon:     ReadTimeout: 16000     ConnectTimeout: 16000 #设置最大容错超时时间 hystrix:   command:     default:       execution:         timeout:           enabled: true         isolation:           thread:             timeoutInMilliseconds: 16000     logging:   level:     root: INFO     org.hibernate: INFO     org.hibernate.type.descriptor.sql.BasicBinder: TRACE     org.hibernate.type.descriptor.sql.BasicExtractor: TRACE ``` 七牛云,七牛云核心配置 ![](https://box.kancloud.cn/cf44ac3e04f702f399d69821f7e9363b_1727x647.png) 七牛云上传核心类 ![](https://box.kancloud.cn/29c024ee23404cccb6110de75752640f_1107x467.png) ## file-center 登录流程图 ![](https://box.kancloud.cn/7eea410bb58d317640e825e7a3e7c20e_588x703.png) ``` public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (authentication == null) { throw new InvalidTokenException("Invalid token (token not found)"); } String token = (String) authentication.getPrincipal(); OAuth2Authentication auth = tokenServices.loadAuthentication(token); if (auth == null) { throw new InvalidTokenException("Invalid token: " + token); } Collection<String> resourceIds = auth.getOAuth2Request().getResourceIds(); if (resourceId != null && resourceIds != null && !resourceIds.isEmpty() && !resourceIds.contains(resourceId)) { throw new OAuth2AccessDeniedException("Invalid token does not contain resource id (" + resourceId + ")"); } checkClientDetails(auth); if (authentication.getDetails() instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails(); // Guard against a cached copy of the same details if (!details.equals(auth.getDetails())) { // Preserve the authentication details from the one loaded by token services details.setDecodedDetails(auth.getDetails()); } } auth.setDetails(authentication.getDetails()); auth.setAuthenticated(true); return auth;