use of org.apache.sling.auth.core.spi.AuthenticationInfo in project sling by apache.
the class XingLoginAuthenticationHandler method extractCredentials.
/**
* we need the <i>hash</i> from the XING cookie (<code>xing_p_lw_s_[...]</code>) and
* the <i>user data</i> and <i>id</i> from our own cookies (<code>sling_auth_xing_[...]</code>)
*
* @param request
* @param response
* @return
*/
@Override
public AuthenticationInfo extractCredentials(final HttpServletRequest request, final HttpServletResponse response) {
logger.debug("extract credentials");
String hash = null;
String user = null;
String userId = null;
final Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (final Cookie cookie : cookies) {
final String cookieName = cookie.getName();
if (cookieName.equals(xingCookie)) {
hash = readCookieValue(cookie);
logger.debug("“Login with XING” cookie found: {}", hash);
} else if (cookieName.equals(userCookie)) {
user = readCookieValue(cookie);
} else if (cookieName.equals(userIdCookie)) {
userId = readCookieValue(cookie);
}
}
}
if (!StringUtils.isEmpty(hash) && !StringUtils.isEmpty(userId) && !StringUtils.isEmpty(user)) {
logger.debug("valid cookies with hash and user data and id found");
final AuthenticationInfo authenticationInfo = new AuthenticationInfo(XingLogin.AUTH_TYPE, userId);
authenticationInfo.put(XingLogin.AUTHENTICATION_CREDENTIALS_HASH_KEY, hash);
authenticationInfo.put(XingLogin.AUTHENTICATION_CREDENTIALS_USERDATA_KEY, user);
return authenticationInfo;
} else {
logger.debug("unable to extract credentials from request");
return null;
}
}
Aggregations