use of org.eclipse.leshan.server.security.SecurityInfo in project leshan by eclipse.
the class LeshanBootstrapServerBuilderTest method create_server_with_securityStore.
@Test
public void create_server_with_securityStore() {
builder.setSecurityStore(new BootstrapSecurityStore() {
@Override
public SecurityInfo getByIdentity(String pskIdentity) {
return null;
}
@Override
public List<SecurityInfo> getAllByEndpoint(String endpoint) {
return null;
}
});
server = builder.build();
assertNotNull(server.getSecuredAddress());
assertNotNull(server.getUnsecuredAddress());
assertNotNull(server.getBootstrapSecurityStore());
}
use of org.eclipse.leshan.server.security.SecurityInfo in project leshan by eclipse.
the class FileSecurityStore method add.
@Override
public SecurityInfo add(SecurityInfo info) throws NonUniqueSecurityInfoException {
writeLock.lock();
try {
SecurityInfo previous = addToStore(info);
saveToFile();
return previous;
} finally {
writeLock.unlock();
}
}
use of org.eclipse.leshan.server.security.SecurityInfo in project leshan by eclipse.
the class FileSecurityStore method saveToFile.
protected void saveToFile() {
try {
File file = new File(filename);
if (!file.exists()) {
File parent = file.getParentFile();
if (parent != null) {
parent.mkdirs();
}
file.createNewFile();
}
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename))) {
out.writeObject(this.getAll().toArray(new SecurityInfo[0]));
}
} catch (IOException e) {
LOG.error("Could not save security infos to file", e);
}
}
use of org.eclipse.leshan.server.security.SecurityInfo in project leshan by eclipse.
the class RedisSecurityStore method getAll.
@Override
public Collection<SecurityInfo> getAll() {
try (Jedis j = pool.getResource()) {
ScanParams params = new ScanParams().match(SEC_EP + "*").count(100);
Collection<SecurityInfo> list = new LinkedList<>();
String cursor = "0";
do {
ScanResult<byte[]> res = j.scan(cursor.getBytes(), params);
for (byte[] key : res.getResult()) {
byte[] element = j.get(key);
list.add(deserialize(element));
}
cursor = res.getStringCursor();
} while (!"0".equals(cursor));
return list;
}
}
use of org.eclipse.leshan.server.security.SecurityInfo in project leshan by eclipse.
the class RedisSecurityStore method add.
@Override
public SecurityInfo add(SecurityInfo info) throws NonUniqueSecurityInfoException {
byte[] data = serialize(info);
try (Jedis j = pool.getResource()) {
if (info.getIdentity() != null) {
// populate the secondary index (security info by PSK id)
String oldEndpoint = j.hget(PSKID_SEC, info.getIdentity());
if (oldEndpoint != null && !oldEndpoint.equals(info.getEndpoint())) {
throw new NonUniqueSecurityInfoException("PSK Identity " + info.getIdentity() + " is already used");
}
j.hset(PSKID_SEC.getBytes(), info.getIdentity().getBytes(), info.getEndpoint().getBytes());
}
byte[] previousData = j.getSet((SEC_EP + info.getEndpoint()).getBytes(), data);
SecurityInfo previous = previousData == null ? null : deserialize(previousData);
String previousIdentity = previous == null ? null : previous.getIdentity();
if (previousIdentity != null && !previousIdentity.equals(info.getIdentity())) {
j.hdel(PSKID_SEC, previousIdentity);
}
return previous;
}
}
Aggregations