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();
}
}
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;
}
}
Aggregations