Example usage for org.springframework.security.ldap.userdetails InetOrgPerson getUid

List of usage examples for org.springframework.security.ldap.userdetails InetOrgPerson getUid

Introduction

In this page you can find the example usage for org.springframework.security.ldap.userdetails InetOrgPerson getUid.

Prototype

public String getUid() 

Source Link

Usage

From source file:net.maritimecloud.identityregistry.utils.AccessControlUtil.java

public static boolean isUserSync(String userSyncMRN, String userSyncO, String userSyncOU, String userSyncC) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth instanceof PreAuthenticatedAuthenticationToken) {
        log.debug("Certificate authentication of user sync'er in process");
        // Certificate authentication
        PreAuthenticatedAuthenticationToken token = (PreAuthenticatedAuthenticationToken) auth;
        // Check that the Organization name of the accessed organization and the organization in the certificate is equal
        InetOrgPerson person = ((InetOrgPerson) token.getPrincipal());
        if (userSyncMRN.equals(person.getUid()) && userSyncO.equals(person.getO())
        // Hack alert! There is no country property in this type, so we misuse PostalAddress...
                && userSyncOU.equals(person.getOu()) && userSyncC.equals(person.getPostalAddress())) {
            log.debug("User sync'er accepted!");
            return true;
        }// w w w.  j a  v a  2  s  .  com
        log.debug("This was not the user-sync'er! " + userSyncMRN + "~" + person.getUid() + ", " + userSyncO
                + "~" + person.getO() + ", " + userSyncOU + "~" + person.getOu() + ", " + userSyncC + "~"
                + person.getPostalAddress());
    }
    return false;
}