Search in sources :

Example 1 with LdapResponse

use of eu.cryptoeuro.accountmapper.response.LdapResponse in project account-identity by cryptofiat.

the class LdapController method checkIdCode.

@RequestMapping(method = RequestMethod.GET, value = "/{idCode}")
public ResponseEntity<LdapResponse> checkIdCode(@PathVariable("idCode") long idCode) {
    LdapResponse lr = ldapService.lookupIdCode(idCode);
    // should check if didn't return, then respond with 404
    if (lr != null && lr.getIdCode() > 0) {
        HttpHeaders headers = new HttpHeaders();
        headers.setCacheControl("max-age=3600");
        return new ResponseEntity<LdapResponse>(lr, headers, HttpStatus.OK);
    } else {
        throw new LdapNotFoundException();
    }
}
Also used : LdapResponse(eu.cryptoeuro.accountmapper.response.LdapResponse) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) LdapNotFoundException(eu.cryptoeuro.accountmapper.error.LdapNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with LdapResponse

use of eu.cryptoeuro.accountmapper.response.LdapResponse in project account-identity by cryptofiat.

the class LdapService method lookupIdCode.

public LdapResponse lookupIdCode(long idCode) {
    LdapResponse lResponse = LdapResponse.builder().build();
    lResponse = tryLocalCache(idCode);
    if (lResponse != null && lResponse.getIdCode() > 0) {
        return lResponse;
    }
    LdapNetworkConnection connection = new LdapNetworkConnection("ldap.sk.ee");
    try {
        connection.bind();
        EntryCursor cursor = connection.search("c=EE", "(serialNumber=" + String.valueOf(idCode) + ")", SearchScope.SUBTREE, "*");
        while (cursor.next()) {
            Entry entry = cursor.get();
            log.info("got an entry: " + entry.toString());
            String cn = entry.get("cn").getString();
            lResponse = LdapResponse.builder().idCode(Long.valueOf(idCode)).firstName(cn.split(",")[1]).lastName(cn.split(",")[0]).build();
        }
        connection.unBind();
        connection.close();
    } catch (Exception e) {
        log.error("Exception trying LDAP " + e.toString());
    }
    if (lResponse != null && lResponse.getIdCode() > 0) {
        storeLocalCache(lResponse);
        return lResponse;
    } else {
        return null;
    }
}
Also used : LdapResponse(eu.cryptoeuro.accountmapper.response.LdapResponse) EntryCursor(org.apache.directory.api.ldap.model.cursor.EntryCursor) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection)

Aggregations

LdapResponse (eu.cryptoeuro.accountmapper.response.LdapResponse)2 LdapNotFoundException (eu.cryptoeuro.accountmapper.error.LdapNotFoundException)1 EntryCursor (org.apache.directory.api.ldap.model.cursor.EntryCursor)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1