java - Digest auth with Spring Security using javaconfig -
so i'm trying create digest authentication spring following documentation trying translate xml "requirements" in java requirements.
let's have xml in docs:
<bean id="digestfilter" class= "org.springframework.security.web.authentication.www.digestauthenticationfilter"> <property name="userdetailsservice" ref="jdbcdaoimpl"/> <property name="authenticationentrypoint" ref="digestentrypoint"/> <property name="usercache" ref="usercache"/> </bean> <bean id="digestentrypoint" class= "org.springframework.security.web.authentication.www.digestauthenticationentrypoint"> <property name="realmname" value="contacts realm via digest authentication"/> <property name="key" value="acegi"/> <property name="noncevalidityseconds" value="10"/> </bean>
this current javaconfig:
@configuration @profile({"integration", "release"}) @enablewebsecurity public class securityconfiguration extends websecurityconfigureradapter { @resource(authenticationtype = resource.authenticationtype.container, mappedname = "jdbc/db") private datasource datasource; @override protected void registerauthentication (authenticationmanagerbuilder auth) throws exception { auth.jdbcauthentication().datasource(datasource) .usersbyusernamequery("select id_user, password, active users id_user = ?;") .authoritiesbyusernamequery("select id_user, id_role user_roles id_user = ?"); } @bean public basicauthenticationentrypoint entrypoint () { basicauthenticationentrypoint basicauthenticationentrypoint = new basicauthenticationentrypoint(); basicauthenticationentrypoint.setrealmname("basic wf realm"); return basicauthenticationentrypoint; } @bean public digestauthenticationentrypoint digestentrypoint () { digestauthenticationentrypoint digestauthenticationentrypoint = new digestauthenticationentrypoint(); digestauthenticationentrypoint.setkey("mykey"); digestauthenticationentrypoint.setrealmname("digest wf realm"); return digestauthenticationentrypoint; } public digestauthenticationfilter digestauthenticationfilter ( digestauthenticationentrypoint digestauthenticationentrypoint) { digestauthenticationfilter digestauthenticationfilter = new digestauthenticationfilter(); digestauthenticationfilter.setauthenticationentrypoint(digestentrypoint()); // digestauthenticationfilter.setauthenticationdetailssource(authenticationdetailssource); return digestauthenticationfilter; } @override protected void configure (httpsecurity http) throws exception { // basic auth - works! // http.exceptionhandling().authenticationentrypoint(entrypoint()).and() http .authorizeurls().antmatchers("/firstres/*").permitall() .antmatchers("/secondres/*").permitall() .antmatchers("/resources/*").permitall() .antmatchers("/**").hasanyauthority("first_role", "second_role").and()//.httpbasic(); .addfilter(digestauthenticationfilter(digestentrypoint())); } }
i 403 - access denied. httpbasic working. can tell i'm missing?
i'm not sure when getting 403 access denied, if happening when request protected resource before have authenticated need this:
@override protected void configure (httpsecurity http) throws exception { http .exceptionhandling() // entry point handles when request protected page , // not yet authenticated .authenticationentrypoint(digestentrypoint()) .and() .authorizeurls() .antmatchers("/firstres/*").permitall() .antmatchers("/secondres/*").permitall() .antmatchers("/resources/*").permitall() .antmatchers("/**").hasanyauthority("first_role", "second_role").and() // entry point on digest filter used failed authentication attempts .addfilter(digestauthenticationfilter(digestentrypoint())); } @override @bean public userdetailsservice userdetailsservicebean() { return super.userdetailsservicebean(); } public digestauthenticationfilter digestauthenticationfilter ( digestauthenticationentrypoint digestauthenticationentrypoint) { digestauthenticationfilter digestauthenticationfilter = new digestauthenticationfilter(); digestauthenticationfilter.setauthenticationentrypoint(digestentrypoint()); digestauthenticationfilter.setuserdetailsservice(userdetailsservicebean()); return digestauthenticationfilter; }
Comments
Post a Comment