Wildfly 15 get EJBContext in Singleton from jax rs logged in user
I want to get the caller principal in an singleton from the logged in user. the user is authenticating against the rest service with username/password
the security domain is in the jboss-web.xml in the war
<security-domain>application-security</security-domain>
The endpoint in the war is:
@Path("/message/{message}")
public class MyRessource
{
@EJB
MySingleton singletonBean;
@GET
public Response resource(@PathParam("message") String message)
{
singletonBean.printText(message);
System.out.println("called from: " + ctx.getUserPrincipal().getName());
}
the singleton is in an own project, and is provided as dependency at the war.
@Stateless
public class MySingletonBean implements MySingleton
{
@Resource
EJBContext context;
@Resource
SessionContext ctx;
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName() + " SessionContext: " + ctx.getCallerPrincipal().getName());
}
}
my web.xml:
<web-app>
<security-role>
<role-name>Admin</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
standalone-full-ha.xml
<subsystem xmlns="urn:wildfly:elytron:5.0" ...>
[...]
<security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper">
<realm name="application-properties"/>
</security-domain>
[...]
</subsystem>
[...]
<http-authentication-factory name="application-security-http" security-domain="application-security" http-server-mechanism-factory="global">
<mechanism-configuration>
<mechanism mechanism-name="BASIC"/>
</mechanism-configuration>
</http-authentication-factory>
[...]
<security-domains>
<security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper">
<realm name="application-properties"/>
</security-domain>
[...]
</security-domains>
[...]
<subsystem xmlns="urn:jboss:domain:security:2.0">
<security-domains>
<security-domain name="application-security">
<authentication>
<login-module code="UsersRoles" flag="required">
<module-option name="usersProperties" value="file://${jboss.server.config.dir}/context-users.properties"/>
<module-option name="rolesProperties" value="file://${jboss.server.config.dir}/context-roles.properties"/>
</login-module>
</authentication>
</security-domain>
[...]
</subsystem>
[...]
<subsystem xmlns="urn:boss:domain:undertow"...>
<application-security-domains>
<application-security-domain name="application-security" http-authentication-factory="application-security-http"/>
</application-security-domains>
[...]
</subsystem>
But i always get anonymous as principals.
What did i do wrong?
java java-ee ejb wildfly javabeans
|
show 3 more comments
I want to get the caller principal in an singleton from the logged in user. the user is authenticating against the rest service with username/password
the security domain is in the jboss-web.xml in the war
<security-domain>application-security</security-domain>
The endpoint in the war is:
@Path("/message/{message}")
public class MyRessource
{
@EJB
MySingleton singletonBean;
@GET
public Response resource(@PathParam("message") String message)
{
singletonBean.printText(message);
System.out.println("called from: " + ctx.getUserPrincipal().getName());
}
the singleton is in an own project, and is provided as dependency at the war.
@Stateless
public class MySingletonBean implements MySingleton
{
@Resource
EJBContext context;
@Resource
SessionContext ctx;
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName() + " SessionContext: " + ctx.getCallerPrincipal().getName());
}
}
my web.xml:
<web-app>
<security-role>
<role-name>Admin</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
standalone-full-ha.xml
<subsystem xmlns="urn:wildfly:elytron:5.0" ...>
[...]
<security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper">
<realm name="application-properties"/>
</security-domain>
[...]
</subsystem>
[...]
<http-authentication-factory name="application-security-http" security-domain="application-security" http-server-mechanism-factory="global">
<mechanism-configuration>
<mechanism mechanism-name="BASIC"/>
</mechanism-configuration>
</http-authentication-factory>
[...]
<security-domains>
<security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper">
<realm name="application-properties"/>
</security-domain>
[...]
</security-domains>
[...]
<subsystem xmlns="urn:jboss:domain:security:2.0">
<security-domains>
<security-domain name="application-security">
<authentication>
<login-module code="UsersRoles" flag="required">
<module-option name="usersProperties" value="file://${jboss.server.config.dir}/context-users.properties"/>
<module-option name="rolesProperties" value="file://${jboss.server.config.dir}/context-roles.properties"/>
</login-module>
</authentication>
</security-domain>
[...]
</subsystem>
[...]
<subsystem xmlns="urn:boss:domain:undertow"...>
<application-security-domains>
<application-security-domain name="application-security" http-authentication-factory="application-security-http"/>
</application-security-domains>
[...]
</subsystem>
But i always get anonymous as principals.
What did i do wrong?
java java-ee ejb wildfly javabeans
Do you have any security configuration in your web.xml? Typically you will only see a Principal when the accessed resource has been protected by a security constraint.
– Steve C
Jan 17 at 1:49
yes, my web.xml contains the security-role, the security-constraint and the login-config.
– auryn31
Jan 17 at 9:41
1
Please add these snippets to your question
– Steve C
Jan 17 at 13:23
i added the web.xml content
– auryn31
Jan 17 at 13:37
1
Please show your security configuration in WildFly
– Steve C
Jan 17 at 13:44
|
show 3 more comments
I want to get the caller principal in an singleton from the logged in user. the user is authenticating against the rest service with username/password
the security domain is in the jboss-web.xml in the war
<security-domain>application-security</security-domain>
The endpoint in the war is:
@Path("/message/{message}")
public class MyRessource
{
@EJB
MySingleton singletonBean;
@GET
public Response resource(@PathParam("message") String message)
{
singletonBean.printText(message);
System.out.println("called from: " + ctx.getUserPrincipal().getName());
}
the singleton is in an own project, and is provided as dependency at the war.
@Stateless
public class MySingletonBean implements MySingleton
{
@Resource
EJBContext context;
@Resource
SessionContext ctx;
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName() + " SessionContext: " + ctx.getCallerPrincipal().getName());
}
}
my web.xml:
<web-app>
<security-role>
<role-name>Admin</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
standalone-full-ha.xml
<subsystem xmlns="urn:wildfly:elytron:5.0" ...>
[...]
<security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper">
<realm name="application-properties"/>
</security-domain>
[...]
</subsystem>
[...]
<http-authentication-factory name="application-security-http" security-domain="application-security" http-server-mechanism-factory="global">
<mechanism-configuration>
<mechanism mechanism-name="BASIC"/>
</mechanism-configuration>
</http-authentication-factory>
[...]
<security-domains>
<security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper">
<realm name="application-properties"/>
</security-domain>
[...]
</security-domains>
[...]
<subsystem xmlns="urn:jboss:domain:security:2.0">
<security-domains>
<security-domain name="application-security">
<authentication>
<login-module code="UsersRoles" flag="required">
<module-option name="usersProperties" value="file://${jboss.server.config.dir}/context-users.properties"/>
<module-option name="rolesProperties" value="file://${jboss.server.config.dir}/context-roles.properties"/>
</login-module>
</authentication>
</security-domain>
[...]
</subsystem>
[...]
<subsystem xmlns="urn:boss:domain:undertow"...>
<application-security-domains>
<application-security-domain name="application-security" http-authentication-factory="application-security-http"/>
</application-security-domains>
[...]
</subsystem>
But i always get anonymous as principals.
What did i do wrong?
java java-ee ejb wildfly javabeans
I want to get the caller principal in an singleton from the logged in user. the user is authenticating against the rest service with username/password
the security domain is in the jboss-web.xml in the war
<security-domain>application-security</security-domain>
The endpoint in the war is:
@Path("/message/{message}")
public class MyRessource
{
@EJB
MySingleton singletonBean;
@GET
public Response resource(@PathParam("message") String message)
{
singletonBean.printText(message);
System.out.println("called from: " + ctx.getUserPrincipal().getName());
}
the singleton is in an own project, and is provided as dependency at the war.
@Stateless
public class MySingletonBean implements MySingleton
{
@Resource
EJBContext context;
@Resource
SessionContext ctx;
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName() + " SessionContext: " + ctx.getCallerPrincipal().getName());
}
}
my web.xml:
<web-app>
<security-role>
<role-name>Admin</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
standalone-full-ha.xml
<subsystem xmlns="urn:wildfly:elytron:5.0" ...>
[...]
<security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper">
<realm name="application-properties"/>
</security-domain>
[...]
</subsystem>
[...]
<http-authentication-factory name="application-security-http" security-domain="application-security" http-server-mechanism-factory="global">
<mechanism-configuration>
<mechanism mechanism-name="BASIC"/>
</mechanism-configuration>
</http-authentication-factory>
[...]
<security-domains>
<security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper">
<realm name="application-properties"/>
</security-domain>
[...]
</security-domains>
[...]
<subsystem xmlns="urn:jboss:domain:security:2.0">
<security-domains>
<security-domain name="application-security">
<authentication>
<login-module code="UsersRoles" flag="required">
<module-option name="usersProperties" value="file://${jboss.server.config.dir}/context-users.properties"/>
<module-option name="rolesProperties" value="file://${jboss.server.config.dir}/context-roles.properties"/>
</login-module>
</authentication>
</security-domain>
[...]
</subsystem>
[...]
<subsystem xmlns="urn:boss:domain:undertow"...>
<application-security-domains>
<application-security-domain name="application-security" http-authentication-factory="application-security-http"/>
</application-security-domains>
[...]
</subsystem>
But i always get anonymous as principals.
What did i do wrong?
java java-ee ejb wildfly javabeans
java java-ee ejb wildfly javabeans
edited Jan 17 at 14:31
auryn31
asked Jan 16 at 14:36
auryn31auryn31
359117
359117
Do you have any security configuration in your web.xml? Typically you will only see a Principal when the accessed resource has been protected by a security constraint.
– Steve C
Jan 17 at 1:49
yes, my web.xml contains the security-role, the security-constraint and the login-config.
– auryn31
Jan 17 at 9:41
1
Please add these snippets to your question
– Steve C
Jan 17 at 13:23
i added the web.xml content
– auryn31
Jan 17 at 13:37
1
Please show your security configuration in WildFly
– Steve C
Jan 17 at 13:44
|
show 3 more comments
Do you have any security configuration in your web.xml? Typically you will only see a Principal when the accessed resource has been protected by a security constraint.
– Steve C
Jan 17 at 1:49
yes, my web.xml contains the security-role, the security-constraint and the login-config.
– auryn31
Jan 17 at 9:41
1
Please add these snippets to your question
– Steve C
Jan 17 at 13:23
i added the web.xml content
– auryn31
Jan 17 at 13:37
1
Please show your security configuration in WildFly
– Steve C
Jan 17 at 13:44
Do you have any security configuration in your web.xml? Typically you will only see a Principal when the accessed resource has been protected by a security constraint.
– Steve C
Jan 17 at 1:49
Do you have any security configuration in your web.xml? Typically you will only see a Principal when the accessed resource has been protected by a security constraint.
– Steve C
Jan 17 at 1:49
yes, my web.xml contains the security-role, the security-constraint and the login-config.
– auryn31
Jan 17 at 9:41
yes, my web.xml contains the security-role, the security-constraint and the login-config.
– auryn31
Jan 17 at 9:41
1
1
Please add these snippets to your question
– Steve C
Jan 17 at 13:23
Please add these snippets to your question
– Steve C
Jan 17 at 13:23
i added the web.xml content
– auryn31
Jan 17 at 13:37
i added the web.xml content
– auryn31
Jan 17 at 13:37
1
1
Please show your security configuration in WildFly
– Steve C
Jan 17 at 13:44
Please show your security configuration in WildFly
– Steve C
Jan 17 at 13:44
|
show 3 more comments
1 Answer
1
active
oldest
votes
You have at least three problems here:
<subsystem xmlns="urn:jboss:domain:security:2.0">
is a legacy configuration element that does not link up with elytron;You are completely missing the ejb3 security configuration;
Your EJB method is not protected with
@RolesAllowed(...)
.
I got a similar example working:
Create an elytron properties realm:
/subsystem=elytron/properties-realm=DemoPropsRealm:add(groups-attribute=groups,
groups-properties={
path=demo-roles.properties,relative-to=jboss.server.config.dir},
users-properties={
path=demo-users.properties,relative-to=jboss.server.config.dir,plain-text=true})
Create an elytron security domain:
/subsystem=elytron/security-domain=DemoDomain:add(
realms=[{realm=DemoPropsRealm,role-decoder=groups-to-roles}],
default-realm=DemoPropsRealm,permission-mapper=default-permission-mapper)
Create an elytron http-authentication factory that is mapped to our DemoDomain:
/subsystem=elytron/http-authentication-factory=demo-http-auth:add(
http-server-mechanism-factory=global,
security-domain=DemoDomain,
mechanism-configurations=[{
mechanism-name=BASIC,
mechanism-realm-configurations=[{
realm-name=DemoApplicationDomain
}]
}])
Map an ejb3 subsystem application security domain to our DemoDomain
/subsystem=ejb3/application-security-domain=
DemoApplicationDomain:add(security-domain=DemoDomain)
Link an undertow subsystem application security domain to our http-authentication-factory:
/subsystem=undertow/application-security-domain=
DemoApplicationDomain:add(http-authentication-factory=demo-http-auth)
"DemoApplicationDomain" will be the realm name in the
login-config
element of the web.xml and thesecurity-domain
in the jboss-web.xml file.
Declare the permitted roles on your EJB method:
@RolesAllowed("Admin")
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName()
+ " SessionContext: " + ctx.getCallerPrincipal().getName());
}
Example source is in GitHub at jax-rs-basic-auth.
Thanks a lot for your help!!!!
– auryn31
Jan 22 at 9:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54219391%2fwildfly-15-get-ejbcontext-in-singleton-from-jax-rs-logged-in-user%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have at least three problems here:
<subsystem xmlns="urn:jboss:domain:security:2.0">
is a legacy configuration element that does not link up with elytron;You are completely missing the ejb3 security configuration;
Your EJB method is not protected with
@RolesAllowed(...)
.
I got a similar example working:
Create an elytron properties realm:
/subsystem=elytron/properties-realm=DemoPropsRealm:add(groups-attribute=groups,
groups-properties={
path=demo-roles.properties,relative-to=jboss.server.config.dir},
users-properties={
path=demo-users.properties,relative-to=jboss.server.config.dir,plain-text=true})
Create an elytron security domain:
/subsystem=elytron/security-domain=DemoDomain:add(
realms=[{realm=DemoPropsRealm,role-decoder=groups-to-roles}],
default-realm=DemoPropsRealm,permission-mapper=default-permission-mapper)
Create an elytron http-authentication factory that is mapped to our DemoDomain:
/subsystem=elytron/http-authentication-factory=demo-http-auth:add(
http-server-mechanism-factory=global,
security-domain=DemoDomain,
mechanism-configurations=[{
mechanism-name=BASIC,
mechanism-realm-configurations=[{
realm-name=DemoApplicationDomain
}]
}])
Map an ejb3 subsystem application security domain to our DemoDomain
/subsystem=ejb3/application-security-domain=
DemoApplicationDomain:add(security-domain=DemoDomain)
Link an undertow subsystem application security domain to our http-authentication-factory:
/subsystem=undertow/application-security-domain=
DemoApplicationDomain:add(http-authentication-factory=demo-http-auth)
"DemoApplicationDomain" will be the realm name in the
login-config
element of the web.xml and thesecurity-domain
in the jboss-web.xml file.
Declare the permitted roles on your EJB method:
@RolesAllowed("Admin")
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName()
+ " SessionContext: " + ctx.getCallerPrincipal().getName());
}
Example source is in GitHub at jax-rs-basic-auth.
Thanks a lot for your help!!!!
– auryn31
Jan 22 at 9:23
add a comment |
You have at least three problems here:
<subsystem xmlns="urn:jboss:domain:security:2.0">
is a legacy configuration element that does not link up with elytron;You are completely missing the ejb3 security configuration;
Your EJB method is not protected with
@RolesAllowed(...)
.
I got a similar example working:
Create an elytron properties realm:
/subsystem=elytron/properties-realm=DemoPropsRealm:add(groups-attribute=groups,
groups-properties={
path=demo-roles.properties,relative-to=jboss.server.config.dir},
users-properties={
path=demo-users.properties,relative-to=jboss.server.config.dir,plain-text=true})
Create an elytron security domain:
/subsystem=elytron/security-domain=DemoDomain:add(
realms=[{realm=DemoPropsRealm,role-decoder=groups-to-roles}],
default-realm=DemoPropsRealm,permission-mapper=default-permission-mapper)
Create an elytron http-authentication factory that is mapped to our DemoDomain:
/subsystem=elytron/http-authentication-factory=demo-http-auth:add(
http-server-mechanism-factory=global,
security-domain=DemoDomain,
mechanism-configurations=[{
mechanism-name=BASIC,
mechanism-realm-configurations=[{
realm-name=DemoApplicationDomain
}]
}])
Map an ejb3 subsystem application security domain to our DemoDomain
/subsystem=ejb3/application-security-domain=
DemoApplicationDomain:add(security-domain=DemoDomain)
Link an undertow subsystem application security domain to our http-authentication-factory:
/subsystem=undertow/application-security-domain=
DemoApplicationDomain:add(http-authentication-factory=demo-http-auth)
"DemoApplicationDomain" will be the realm name in the
login-config
element of the web.xml and thesecurity-domain
in the jboss-web.xml file.
Declare the permitted roles on your EJB method:
@RolesAllowed("Admin")
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName()
+ " SessionContext: " + ctx.getCallerPrincipal().getName());
}
Example source is in GitHub at jax-rs-basic-auth.
Thanks a lot for your help!!!!
– auryn31
Jan 22 at 9:23
add a comment |
You have at least three problems here:
<subsystem xmlns="urn:jboss:domain:security:2.0">
is a legacy configuration element that does not link up with elytron;You are completely missing the ejb3 security configuration;
Your EJB method is not protected with
@RolesAllowed(...)
.
I got a similar example working:
Create an elytron properties realm:
/subsystem=elytron/properties-realm=DemoPropsRealm:add(groups-attribute=groups,
groups-properties={
path=demo-roles.properties,relative-to=jboss.server.config.dir},
users-properties={
path=demo-users.properties,relative-to=jboss.server.config.dir,plain-text=true})
Create an elytron security domain:
/subsystem=elytron/security-domain=DemoDomain:add(
realms=[{realm=DemoPropsRealm,role-decoder=groups-to-roles}],
default-realm=DemoPropsRealm,permission-mapper=default-permission-mapper)
Create an elytron http-authentication factory that is mapped to our DemoDomain:
/subsystem=elytron/http-authentication-factory=demo-http-auth:add(
http-server-mechanism-factory=global,
security-domain=DemoDomain,
mechanism-configurations=[{
mechanism-name=BASIC,
mechanism-realm-configurations=[{
realm-name=DemoApplicationDomain
}]
}])
Map an ejb3 subsystem application security domain to our DemoDomain
/subsystem=ejb3/application-security-domain=
DemoApplicationDomain:add(security-domain=DemoDomain)
Link an undertow subsystem application security domain to our http-authentication-factory:
/subsystem=undertow/application-security-domain=
DemoApplicationDomain:add(http-authentication-factory=demo-http-auth)
"DemoApplicationDomain" will be the realm name in the
login-config
element of the web.xml and thesecurity-domain
in the jboss-web.xml file.
Declare the permitted roles on your EJB method:
@RolesAllowed("Admin")
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName()
+ " SessionContext: " + ctx.getCallerPrincipal().getName());
}
Example source is in GitHub at jax-rs-basic-auth.
You have at least three problems here:
<subsystem xmlns="urn:jboss:domain:security:2.0">
is a legacy configuration element that does not link up with elytron;You are completely missing the ejb3 security configuration;
Your EJB method is not protected with
@RolesAllowed(...)
.
I got a similar example working:
Create an elytron properties realm:
/subsystem=elytron/properties-realm=DemoPropsRealm:add(groups-attribute=groups,
groups-properties={
path=demo-roles.properties,relative-to=jboss.server.config.dir},
users-properties={
path=demo-users.properties,relative-to=jboss.server.config.dir,plain-text=true})
Create an elytron security domain:
/subsystem=elytron/security-domain=DemoDomain:add(
realms=[{realm=DemoPropsRealm,role-decoder=groups-to-roles}],
default-realm=DemoPropsRealm,permission-mapper=default-permission-mapper)
Create an elytron http-authentication factory that is mapped to our DemoDomain:
/subsystem=elytron/http-authentication-factory=demo-http-auth:add(
http-server-mechanism-factory=global,
security-domain=DemoDomain,
mechanism-configurations=[{
mechanism-name=BASIC,
mechanism-realm-configurations=[{
realm-name=DemoApplicationDomain
}]
}])
Map an ejb3 subsystem application security domain to our DemoDomain
/subsystem=ejb3/application-security-domain=
DemoApplicationDomain:add(security-domain=DemoDomain)
Link an undertow subsystem application security domain to our http-authentication-factory:
/subsystem=undertow/application-security-domain=
DemoApplicationDomain:add(http-authentication-factory=demo-http-auth)
"DemoApplicationDomain" will be the realm name in the
login-config
element of the web.xml and thesecurity-domain
in the jboss-web.xml file.
Declare the permitted roles on your EJB method:
@RolesAllowed("Admin")
public void printText(String text) {
System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName()
+ " SessionContext: " + ctx.getCallerPrincipal().getName());
}
Example source is in GitHub at jax-rs-basic-auth.
edited Jan 20 at 7:11
answered Jan 20 at 6:42
Steve CSteve C
14.3k42032
14.3k42032
Thanks a lot for your help!!!!
– auryn31
Jan 22 at 9:23
add a comment |
Thanks a lot for your help!!!!
– auryn31
Jan 22 at 9:23
Thanks a lot for your help!!!!
– auryn31
Jan 22 at 9:23
Thanks a lot for your help!!!!
– auryn31
Jan 22 at 9:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54219391%2fwildfly-15-get-ejbcontext-in-singleton-from-jax-rs-logged-in-user%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you have any security configuration in your web.xml? Typically you will only see a Principal when the accessed resource has been protected by a security constraint.
– Steve C
Jan 17 at 1:49
yes, my web.xml contains the security-role, the security-constraint and the login-config.
– auryn31
Jan 17 at 9:41
1
Please add these snippets to your question
– Steve C
Jan 17 at 13:23
i added the web.xml content
– auryn31
Jan 17 at 13:37
1
Please show your security configuration in WildFly
– Steve C
Jan 17 at 13:44