开发者

how to do authenticate in REST web service using jersey and java

how to do authentication in REST web service using jersey framework and java? I used NetBean IDE and create Rest web service, the application server is glassfish. I don't use javadb or derby. My database is mongodb. I have google and i found http://weblog开发者_运维技巧s.java.net/blog/mhadley/archive/2008/03/authentication.html. But that site described he used derby database. How should i configure in web.xml for authenticate?


You can as well use file realm of glassfish to test if your code & basic authentication works. For that add your users into file realm and modify your configuration in web.xml:

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>file</realm-name>
</login-config>
<security-role>
    <description/>
    <role-name>USERS</role-name>
</security-role>

Later you can switch to jdbc realm and add jdbc data source to use with mongodb and realm.


The page you link to will let you make authentication work, even if your application uses another db. You would then have user credentials in a separate db (derby in that case, but you are free to use any db for which you have a jdbc driver).

You could also use another 'realm' for authentication. If you just have a couple of users and don't need to change their username/password from application code, you could just use 'filerealm' in glassfish.

You could also design your own realm, but that's more work. You could find some blog entries about that, or just find some inspiration in Glassfish source code.

I don't think you can use the referenced 'jdbcrealm' for mongodb, as I don't think there is a full jdbc driver for it (as that probably wouldn't make sense, mongodb being a document-oriented database and not a relational one). If you really need your users and groups to be defined in mongodb, you should write a custom realm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜