private void writeCreds( UUID appId, EntityRef owner, CredentialsInfo creds, String key ) throws Exception { EntityManager em = emf.getEntityManager( appId ); em.addToDictionary( owner, DICTIONARY_CREDENTIALS, key, creds ); }
/** currently only affects properties */ public void updateOrganization( OrganizationInfo organizationInfo ) throws Exception { Map<String, Object> properties = organizationInfo.getProperties(); if ( properties != null ) { EntityRef organizationEntity = new SimpleEntityRef( Group.ENTITY_TYPE, organizationInfo.getUuid() ); EntityManager em = emf.getEntityManager( smf.getManagementAppId() ); for ( Map.Entry<String, Object> entry : properties.entrySet() ) { if ( "".equals( entry.getValue() ) ) { properties.remove( entry.getKey() ); em.removeFromDictionary( organizationEntity, ORGANIZATION_PROPERTIES_DICTIONARY, entry.getKey() ); } else { em.addToDictionary( organizationEntity, ORGANIZATION_PROPERTIES_DICTIONARY, entry.getKey(), entry.getValue() ); } } } }
@Override public void updateOrganizationConfig( OrganizationConfig organizationConfig ) throws Exception { // get only the overrides Map<String, Object> orgConfigProperties = organizationConfig.getOrgConfigOverridesMap(); if ( orgConfigProperties != null ) { EntityRef organizationEntity = new SimpleEntityRef( Group.ENTITY_TYPE, organizationConfig.getUuid() ); EntityManager em = emf.getEntityManager( smf.getManagementAppId() ); for ( Map.Entry<String, Object> entry : orgConfigProperties.entrySet() ) { if ( "".equals( entry.getValue() ) ) { em.removeFromDictionary( organizationEntity, ORGANIZATION_CONFIG_DICTIONARY, entry.getKey() ); } else { em.addToDictionary( organizationEntity, ORGANIZATION_CONFIG_DICTIONARY, entry.getKey(), entry.getValue() ); } } // evict cache for this key if it exists orgConfigByAppCache.invalidate( organizationConfig.getUuid() ); } }
Entity thing = em.create( "thing", properties ); assertNotNull( thing ); em.addToDictionary( thing, "stuff", "alpha" ); em.addToDictionary( thing, "stuff", "beta" ); em.addToDictionary( thing, "stuff", "gamma" ); assertEquals( "third item should be gamma", "gamma", i.next() ); em.addToDictionary( thing, "test", "foo", "bar" ); String val = ( String ) em.getDictionaryElementValue( thing, "test", "foo" ); assertEquals( "val should be bar", "bar", val );
em.addToDictionary( user, CREDENTIALS_HISTORY, uuid.toString(), currentCredentials );
@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
credentials.setCryptoChain( new String[] { "plaintext" } ); em.addToDictionary( user, "credentials", "plaintext", credentials ); credentials.setCryptoChain( new String[] { "sha-1" } ); em.addToDictionary( user, "credentials", "encrypted", credentials );
@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 ); }
em.addToDictionary( storedUser, DICTIONARY_CREDENTIALS, "password", info );
em.addToDictionary( storedUser, DICTIONARY_CREDENTIALS, "password", info );
em.addToDictionary( storedUser, DICTIONARY_CREDENTIALS, "password", info );
em.addToDictionary( storedUser, DICTIONARY_CREDENTIALS, "password", info );