java - spring security authorization only -
i trying develop user management tool using waffle perform windows authentication spring security. unfortunately, thing provides me authentication part.
i assign role particular user session in order limit users privileges. each username stored in database along associated role. how can spring security query database , load associated role session, can use @preauthorize(hasrole(role)) annotation in controller restrict access actions?
edit: answer don't think thats quite looking for. have made progress(i think). authentication provider have created own custom grantedauthorityfactory property of wafflespringauthenticationprovider follows:
<bean id="wafflespringauthenticationprovider" class="waffle.spring.windowsauthenticationprovider"> <property name="allowguestlogin" value="false" /> <property name="principalformat" value="fqn" /> <property name="roleformat" value="both" /> <property name="authprovider" ref="wafflewindowsauthprovider" /> <property name="grantedauthorityfactory" ref ="simplegrantedauthorityfactory"/> <!-- --> </bean>
the grantedauthorityfactory code follows:
import org.springframework.beans.factory.annotation.autowired; import org.springframework.beans.factory.annotation.qualifier; import org.springframework.jdbc.core.namedparam.namedparameterjdbctemplate; import org.springframework.security.core.grantedauthority; import waffle.spring.grantedauthorityfactory; import waffle.windows.auth.windowsaccount; public class simplegrantedauthorityfactory implements grantedauthorityfactory{ private final string prefix; private final boolean convert_to_upper_case; @autowired @qualifier(value = "jdbcroledao") private jdbcroledao jdbcroledao; public simplegrantedauthorityfactory(string prefix, boolean converttouppercase) { prefix = prefix; convert_to_upper_case = converttouppercase; } @override public grantedauthority creategrantedauthority(windowsaccount windowsaccount) { system.out.println("username: "+windowsaccount.getfqn()); string grantedauthoritystring = windowsaccount.getfqn(); string grantedauthority = jdbcroledao.getrole(grantedauthoritystring); return new simplegrantedauthority(prefix+grantedauthority); } }
now when run program , try log in, login fails. when remove custom factory property config file, login completed no assigned roles. i'm not sure if important, windowsaccount.getfqn() not returning correct username enter on login form. there i'm missing factory class?
you have 2 options:
configure
jdbcdaoimpl
userdetailsservice
if use provided db schema<authentication-manager> <authentication-provider> <jdbc-user-service data-source-ref="yourdatasource"> </authentication-provider> </authentication-manager>
write , configure own
userdetailsservice
if use custom db schema.<authentication-manager> <authentication-provider user-service-ref="idofyourcustomuserdetailsservice" /> </authentication-manager>
Comments
Post a Comment