com.clouway.oauth2.exampleapp.storage.InMemoryClientRepository Maven / Gradle / Ivy
package com.clouway.oauth2.exampleapp.storage;
import com.clouway.oauth2.client.Client;
import com.clouway.oauth2.client.ClientRepository;
import com.clouway.oauth2.client.ServiceAccount;
import com.clouway.oauth2.client.ServiceAccountRepository;
import com.clouway.oauth2.jwt.Jwt.ClaimSet;
import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import java.util.Map;
/**
* @author Ivan Stefanov
*/
class InMemoryClientRepository implements ClientRepository, ServiceAccountRepository {
private Map clients = Maps.newHashMap();
private Map serviceAccounts = Maps.newHashMap();
@Inject
public InMemoryClientRepository() {
}
@Override
public void register(Client client) {
clients.put(client.id, client);
}
@Override
public Optional findById(String id) {
return Optional.fromNullable(clients.get(id));
}
@Override
public Optional findServiceAccount(ClaimSet claimSet) {
if (serviceAccounts.containsKey(claimSet.iss)) {
return Optional.of(serviceAccounts.get(claimSet.iss));
}
return Optional.absent();
}
public void registerServiceAccount(String clientEmail, String privateKeyAsPem) {
serviceAccounts.put(clientEmail,new ServiceAccount(clientEmail, privateKeyAsPem));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy