I am working on an application to migrate from openid to Oauth2 using spring security. I followed the demo implementation for pac4j.
Our application is hosted on GAE. I am injecting CustomizedUserDetailService injected in ClientAuthenticationProvider to assign roles to the user.
But I noticed authenticate method of ClientAuthenticationProvider never called so loadUserDetails inside CustomizedUserDetailService is also will not be called. However the user was successfully authenticated and returned to the application.
If I user callback service then the AuthenticationToken is always Anonymous and can't be casted to ClientAuthenticationToken. Below are my security configurations. Can anyone of you please help me to find out what is missing?
<?xml version="1.0" encoding="UTF-8"?>
<security:http auto-config="false" use-expressions="true" access-denied-page="/denied" >
<security:intercept-url pattern="/auth/login" access="permitAll"/>
<security:intercept-url pattern="/auth/oAuthCallback" access="permitAll"/>
<security:intercept-url pattern="/contact/us" access="permitAll"/>
<security:intercept-url pattern="/admin/auth/login" access="permitAll"/>
<security:intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')" />
<security:intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />
<security:intercept-url pattern="/starreg/auth/login" access="permitAll"/>
<security:intercept-url pattern="/starreg" access="hasAnyRole('ROLE_CSP_ADMIN', 'ROLE_CSP_EVAL')" />
<security:intercept-url pattern="/starreg/**" access="hasAnyRole('ROLE_CSP_ADMIN', 'ROLE_CSP_EVAL')" />
<security:intercept-url pattern="/page/adminpages/*.jsp" access="hasRole('ROLE_ADMIN')" />
<security:intercept-url pattern="/page/starregpages/*.jsp" access="hasAnyRole('ROLE_CSP_ADMIN', 'ROLE_CSP_EVAL')" />
<security:intercept-url pattern="/page/*.jsp" access="isAuthenticated()" />
<security:form-login
login-page="/auth/login"
authentication-failure-url="/auth/login?error=true"
default-target-url="/"
/>
<security:logout
invalidate-session="true"
logout-success-url="/page/logout.jsp"
/>
<!--<security:logout />-->
<security:custom-filter after="BASIC_AUTH_FILTER" ref="clientFilter" />
</security:http>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="clientProvider" />
</security:authentication-manager>
<bean id="googleEntryPoint" class="org.pac4j.springframework.security.web.ClientAuthenticationEntryPoint">
<property name="client" ref="googleClient" />
</bean>
<!-- clients definition -->
<bean id="googleClient" class="org.pac4j.oauth.client.Google2Client">
<property name="key" value="[KEY]" />
<property name="secret" value="SECRET" />
<property name="scope" value="EMAIL_AND_PROFILE" />
</bean>
<bean id="clients" class="org.pac4j.core.client.Clients">
<property name="clients">
<list>
<ref bean="googleClient" />
</list>
</property>
</bean>
<!-- common to all clients -->
<bean id="clientFilter" class="org.pac4j.springframework.security.web.ClientAuthenticationFilter">
<constructor-arg value="/callback"/>
<property name="clients" ref="clients" />
<property name="sessionAuthenticationStrategy" ref="sas" />
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<bean id="customAuthenticationUserDetailsService" class="csp.com.neupart.security.CustomAuthenticationUserDetailsService">
<property name="cspUserDAO" ref="CSPUserDAO"></property>
</bean>
<bean id="clientProvider" class="csp.com.neupart.security.ClientAuthenticationProvider">
<property name="userDetailsService" ref="customAuthenticationUserDetailsService"/>
<property name="clients" ref="clients" />
</bean>
<bean id="httpSessionRequestCache" class="org.springframework.security.web.savedrequest.HttpSessionRequestCache" />
<bean id="sas" class="org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy" />
</beans>