Java EE 6 Programmatic security, glassfish and JDBC realm -
i'm exploring pure java ee ways of doing programmatic security, login users, based on jdbc realm glassfish server.
so basically, in login servlet i'm doing
string username = request.getparameter("username"); string password = request.getparameter("password"); try { request.login(username, password); ....
without doing in web.xml, default realm (file) used. don't want that, want use jdbcrealm named jdbcsecurerealm.
so i'm adding following web.xml
<login-config> <auth-method>form</auth-method> <realm-name>jdbcsecurerealm</realm-name> </login-config>
note don't add form-login-config define form-login-page , form-error-page.
then if define security constraints such as
<security-constraint> <web-resource-collection> <web-resource-name>admin pages</web-resource-name> <description></description> <url-pattern>/admin/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>administrator</role-name> </auth-constraint> </security-constraint>
well... works ! request.login checks against jdbcrealm , if try access secured pages without being logged in i'm getting nice 403.
but seems i'm mixing declarative security , programmatic security, because feel shouldn't declaring inside web.xml rather using request.isuserinrole.
question:
am hitting glassfish specific behaviour, or allowed use programmatic security (request.login) jdbc realm defined inside web.xml without form-login-config ?
update i've seen there possibility specify realm inside glassfish-application.xml, better approach build ear instead of war in order specify realm ?
a purely programmatic approach in portable (pure java ee) way not possible when use container specific (proprietary) login modules such glassfish jdbc login module/realm.
there api in java ee 6 this: jaspic. api (spi technically), can build portable authentication modules , configure them programmatic without need declaration.
i wrote blog article provides more details.
Comments
Post a Comment