Skip to content

Commit

Permalink
adds offline_session_max_lifespan_enabled attribute to keycloak_realm…
Browse files Browse the repository at this point in the history
… resource (#377)
  • Loading branch information
pmellati authored Sep 18, 2020
1 parent a7aa1e8 commit 81e5fbc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
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 @@ -124,6 +124,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 @@ -249,6 +249,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 @@ -305,6 +305,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 @@ -715,6 +720,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 @@ -1022,6 +1031,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

0 comments on commit 81e5fbc

Please sign in to comment.