WebSphere Tutorial · WebSphere Liberty · Lesson 10 of 23
Security in Liberty
Authentication and authorisation in Liberty: user registries, application security roles, TLS keystores, and single sign-on options.
Pieces of Liberty security
appSecurity-5.0turns on Jakarta Security; applications declare roles and protected URLs.- A user registry:
basicRegistryfor tests,ldapRegistryfor corporate directories, or federation. - Role bindings map application roles to users or groups in
<application-bnd>. - TLS with
transportSecurity-1.0, a<keyStore>for the server's certificate and a truststore for outbound calls. - Single sign-on with LTPA tokens between Liberty servers, or modern options:
openidConnectClient-1.0(log in through an identity provider) andmpJwt-2.1(accept JWTs on APIs).
<featureManager>
<feature>appSecurity-5.0</feature>
<feature>transportSecurity-1.0</feature>
<feature>mpJwt-2.1</feature>
</featureManager>
<ldapRegistry host="ldap.example.com" port="636" sslEnabled="true" baseDN="dc=example,dc=com" ldapType="Microsoft Active Directory"
bindDN="${env.LDAP_BIND_DN}" bindPassword="${env.LDAP_BIND_PASSWORD}"/>
<keyStore id="defaultKeyStore" location="key.p12" password="${env.KEYSTORE_PASSWORD}"/>
bindings = {"admin": {"group:billing-admins"}, "viewer": {"group:billing-admins", "group:finance"}}
user_groups = {"ana": {"group:finance"}, "raj": {"group:billing-admins"}, "zoe": set()}
constraints = {"/billing/report": "viewer", "/billing/refund": "admin"}
for user, groups in user_groups.items():
for url, role in constraints.items():
allowed = bool(groups & bindings[role])
print(f"{user:4} {url:16} needs {role:6} -> {'allowed' if allowed else '403 Forbidden'}")
Output
ana /billing/report needs viewer -> allowed ana /billing/refund needs admin -> 403 Forbidden raj /billing/report needs viewer -> allowed raj /billing/refund needs admin -> allowed zoe /billing/report needs viewer -> 403 Forbidden zoe /billing/refund needs admin -> 403 Forbidden
Test yourself
Which Liberty feature lets REST APIs accept JSON Web Tokens?
jdbcmpJwtmpHealthjsonb
Show answer
Answer: mpJwt
MicroProfile JWT authenticates requests with signed JWTs.