Spring Database Authentication Exception Handling? -
i'm using spring authentication against oracle database temporary users. these users assigned numeric id can user log limited web site. working fine, know users @ point type in user name instead of numeric id (i've done myself while testing!). since database column i'm authenticating against number, ugly http status 401 page sqlsyntaxerrorexception saying typed in invalid number (which is).
is there way handle gracefully? example, spring has exceptionmappingauthenticationfailurehandler allows map various types of authentication exceptions web pages can redirect user meaningful error page, , we're using things badcredentialsexception. appears can't use old type of excpetion here, though, because tried adding java.sql.sqlsyntaxerrorexception , didn't change anything. there similar spring class allow catch other types of exceptions? or not configuring right? here's have:
<bean id="authenticationfailurehandler" class="org.springframework.security.web.authentication.exceptionmappingauthenticationfailurehandler> <property name="exceptionmappings"> <props> <!-- spring exception types work fine... --> <prop key="org.springframework.security.authentication.badcredentialsexception"> /login/bad credentials </prop> <prop key="org.springframework.security.authentication.credentialsexpiredexception"> /login/expired credentials </prop> <prop key="org.springframework.security.authentication.lockedexception"> /login/account locked </prop> <prop key="org.springframework.security.authentication.disabledexception"> /login/account disabled </prop> <!-- ...but 1 doesn't anything! --> <prop key="java.sql.sqlsyntaxerrorexception"> /login/use numeric id </prop> </props> </property> <bean> i'd keep database column defined number. easy solution make varchar put numeric data in it, that's kind of ugly. nice have unified way handle authentication exceptions, , we're using spring handler.
thanks in advance!
rather dealing exception of having string compared against number should handle before get's validated. possible options are:
modify login controller reject attempts login non-numeric user ids. if you're using built in controller in spring security more of pain option #2.
modify
userdetailsservicereject attempts load users non-numeric usernames. have throwusernamenotfoundexceptionif username not valid.reject login attempt purely on client — bad idea things should happen on server side. i'm suggesting if modifying server side not possible. fyi, javascript regex validation before login form submission. should work in cases though not work if client has javascript disabled.
Comments
Post a Comment