从Spring OAuth2 YML中提取常用值

时间:2018-04-26 14:26:20

标签: spring spring-boot spring-security oauth-2.0 spring-security-oauth2

我有以下带有OAuth2配置的.yml文件:

spring:
  security:
    oauth2:
      client:
        registration:
          evesso:
            client-id: xxxxxx
            client-secret: yyyyyy
            authorizationGrantType: authorization_code
            response_type: code
            redirectUriTemplate: http://localhost:8080/login/oauth2/code/
            scope: esi-location.read_location.v1
            clientName: EVE SSO
          evessostats:
            client-id: xxxxxx
            client-secret: yyyyyy
            authorizationGrantType: authorization_code
            response_type: code
            redirectUriTemplate: http://localhost:8080/login/oauth2/code/
            scope: esi-location.read_location.v1,esi-clones.read_implants.v1,esi-skills.read_skills.v1
            clientName: EVE SSO
          evessofc:
            client-id: xxxxxx
            client-secret: yyyyyy
            authorizationGrantType: authorization_code
            response_type: code
            redirectUriTemplate: http://localhost:8080/login/oauth2/code/
            scope: esi-location.read_location.v1,esi-clones.read_implants.v1,esi-skills.read_skills.v1,esi-fleets.read_fleet.v1,esi-fleets.write_fleet.v1
            clientName: EVE SSO
        provider:
          evesso:
            authorization-uri: https://login.eveonline.com/oauth/authorize
            token-uri: https://login.eveonline.com/oauth/token
            user-info-uri: https://login.eveonline.com/oauth/verify
            user-name-attribute: CharacterName
          evessostats:
            authorization-uri: https://login.eveonline.com/oauth/authorize
            token-uri: https://login.eveonline.com/oauth/token
            user-info-uri: https://login.eveonline.com/oauth/verify
            user-name-attribute: CharacterName
          evessofc:
            authorization-uri: https://login.eveonline.com/oauth/authorize
            token-uri: https://login.eveonline.com/oauth/token
            user-info-uri: https://login.eveonline.com/oauth/verify
            user-name-attribute: CharacterName

正如您所看到的那样,冗余数据太多了。有什么方法可以减少它吗?

1 个答案:

答案 0 :(得分:0)

据我所知,如果不使用代码,就无法显着缩小.propertiesserver: port: 8080 url: http://localhost:${server.port} oauth2-redirect-url: ${url}/login/oauth2/code/ oauth2-client-id: xxxxxx oauth2-client-secret: yyyyyy spring: security: oauth2: client: registration: evesso: client-id: ${oauth2-client-id} client-secret: ${oauth2-client-secret} authorizationGrantType: authorization_code response_type: code redirectUriTemplate: ${oauth2-redirect-url} scope: esi-location.read_location.v1 clientName: EVE SSO evessostats: client-id: ${oauth2-client-id} client-secret: ${oauth2-client-secret} authorizationGrantType: authorization_code response_type: code redirectUriTemplate: ${oauth2-redirect-url} scope: esi-location.read_location.v1,esi-clones.read_implants.v1,esi-skills.read_skills.v1 clientName: EVE SSO evessofc: client-id: ${oauth2-client-id} client-secret: ${oauth2-client-secret} authorizationGrantType: authorization_code response_type: code redirectUriTemplate: ${oauth2-redirect-url} scope: esi-location.read_location.v1,esi-clones.read_implants.v1,esi-skills.read_skills.v1,esi-fleets.read_fleet.v1,esi-fleets.write_fleet.v1 clientName: EVE SSO 配置的大小。

但是,您仍然可以通过对重复的键字符串进行分组来显着改善您的配置。

E.g。

server.port

虽然这不会保存线条,但是添加额外的线条,它会更加清晰。如果您必须更改端口,则只需更改redirectUriTemplate,而不是更改每个application-oauth.yml

注意:我只在某些字段中显示结果,但您可以将其应用于具有重复字符串的每个值(例如范围,提供者uri等)。< / em>的

您还可以将配置拆分为不同的文件(例如,所有oauth2配置都可以在spring.profiles.active中),然后使用spring: profiles: active: oauth2 包含该文件:

Sub GetFilePath()

Dim objFSO As New FileSystemObject, w As String, wb As Workbook

Application.ScreenUpdating = False

Set myFile = Application.FileDialog(msoFileDialogOpen)
With myFile
    .Title = "Choose File"
    .AllowMultiSelect = False
    If .Show <> -1 Then
        Exit Sub
    End If
    Set wb = Workbooks.Open(.SelectedItems(1))
End With

w = InputBox("Enter sheet name")

If SheetExists(w) Then
    wb.Sheets(w).Range("B2:B5").Copy
    ThisWorkbook.Sheets("Compare").Range("A1").pastespecial xlvalues
Else
    MsgBox "Sheet not found"
End If

wb.Close False

Application.ScreenUpdating = True

End Sub

Function SheetExists(s As String) As Boolean

Dim x    
On Error GoTo NextSheet
x = ActiveWorkbook.Sheets(SheetName).Name
SheetExists = True
Exit Function    
NextSheet:
    SheetExists = False    
End Function

但即使你这样做,我仍然建议你也使用我上面提到的第一个建议,因为这样可以将重复的值最小化到最低限度。