SyntaxHighlighter JS

2015-09-19

Change the username and password of Apache Karaf admin user

What you will do:
  • Change the username and password for Apache Karaf admin user
What you will learn:
  • Overwrite default Karaf configuration files
  • Use Maven filtered resources
Please see the post "Create a custom Apache Karaf server" for the initial setup.

By default, the admin user has the username/password of karaf/karaf.  For branding purposes, we want to rename the username/password of dekantar/dekantar .

Step 1: Define username/password
Define the username/password as Maven properties in the pom.xml

<properties>
    <dekantar.username>dekantar</dekantar.username>
    <dekantar.password>dekantar</dekantar.password>
</properties>

Step 2: Turn on Maven filtered resources
Filtered resource will substitute Maven variables in text files with the property values

<resources>
<resource>
    <directory>src/main/resources</directory>
    <filtering>false</filtering>
    <includes>
    <include>**/*</include>
    </includes>
</resource>
<resource>
    <directory>src/main/filtered-resources</directory>
    <filtering>true</filtering>
    <includes>
    <include>**/*</include>
    </includes>
</resource>
</resources>
The filtering is true property turns on variable substitution in the src/main/filtered-resources directory.


Step 3: Overwrite default Karaf security file
The default Karaf security file is etc/user.properties. To overwrite, create the file src/main/filtered-resources/etc/user.properties.

The content of etc/user.properties is

${dekantar.username} = ${dekantar.password},_g_:admingroup
_g_\:admingroup = group,admin,manager,viewer,webconsole

The variable substitution results in the output

dekantar = dekantar,_g_:admingroup
_g_\:admingroup = group,admin,manager,viewer,webconsole

Don't worry about the clear text password. Karaf will automatically encrypt it on first login.


Step 4: Test it
After building the Karaf server, start it via command

cd $KARAF_DIR/bin
./start

Then log in with the new username

ssh dekantar@localhost -p8101

No comments:

Post a Comment