}
public Tokens getTokens() throws UnsupportedSocialNetworkException{
//since this method can be called by the /callback endpoint that does not open a DB connection, we need to manage it here
if (BBConfiguration.getSocialMock()) return new Tokens("fake_token","fake_secret");
ODatabaseRecordTx db=null;
try {
db = DbHelper.getOrOpenConnection(BBConfiguration.getAPPCODE(), BBConfiguration.getBaasBoxUsername(), BBConfiguration.getBaasBoxPassword());
String keyFormat = socialNetwork.toUpperCase()+"_TOKEN";
String token = (String)Cache.get(keyFormat);
if(token ==null){
token = SocialLoginConfiguration.valueOf(keyFormat).getValueAsString();
Cache.set(keyFormat,token,0);
}
keyFormat = socialNetwork.toUpperCase()+"_SECRET";
String secret = (String)Cache.get(keyFormat);;
if(secret ==null){
secret = SocialLoginConfiguration.valueOf(keyFormat).getValueAsString();
Cache.set(keyFormat,secret,0);
}
if(secret==null || token == null){
throw new UnsupportedSocialNetworkException("Social login for "+socialNetwork+" is not enabled.Please add app token and secret to configuration");
}
return new Tokens(token,secret);
} catch (InvalidAppCodeException e) {
//a very strange thing happened here!
throw new RuntimeException(e);
}finally{
if (db!=null && !db.isClosed()) db.close();
}
}