Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offline_session_max_lifespan_enabled attribute to realm #377

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs-old/resources/keycloak_realm.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ The attributes below should be specified as [Go duration strings](https://golang
- `sso_session_max_lifespan_remember_me` - (Optional) The maximum amount of time before a "remember me" session expires regardless of activity.
- `offline_session_idle_timeout` - (Optional) The amount of time an offline session can be idle before it expires.
- `offline_session_max_lifespan` - (Optional) The maximum amount of time before an offline session expires regardless of activity.
- `offline_session_max_lifespan_enabled` - (Optional) Enable `offline_session_max_lifespan`.
- `access_token_lifespan` - (Optional) The amount of time an access token can be used before it expires.
- `access_token_lifespan_for_implicit_flow` - (Optional) The amount of time an access token issued with the OpenID Connect Implicit Flow can be used before it expires.
- `access_code_lifespan` - (Optional) The maximum amount of time a client has to finish the authorization code flow.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/realm.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ The arguments below should be specified as [Go duration strings](https://golang.
- `sso_session_max_lifespan` - (Optional) The maximum amount of time before a session expires regardless of activity.
- `offline_session_idle_timeout` - (Optional) The amount of time an offline session can be idle before it expires.
- `offline_session_max_lifespan` - (Optional) The maximum amount of time before an offline session expires regardless of activity.
- `offline_session_max_lifespan_enabled` - (Optional) Enable `offline_session_max_lifespan`.
- `access_token_lifespan` - (Optional) The amount of time an access token can be used before it expires.
- `access_token_lifespan_for_implicit_flow` - (Optional) The amount of time an access token issued with the OpenID Connect Implicit Flow can be used before it expires.
- `access_code_lifespan` - (Optional) The maximum amount of time a client has to finish the authorization code flow.
Expand Down
1 change: 1 addition & 0 deletions keycloak/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Realm struct {
SsoSessionMaxLifespanRememberMe int `json:"ssoSessionMaxLifespanRememberMe,omitempty"`
OfflineSessionIdleTimeout int `json:"offlineSessionIdleTimeout,omitempty"`
OfflineSessionMaxLifespan int `json:"offlineSessionMaxLifespan,omitempty"`
OfflineSessionMaxLifespanEnabled bool `json:"offlineSessionMaxLifespanEnabled,omitempty"`
AccessTokenLifespan int `json:"accessTokenLifespan,omitempty"`
AccessTokenLifespanForImplicitFlow int `json:"accessTokenLifespanForImplicitFlow,omitempty"`
AccessCodeLifespan int `json:"accessCodeLifespan,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions provider/data_source_keycloak_realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func dataSourceKeycloakRealm() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"offline_session_max_lifespan_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"access_token_lifespan": {
Type: schema.TypeString,
Computed: true,
Expand Down
10 changes: 10 additions & 0 deletions provider/resource_keycloak_realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ func resourceKeycloakRealm() *schema.Resource {
Computed: true,
DiffSuppressFunc: suppressDurationStringDiff,
},
"offline_session_max_lifespan_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"access_token_lifespan": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -616,6 +621,10 @@ func getRealmFromData(data *schema.ResourceData) (*keycloak.Realm, error) {
realm.OfflineSessionMaxLifespan = offlineSessionMaxLifespanDurationString
}

if offlineSessionMaxLifespanEnabled, ok := data.GetOk("offline_session_max_lifespan_enabled"); ok {
realm.OfflineSessionMaxLifespanEnabled = offlineSessionMaxLifespanEnabled.(bool)
}

if accessTokenLifespan := data.Get("access_token_lifespan").(string); accessTokenLifespan != "" {
accessTokenLifespanDurationString, err := getSecondsFromDurationString(accessTokenLifespan)
if err != nil {
Expand Down Expand Up @@ -841,6 +850,7 @@ func setRealmData(data *schema.ResourceData, realm *keycloak.Realm) {
data.Set("sso_session_max_lifespan_remember_me", getDurationStringFromSeconds(realm.SsoSessionMaxLifespanRememberMe))
data.Set("offline_session_idle_timeout", getDurationStringFromSeconds(realm.OfflineSessionIdleTimeout))
data.Set("offline_session_max_lifespan", getDurationStringFromSeconds(realm.OfflineSessionMaxLifespan))
data.Set("offline_session_max_lifespan_enabled", realm.OfflineSessionMaxLifespanEnabled)
data.Set("access_token_lifespan", getDurationStringFromSeconds(realm.AccessTokenLifespan))
data.Set("access_token_lifespan_for_implicit_flow", getDurationStringFromSeconds(realm.AccessTokenLifespanForImplicitFlow))
data.Set("access_code_lifespan", getDurationStringFromSeconds(realm.AccessCodeLifespan))
Expand Down