Good morning
I'd like to implement this solution: i want to have to type of authentication (form-login and openID login) with spring security 3.1
I proceed like that:
in this configuration you can see, i have too providers ; the openid privider use a custom userDetailsService.Code:<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> <!--<http pattern="/resources" security="none" /> --> <http auto-config="false" use-expressions="true"> <intercept-url pattern="/login.htm" access="permitAll" /> <intercept-url pattern="/loginfailed*" access="permitAll" /> <intercept-url pattern="/home.htm" access="permitAll" /> <intercept-url pattern="/**.htm" access="hasRole('ROLE_CLOUD_USER')" /> <form-login login-page="/login.htm" default-target-url="/admin.htm" authentication-failure-url="/loginfailed.htm" always-use-default-target="true"/> <logout logout-url="/logout.htm" logout-success-url="/home.htm" /> </http> <http auto-config="true" use-expressions="true" pattern="/loginopenid*" authentication-manager-ref="authenticationManager"> <openid-login authentication-failure-url="/loginopenidfailed.htm"> <attribute-exchange> <openid-attribute name="email" type="http://schema.openid.net/contact/email" required="true" count="2"/> <openid-attribute name="name" type="http://schema.openid.net/namePerson/friendly" /> </attribute-exchange> </openid-login> </http> <!--Authentication Manager <authentication-manager alias="authenticationManager"> <authentication-provider ref="daoAuthenticationProvider"/> <authentication-provider ref="openIDAuthenticationProvider"/> </authentication-manager>--> <beans:bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor"> <beans:property name="authenticationManager" ref="providerManager"/> </beans:bean> <beans:bean id="providerManager" class="org.springframework.security.authentication.ProviderManager"> <beans:property name="providers"> <beans:list> <beans:ref bean="daoAuthenticationProvider" /> <beans:ref bean="openIDAuthenticationProvider" /> </beans:list> </beans:property> </beans:bean> <!--dao authentication provider --> <beans:bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"> <beans:property name="userDetailsService" ref="userDetailsService" /> </beans:bean> <!--openID authentication provider --> <beans:bean id="openIDAuthenticationProvider" class="org.springframework.security.openid.OpenIDAuthenticationProvider"> <beans:property name="userDetailsService"> <beans:bean id="openIDUserDS" class="test.security.CloudOpenIDUserDS"/> </beans:property> </beans:bean> <user-service id="userDetailsService"> <user name="abdellah" password="32fe5bbf04adc744455c92fa7b71e9dca8ce729c" authorities="ROLE_CLOUD_USER" /> <user name="guest" password="35675e68f4b5af7b995d9205ad0fc43842f16450" authorities="ROLE_CLOUD_USER" /> </user-service> </beans:beans>
here is the classe:
when i deploy the app i always have this stacktrace:Code:package test.security; import org.springframework.dao.DataAccessException; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.GrantedAuthorityImpl; import org.springframework.security.core.userdetails.AuthenticationUserDetailsService; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.openid.OpenIDAuthenticationToken; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class CloudOpenIDUserDS implements UserDetailsService, AuthenticationUserDetailsService<OpenIDAuthenticationToken> { private final Map<String, List<GrantedAuthority>> userAuthorities = new HashMap<String, List<GrantedAuthority>>(); public CloudOpenIDUserDS() { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); //this user has the privilege: "customer" authorities.add(new GrantedAuthorityImpl("customer")); this.userAuthorities.put("[http://mykel33.myopenid.com,]", authorities); } @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { User out_retour = null; if (this.userAuthorities.containsKey(username)) { out_retour = new User(username, "", true, true, true, true, this.userAuthorities.get(username)); } return out_retour; } @Override public UserDetails loadUserDetails(OpenIDAuthenticationToken tocken) throws UsernameNotFoundException { return null; } }


Reply With Quote
