private CredentialsInfo readCreds( UUID appId, UUID ownerId, String ownerType, String key ) throws Exception { EntityManager em = emf.getEntityManager( appId ); Entity owner = em.get( ownerId ); return ( CredentialsInfo ) em.getDictionaryElementValue( owner, DICTIONARY_CREDENTIALS, key ); }
private Set<CredentialsInfo> readUserPasswordHistory( UUID appId, UUID ownerId ) throws Exception { EntityManager em = emf.getEntityManager( appId ); Entity owner = em.get( new SimpleEntityRef("user", ownerId )); @SuppressWarnings("unchecked") Set<CredentialsInfo> credInfo = (Set<CredentialsInfo>)em.getDictionaryElementValue(owner, DICTIONARY_CREDENTIALS, USER_PASSWORD_HISTORY); return credInfo; }
@Test public void testAddMapToDictionaries() throws Exception { logger.info( "EntityDictionaryIT.testAddMapToDictionaries" ); Map<String,Object> testMap = new HashMap<String,Object>(); EntityManager em = app.getEntityManager(); assertNotNull( em ); testMap.put( "testName","testval" ); em.addMapToDictionary( em.getApplicationRef(), "testProvider",testMap ); Object o = em.getDictionaryElementValue( em.getApplicationRef(), "testProvider","testName" ); assertEquals("testval" , o.toString() ); } }
String val = ( String ) em.getDictionaryElementValue( thing, "test", "foo" ); assertEquals( "val should be bar", "bar", val );
@Test public void testRemoveFromDictionary() throws Exception { logger.info( "EntityDictionaryIT.testRemoveFromDictionary" ); Application.OAuthProvider provider = new Application.OAuthProvider(); provider.setClientId( "123456789012.apps.googleusercontent.com" ); provider.setClientSecret( "abcdefghijklmnopqrstuvwx" ); provider.setRedirectUris( "https://www.example.com/oauth2callback" ); provider.setJavaScriptOrigins( "https://www.example.com" ); provider.setAuthorizationEndpointUrl( "https://accounts.google.com/o/oauth2/auth" ); provider.setAccessTokenEndpointUrl( "https://accounts.google.com/o/oauth2/token" ); provider.setVersion( "2.0" ); logger.info( "EntityDictionaryIT.testApplicationDictionaries" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); em.addToDictionary( em.getApplicationRef(), "oauthproviders", "google", provider ); Object o = em.getDictionaryElementValue( em.getApplicationRef(), "oauthproviders", "google" ); assertNotNull( o ); em.removeFromDictionary( em.getApplicationRef(),"oauthproviders","google" ); o = em.getDictionaryElementValue( em.getApplicationRef(), "oauthproviders", "google" ); assertNull( o ); }
@Test public void testApplicationDictionaries() throws Exception { Application.OAuthProvider provider = new Application.OAuthProvider(); provider.setClientId( "123456789012.apps.googleusercontent.com" ); provider.setClientSecret( "abcdefghijklmnopqrstuvwx" ); provider.setRedirectUris( "https://www.example.com/oauth2callback" ); provider.setJavaScriptOrigins( "https://www.example.com" ); provider.setAuthorizationEndpointUrl( "https://accounts.google.com/o/oauth2/auth" ); provider.setAccessTokenEndpointUrl( "https://accounts.google.com/o/oauth2/token" ); provider.setVersion( "2.0" ); logger.info( "EntityDictionaryIT.testApplicationDictionaries" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); em.addToDictionary( em.getApplicationRef(), "oauthproviders", "google", provider ); Object o = em.getDictionaryElementValue( em.getApplicationRef(), "oauthproviders", "google" ); logger.info( JsonUtils.mapToFormattedJsonString( o ) ); }
@Test public void testGetDictionaries() throws Exception { logger.info( "EntityDictionaryIT.testGetDictionaries" ); Application.OAuthProvider provider = new Application.OAuthProvider(); provider.setClientId( "123456789012.apps.googleusercontent.com" ); provider.setClientSecret( "abcdefghijklmnopqrstuvwx" ); provider.setRedirectUris( "https://www.example.com/oauth2callback" ); provider.setJavaScriptOrigins( "https://www.example.com" ); provider.setAuthorizationEndpointUrl( "https://accounts.google.com/o/oauth2/auth" ); provider.setAccessTokenEndpointUrl( "https://accounts.google.com/o/oauth2/token" ); provider.setVersion( "2.0" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); em.addToDictionary( em.getApplicationRef(), "oauthproviders", "google", provider ); Object o = em.getDictionaryElementValue( em.getApplicationRef(), "oauthproviders", "google" ); assertNotNull( o ); Set<String> set = em.getDictionaryNames( em.getApplicationRef() ); assertTrue( set.contains( "oauthproviders" ) ); } @Test
Object o = em.getDictionaryElementValue( user, "credentials", "plaintext" ); logger.info( JsonUtils.mapToFormattedJsonString( o ) ); o = em.getDictionaryElementValue( user, "credentials", "encrypted" ); logger.info( JsonUtils.mapToFormattedJsonString( o ) );