use of won.node.springsecurity.userdetails.ClientCertificateUserDetails in project webofneeds by researchstudio-sat.
the class UserDetailsService method handleClientCertificate.
private UserDetails handleClientCertificate(Certificate certificate, String principal) {
List<GrantedAuthority> authorities = new ArrayList<>(3);
authorities.add(new SimpleGrantedAuthority("ROLE_CLIENT_CERTIFICATE"));
logger.debug("checking if principal '" + principal + "' is a webId");
URI webID = toUriIfPossible(principal);
if (webID != null) {
// principal is an URI, try to verify:
try {
if (webIDVerificationAgent.verify(certificate.getPublicKey(), webID)) {
authorities.add(new SimpleGrantedAuthority("ROLE_WEBID"));
logger.debug("webId '" + principal + "' successfully verified - ROLE_WEBID granted");
return new WebIdUserDetails(webID, authorities);
} else {
logger.debug("could not verify webId '" + principal + "'. ROLE_WEBID not granted");
}
} catch (Exception e) {
logger.debug("could not verify webId '" + principal + "' because of an error during verification. ROLE_WEBID " + "not granted. Cause is logged", e);
}
}
// certificate
return new ClientCertificateUserDetails(principal, authorities);
}
Aggregations