public String doAuthentication(Object credentials, boolean isRememberMe, ServiceClient client,
HttpServletRequest request) throws AuthenticationException {
DefaultAuthenticatorCredentials defaultCredentials = (DefaultAuthenticatorCredentials) credentials;
// call AuthenticationAdmin, since BasicAuth are not validated for LocalTransport
AuthenticationAdminClient authClient;
try {
authClient = getAuthenticationAdminCient(request);
boolean isAutenticated = false;
if (isRememberMe && defaultCredentials.getUserName() != null
&& defaultCredentials.getPassword() != null) {
RememberMeData rememberMe;
rememberMe = authClient.loginWithRememberMeOption(defaultCredentials.getUserName(),
defaultCredentials.getPassword(), "127.0.0.1");
isAutenticated = rememberMe.getAuthenticated();
if (isAutenticated) {
request.setAttribute(CarbonConstants.REMEMBER_ME_COOKIE_VALUE,
rememberMe.getValue());
request.setAttribute(CarbonConstants.REMEMBER_ME_COOKIE_AGE, new Integer(
rememberMe.getMaxAge()).toString());
return defaultCredentials.getUserName();
}
} else if (isRememberMe) {
// This is to login with Remember Me.
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(CarbonConstants.REMEMBER_ME_COOKE_NAME)) {
isAutenticated = authClient
.loginWithRememberMeCookie(cookie.getValue());
if (isAutenticated) {
String cookieValue = cookie.getValue();
return getUserNameFromCookie(cookieValue);
}
}
}
}
} else {
isAutenticated = authClient.login(defaultCredentials.getUserName(),
defaultCredentials.getPassword(), "127.0.0.1");
if (isAutenticated) {
return defaultCredentials.getUserName();
}
}