Defined Type: jboss::user

Defined in:
manifests/user.pp

Overview

Define: jboss::user

This define to add and remove JBoss management and application users, manage their passwords and roles.

Parameters:

password

**Required parameter.** This is password that will be used for user.

ensure

Standard ensure parameter. Can be either ‘present` or `absent`.

user

(namevar) Name of user to manage.

realm

This is by default equal to ‘ManagementRealm`. It can be equal also to `ApplicationRealm`.

roles

This is by default equal to ‘undef`. You can pass a list of roles in form of string delimited by `,` sign.

Parameters:

  • password (Any)
  • ensure (Any) (defaults to: 'present')
  • user (Any) (defaults to: $name)
  • realm (Any) (defaults to: 'ManagementRealm')
  • roles (Any) (defaults to: undef)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'manifests/user.pp', line 18

define jboss::user (
  $password,
  $ensure     = 'present',
  $user       = $name,
  $realm      = 'ManagementRealm',
  $roles      = undef,
) {

  include jboss
  require jboss::internal::package
  include jboss::internal::service
  include jboss::internal::params
  include jboss::internal::relationship::module_user

  $home = $jboss::home

  $dir = $jboss::runasdomain ? {
    true    => 'domain',
    default => 'standalone',
  }

  # application realm or normal
  $application_realm = $realm ? {
    'ApplicationRealm' => true,
    default            => false,
  }

  # -a is needed to set in application-users.properties file
  if ($application_realm) {
    $extraarg = '-a'
  }

  $file = $application_realm ? {
    true    => 'application-users.properties',
    default => 'mgmt-users.properties',
  }

  $filepath = "${home}/${dir}/configuration/${file}"
  $filepath_roles = "${home}/${dir}/configuration/application-roles.properties"
  $jbossuserfix = '2>&1 | awk \'BEGIN{a=0}{if (/Error/){a=1};print}END{if (a==1) exit 1}\''
  Exec {
    path => $jboss::internal::params::syspath,
  }

  case $ensure {
    'present': {
      $rolesstr = $roles ? {
        undef   => '',
        default => "--roles '${roles}'"
      }
      # By default the properties realm expects the entries to be in the format: -
      # username=HEX( MD5( username ':' realm ':' password))
      $mangledpasswd = md5("${name}:${realm}:${password}")
      $command_1 = "${home}/bin/add-user.sh --silent --user '${name}' --password \"\$__PASSWD\""
      $command_2 = " --realm '${realm}' ${rolesstr} ${extraarg} ${jbossuserfix}"
      exec { "jboss::user::add(${realm}/${name})":
        environment => [
          "JBOSS_HOME=${home}",
          "__PASSWD=${password}"
        ],
        command     => "${command_1}${command_2}",
        unless      => "/bin/egrep -e '^${name}=${mangledpasswd}' ${filepath}",
        require     => [
          Anchor['jboss::package::end'],
          Anchor['jboss::internal::relationship::module_user'],
        ],
        notify      => Service[$jboss::internal::service::servicename],
        logoutput   => true,
      }
      if $application_realm {
        file_line { "jboss::user::roles::add(${realm}/${name})":
          ensure  => present,
          path    => $filepath_roles,
          line    => "${name}=${roles}",
          match   => "${name}=.*",
          require => [
            Exec["jboss::user::add(${realm}/${name})"],
            Anchor['jboss::internal::relationship::module_user'],
          ],
          notify  => Service[$jboss::internal::service::servicename],
        }
      }
    }
    'absent':{
      exec { "jboss::user::remove(${realm}/${name})":
        command   => "/bin/sed -iE 's/^${name}=.*$//g' ${filepath}",
        onlyif    => "/bin/egrep -e '^${name}=' ${filepath}",
        require   => [
          Anchor['jboss::package::end'],
          Anchor['jboss::internal::relationship::module_user'],
        ],
        logoutput => 'on_failure',
        notify    => Service[$jboss::internal::service::servicename],
      }
      if $application_realm {
        exec { "jboss::user::roles::remove(${realm}/${name})":
          command   => "/bin/sed -iE 's/^${name}=.*$//g' ${filepath_roles}",
          onlyif    => "/bin/egrep -e '^${name}=' ${filepath_roles}",
          require   => [
            Anchor['jboss::package::end'],
            Anchor['jboss::internal::relationship::module_user'],
          ],
          logoutput => 'on_failure',
          notify    => Service[$jboss::internal::service::servicename],
        }
      }
    }
    default: {
      fail("Ensure must be eiter present or absent, provided: `${ensure}`!")
    }
  }

}