В одном из моих бинов BackofficeSSOService весной я делаю следующий вызов, чтобы использовать объект SAMLCredential для получения настраиваемого атрибута в токене ответа SAML.
final SAMLCredential credential = (SAMLCredential)SecurityContextHolder.getContext().getAuthentication().getCredentials();
String branchNo = de.hybris.platform.samlsinglesignon.utils.SAMLUtil.getCustomAttribute(credential,"branchNo");
В отладке я вижу тип возврата для getCredentials() показывает возвращаемый объект SAMLCredential, но его исключение ClassCastException:
INFO [hybrisHTTP8] [BackofficeSSOService] org.springframework.security.saml.SAMLCredential cannot be cast to org.springframework.security.saml.SAMLCredential java.lang.ClassCastException: org.springframework.security.saml.SAMLCredential cannot be cast to org.springframework.security.saml.SAMLCredential
Чего здесь не хватает?
credential instanceof SAMLCredential check is False
@Override
public UserModel getOrCreateSSOUser(final String id, final String name, final Collection<String> roles)
{
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
try {
SAMLCredential credential1 = (SAMLCredential) authentication.getCredentials();
LOG.info("********** retrieving custom attribute using credential1 ****** "+credential1);
}catch(Exception e) {
LOG.info(e.getMessage(), e);
}
final Object credential = SecurityContextHolder.getContext().getAuthentication().getCredentials();
LOG.info("********** retrieving custom attribute ****** "+credential);
if (credential instanceof SAMLCredential ) {
String branchNo = CTSAMLUtil.getCustomAttribute((SAMLCredential)credential, "branchNo");
}
}
authentication.getCredentials() should return SAMLCredential type since this works in hybris 1808 in de.hybris.platform.samlsinglesignon.RedirectionController() method call without failure in OOB code.
@RequestMapping(method = { RequestMethod.GET })
public String redirect(final HttpServletResponse response, final HttpServletRequest request) {
final SAMLCredential credential = (SAMLCredential)SecurityContextHolder.getContext().getAuthentication().getCredentials();