Search in sources :

Example 1 with ClientCertificateUserDetails

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);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) WebIdUserDetails(won.node.springsecurity.userdetails.WebIdUserDetails) ClientCertificateUserDetails(won.node.springsecurity.userdetails.ClientCertificateUserDetails) URI(java.net.URI) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) URISyntaxException(java.net.URISyntaxException)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 ClientCertificateUserDetails (won.node.springsecurity.userdetails.ClientCertificateUserDetails)1 WebIdUserDetails (won.node.springsecurity.userdetails.WebIdUserDetails)1