Why do you try to do the work of Spring Security? Please follow the
sample in [1]. There's no need to check the credentials on your own. You
just need to provide your implementation of UserDetails.
[1] http://www.localhost.nu/svn/public/tapestry-spring-security-sample/
Am 27/05/2010 16:53, schrieb Todd Orr:
I am trying to integrate spring security into my Tapestry application and am
unable to get the TSS module to work correctly. I've created a login page
and am attempting to perform the authentication manually so that I can use
tap for the fields etc. I have a login page with the j_username, etc. also.
It doesn't work either. The code for my login page is:
private final static Logger LOG = LoggerFactory.getLogger(LoginPage.class);
@Inject
private RequestGlobals requestGlobals;
@Inject
private AuthenticationManager authenticationManager;
private Class<?> defaultTargetUrl = Index.class;
@SuppressWarnings("unused")
@Inject
private Request request;
@SuppressWarnings("unused")
@Inject
private Response response;
@Persist
@Property
private String username;
@Persist(PersistenceConstants.FLASH)
@Property
private String password;
@Property
@Component(id = "loginForm")
private Form loginForm;
private Authentication authResult;
@Component(id = "password")
private PasswordField passwordField;
@SuppressWarnings("unused")
@Component(id = "username")
private TextField usernameField;
public void onValidateFormFromLoginForm() {
// clean up the properties
username = username == null ? null : username.trim();
password = password == null ? null : password.trim();
UsernamePasswordAuthenticationToken authRequest = new
UsernamePasswordAuthenticationToken(username, password);
try {
authResult = authenticationManager.authenticate(authRequest);
} catch (BadCredentialsException e) {
LOG.warn("Authentication failed: {}", e.getAuthentication());
loginForm.recordError(passwordField, "Invalid username or password");
} catch (AuthenticationException e) {
LOG.warn("Authentication failed: {}", e.getAuthentication());
loginForm.recordError(passwordField, "Invalid username or password");
}
}
public Object onSuccessFromLoginForm() {
SavedRequest savedRequest = (SavedRequest)
requestGlobals.getHTTPServletRequest().getSession().getAttribute(
AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY);
SecurityContextHolder.getContext().setAuthentication(authResult);
if (savedRequest != null) {
URL url = null;
try {
url = new URL(savedRequest.getRequestURL());
} catch (MalformedURLException e) {
LOG.error("malformed url:" + savedRequest.getRequestURI());
return defaultTargetUrl;
}
return url;
}
return defaultTargetUrl;
}
And the stdout shows the following when attempting to login:
10:49:01,733 DEBUG [UserDetailsServiceImpl] Attempting to locate user with
username "my_username"
10:49:01,782 INFO [sqlonly] select this_.user_id as user1_0_1_,
this_.user_passwd as user2_0_1_, this_.user_username as
user3_0_1_, roles2_.u_to_p_frn_user_id as u2_3_,
roles2_.u_to_p_frn_permission_id as u1_3_,
roles2_.u_to_p_frn_permission_id as u1_1_0_, roles2_.u_to_p_frn_user_id as
u2_1_0_ from users
this_ left outer join user_to_permissions roles2_ on
this_.user_id=roles2_.u_to_p_frn_user_id
where this_.user_username='my_username'
10:49:02,063 DEBUG [UserDetailsServiceImpl] Located user:
User[username=my_username,roles=[ROLE_TEMP,
ROLE_ADMIN],authorities=[ROLE_TEMP, ROLE_ADMIN]]
10:49:02,446 WARN [LoginPage] Authentication failed:
org.springframework.security.providers.usernamepasswordauthenticationto...@1f:
Principal: my_username; Password: [PROTECTED]; Authenticated: false;
Details: null; Not granted any authorities
I am sure that a valid user with valid authorities is being returned from my
UserDetailsService. I am sure it's password matches the password I am
providing. But no matter what, it always - ALWAYS - throws the
BadCredentialsException.
I've been beating my head against this wall since Tuesday - literally.
Please advise.
Thanks,
T
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org