Hi!
My application needs to use custom authentication provider in order to authenticate against data gained from EJB.
So here is my MyUsernamePasswordAuthenticationProvider class:
and configuration:Code:package sk.skhplus.retail.controller; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.context.SecurityContextHolder; import sk.skhplus.core.users.ejb.intf.UserBeanLocal; public class MyUsernamePasswordAuthenticationProvider implements AuthenticationProvider { private UserBeanLocal userBeanLocal; public void setUserBeanLocal(UserBeanLocal userBeanLocal){ this.userBeanLocal=userBeanLocal; } public UserBeanLocal getUserBeanLocal() { return userBeanLocal; } @Override public Authentication authenticate(Authentication auth) throws AuthenticationException { // checking logic here (condition will be replaced, true is just temporary) if(true){ SecurityContextHolder.getContext().setAuthentication(auth); return new UsernamePasswordAuthenticationToken(auth.getName(), auth.getCredentials()); //co ma vracat a komu? } throw new BadCredentialsException("zle udaje"); } //kontrola, ci/ake auth provider akceptuje tokeny @Override public boolean supports(Class<? extends Object> authentication) { return (UsernamePasswordAuthenticationToken.class .isAssignableFrom(authentication)); } }
web.xml:
springmvc-servlet.xml:Code:<context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/springmvc-servlet.xml /WEB-INF/security-app-context.xml </param-value> </context-param>
/WEB-INF/security-app-context.xml:Code:. . . <bean id="userBean" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="skh-retail/UserBean/local" /> <property name="resourceRef" value="true" /> </bean> <bean id="myUsernamePasswordAuthenticationProvider" class="sk.skhplus.retail.controller.MyUsernamePasswordAuthenticationProvider"> <property name="userBeanLocal" ref="userBean" /> </bean>
compile and deploy goes fine without any errors but when Im trying to login in browser (I expect that with this configuration (allways true condition in MyUsernamePasswordAuth. provider) anything should be accepted) Im getting just:Code:. . . <http auto-config='true'> <intercept-url pattern="/**" access="ROLE_USER" /> <form-login default-target-url="/jsp/hello.do" /> <http-basic /> </http> <authentication-manager> <authentication-provider ref="myUsernamePasswordAuthenticationProvider"/> </authentication-manager>
HTTP Status 403 - Access is denied
type Status report
message Access is denied
description Access to the specified resource (Access is denied) has been forbidden.
JBoss Web/2.1.2.GA
Can you, please, tell me where Im going wrong or what am I missing?
Thanks in advance!


Reply With Quote
