Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting up security in JAVA EE6 Webservice
    primarykey
    data
    text
    <p>I am currently researching how Java EE6 Security can secure our applications using GlassFish. I know how to make realms, roles and users. I managed to get a nice basic login with a servlet. 'Normal'users were not allowed to see an admin page, while an admin user was, so that test worked out nicely.</p> <p>Now however, I want to step a little bit deeper into it. </p> <p>The idea is that I host a webservice using an EJB container. This webservice does not know anything about it's callers so I figured the caller has to send credentials (username and password) along with the call. The webservice could then authenticate the user and could then, based on this, allow or deny access to methods.</p> <p>The thing is, that I have no clue on how to check 2 strings (username and password) and set up a role for the callers within the webservice.</p> <p>I know this API should help me out: <a href="http://docs.oracle.com/javaee/1.4/api/javax/ejb/EJBContext.html" rel="nofollow">http://docs.oracle.com/javaee/1.4/api/javax/ejb/EJBContext.html</a></p> <p>But it doesn't give me a clear understanding on how to do this. All it says to me is that I can check certain properties when the user is already in a role, but since it's a webservice, there is no role yet... I have to create it first, but how?</p> <p>Also, I know that GlassFish supports sign on through LDAP, which is the end goal I am working towards. Perhaps any ideas on how to do that correctly? What would be the best way to approach this all?</p> <p>Thanks in advance,</p> <p>Rens</p> <p>=============================================================================</p> <p>UPDATE/EDIT:</p> <p>Alright, since I could only comment, and couldn't reply, I figured I'd just edit my original post. Here we go:</p> <p>The idea is that I have to research Glassfish's EE6 Security for Webservices. Now... I read a lot about JAAS (Java Authetication Authorization Service). It works with annotations in the webservice bean like this:</p> <pre><code>@RolesAllowed("ADMIN") public String doAdminStuff(){ // do something } </code></pre> <p>I tried some stuff with a servlet, and that worked really great!! I have a basic authentication, which allowed the user to log in before accessing a webservice bean. The servlet web.xml took care of the setting as in describing which realm to check and which users were there etc. </p> <p>Now, I have to test it without a servlet though, because the idea is that the webservice is able to run without it knowing it's clients. So a client should provide username and password along with his call. I used an interceptor to do the login, and then checking if the user is authorized to acces the method using the @RolesALlowed annotation.</p> <p>This is the code: the webservice bean:</p> <pre><code>@LocalBean @WebService @Stateless public class EE6SecurityBean implements EE6SecurityBeanInterface { @Interceptors(UserValidationInterceptor.class) @RolesAllowed("ADMIN") public String doAdminStuff(String user, String password){ return "it works"; } } </code></pre> <p>Then the interceptor:</p> <pre><code>@Interceptor public class UserValidationInterceptor { private ProgrammaticLoginInterface programmaticLogin = new ProgrammaticLogin(); @AroundInvoke public Object intercept(InvocationContext ctx) throws Exception { // for all parameters List&lt;String&gt; list = new ArrayList&lt;String&gt;(); for (Object p : ctx.getParameters()) { list.add(p.toString()); } String username = list.get(0).toString(); String password = list.get(1).toString(); boolean loginSuccessful = programmaticLogin.login( username, password, "Developingjava", true); if (loginSuccessful) { return ctx.proceed(); }else{ throw new userValidationException(); } } } </code></pre> <p>Now this works fine if I comment the @RolesAllowed("ADMIN"), except that every user I configured in the 'Developingjava' realm can use that method. But if I use the @RolesAllowed("ADMIN"), I get the following error:</p> <p>INFO: JACC Policy Provider: Failed Permission Check, context(EE6SecurityEAR/EE6SecurityEJB_jar)- permission((javax.security.jacc.EJBMethodPermission EE6SecurityBean testWaarde,ServiceEndpoint,java.lang.String,java.lang.String))</p> <p>I have configured my sun-ejb-jar.xml like this (The servlet needed xml configuration, but I highly doubt the bean is even using it..):</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd"&gt; &lt;sun-ejb-jar&gt; &lt;security-role-mapping&gt; &lt;role-name&gt;ADMIN&lt;/role-name&gt; &lt;group-name&gt;Admin&lt;/group-name&gt; &lt;principal-name&gt;Admin&lt;/principal-name&gt; &lt;/security-role-mapping&gt; &lt;enterprise-beans&gt; &lt;unique-id&gt;1&lt;/unique-id&gt; &lt;ejb&gt; &lt;ejb-name&gt;EE6SecurityBean&lt;/ejb-name&gt; &lt;jndi-name&gt;&lt;/jndi-name&gt; &lt;pass-by-reference&gt;false&lt;/pass-by-reference&gt; &lt;ior-security-config&gt; &lt;transport-config&gt; &lt;integrity&gt;supported&lt;/integrity&gt; &lt;confidentiality&gt;supported&lt;/confidentiality&gt; &lt;establish-trust-in-target&gt;supported&lt;/establish-trust-in-target&gt; &lt;establish-trust-in-client&gt;supported&lt;/establish-trust-in-client&gt; &lt;/transport-config&gt; &lt;as-context&gt; &lt;auth-method&gt;username_password&lt;/auth-method&gt; &lt;realm&gt;Developingjava&lt;/realm&gt; &lt;required&gt;true&lt;/required&gt; &lt;/as-context&gt; &lt;sas-context&gt; &lt;caller-propagation&gt;supported&lt;/caller-propagation&gt; &lt;/sas-context&gt; &lt;/ior-security-config&gt; &lt;is-read-only-bean&gt;false&lt;/is-read-only-bean&gt; &lt;refresh-period-in-seconds&gt;-1&lt;/refresh-period-in-seconds&gt; &lt;gen-classes/&gt; &lt;/ejb&gt; &lt;/enterprise-beans&gt; &lt;/sun-ejb-jar&gt; </code></pre> <p>I really need help on this. Perhaps this is not the right way to deal with security for webservices at all, but my company wants me to do a research on new technology security of EE6... </p> <p>Any advice?</p> <p>Thanks in advance :) </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload