views:

267

answers:

2

Hello, is it possible to authenticate programmatically a user in J2ee 6?

Let me explain with some more details:

I've got an existing Java SE project with Servlets and hibernate; where I manage manually all the authentication and access control:

class Authenticator {
    int Id
    string username
}

Authenticator login(string username, string password) ;

void doListData(Authenticator auth) {
    if (isLoggedIn(auth)) listData();
    else doListError
}

void doUpdateData (Authenticator auth) {
    if (isLoggedAsAdmin(auth)) updateData() ;
    else doListError();
}

void doListError () {
    listError() ;
}

And Im integrating J2ee/jpa/servlet 3/... (Glassfish 3) in this project.

I've seen anotations like :

@RolesAllowed ("viewer")
void doListdata (...) {
    istData() ;
}

@RolesAllowed("admin")
void doUpdateData (...) {
    updateData() ;
}

@PermotAll
void dolisterror () {
    listerror() ;
}

but how can I manually state, in login(), that my user is in the admin and/or viewer role?

A: 

Hi this is covered pretty well in the sun java ee 6 tutorial.

Justin
A: 

Thank you for your ansers, I took a while to understand it, but you're both right,

login(java.lang.String user, java.lang.String password) 

is what I want to do. Instead of login in my users, I need to login a specific role:

login("admin", "admin") ;
...

:)

Edit your original question if you want to provide feedback or a more detailed question. Or add comments to specific answers.
ewernli
Thanks, I was a bit confused with two accounts (I thought first post was anonymous and therefore not editable)
Kevin