protected void saveToConfiguration(String providerKey, Map<String, Object> config) { try { entityManager.addMapToDictionary(entityManager.getApplication(), providerKey, config); } catch (Exception ex) { logger.error("Error in saveToConfiguration for {}", providerKey, ex); } } }
private void checkApplicationsOk( String orgName) throws Exception { if (logger.isDebugEnabled()) { logger.debug("\n\nChecking applications OK\n"); } for (int i=0; i<10; i++) { String appName = orgName + "/application" + i; UUID uuid = setup.getEmf().lookupApplication(appName); assertTrue ("Should be able to get application", uuid != null ); EntityManager em = setup.getEmf().getEntityManager( uuid ); Application app = em.getApplication(); assertEquals( appName, app.getName() ); Results results = em.searchCollection( em.getApplicationRef(), "things", Query.fromQL("select *")); assertEquals( "Should have 10 entities", 10, results.size() ); } }
/** * Encapsulates the dictionary lookup for any configuration required */ protected Map<Object, Object> loadConfigurationFor(String providerKey) { try { return entityManager.getDictionaryAsMap(entityManager.getApplication(), providerKey); } catch (Exception ex) { logger.error("Error in loadConfigurationFor for {}", providerKey, ex); } return null; }
private void initMgmtAppInternal() { EntityManager em = getEntityManager(getManagementAppId()); indexService.queueInitializeApplicationIndex(CpNamingUtils.getApplicationScope(getManagementAppId())); try { if ( em.getApplication() == null ) { logger.info("Creating management application"); Map mgmtAppProps = new HashMap<String, Object>(); mgmtAppProps.put(PROPERTY_NAME, CassandraService.MANAGEMENT_APPLICATION); em.create( getManagementAppId(), TYPE_APPLICATION, mgmtAppProps); em.getApplication(); } } catch (Exception ex) { throw new RuntimeException("Fatal error creating management application", ex); } }
@Override public void doWrite(EntityManager em, FileImport fileImport, FileImportTracker tracker) { try { if (logger.isTraceEnabled()) { logger.trace("Writing imported entity {}:{} into app {}", entityType, entityUuid, em.getApplication().getUuid()); } em.create(entityUuid, entityType, properties); tracker.entityWritten(); } catch (Exception e) { logger.error("Error writing entity. From file:{}", fileImport.getFileName(), e); tracker.entityFailed(e.getMessage() + " From file: " + fileImport.getFileName()); } } }
public ServiceResults deleteGroupRole( UUID groupId, String roleName ) throws Exception { em.removeGroupFromRole( groupId, roleName ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); return getGroupRoles( groupId ); }
public ServiceResults grantApplicationRolePermission( String roleName, String permission ) throws Exception { em.grantRolePermission(roleName, permission); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); return getApplicationRolePermissions( roleName ); }
public ServiceResults addGroupRole( UUID groupId, String roleName ) throws Exception { em.addGroupToRole( groupId, roleName ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); return getGroupRoles( groupId ); }
public ServiceResults revokeApplicationRolePermission( String roleName, String permission ) throws Exception { em.revokeRolePermission( roleName, permission ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); return getApplicationRolePermissions( roleName ); }
@Override public ServiceResults postEntityDictionary( ServiceContext context, List<EntityRef> refs, EntityDictionaryEntry dictionary, ServicePayload payload ) throws Exception { if ( "permissions".equalsIgnoreCase( dictionary.getName() ) ) { EntityRef entityRef = refs.get( 0 ); checkPermissionsForEntitySubPath( context, entityRef, "permissions" ); String permission = payload.getStringProperty( "permission" ); if ( isBlank( permission ) ) { return null; } em.grantUserPermission( entityRef.getUuid(), permission ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); return genericServiceResults().withData( em.getUserPermissions( entityRef.getUuid() ) ); } return super.postEntityDictionary( context, refs, dictionary, payload ); }
@Override public ServiceResults postEntityDictionary( ServiceContext context, List<EntityRef> refs, EntityDictionaryEntry dictionary, ServicePayload payload ) throws Exception { if ( "permissions".equalsIgnoreCase( dictionary.getName() ) ) { EntityRef entityRef = refs.get( 0 ); checkPermissionsForEntitySubPath( context, entityRef, "permissions" ); String permission = payload.getStringProperty( "permission" ); if ( isBlank( permission ) ) { return null; } em.grantGroupPermission( entityRef.getUuid(), permission ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); return genericServiceResults().withData( em.getGroupPermissions( entityRef.getUuid() ) ); } return super.postEntityDictionary( context, refs, dictionary, payload ); }
@Override public ServiceResults deleteItemById( ServiceContext context, UUID id ) throws Exception { User user = em.get( context.getOwner(), User.class ); ServiceResults results = getItemById( context, id ); if ( !results.isEmpty() ) { em.removeUserFromRole( user.getUuid(), results.getEntity().getName() ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); } return results; }
@Override public ServiceResults deleteItemByName( ServiceContext context, String name ) throws Exception { User user = em.get( context.getOwner(), User.class ); ServiceResults results = getItemByName( context, name ); if ( !results.isEmpty() ) { em.removeUserFromRole( user.getUuid(), results.getEntity().getName() ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); } return results; } }
@Test public void getAllApplications() throws Exception { final Application createdApplication = app.getEntityManager().getApplication();
@Override public ServiceResults postItemByName( ServiceContext context, String name ) throws Exception { User user = em.get( context.getOwner(), User.class ); Entity entity = sm.getService( "/roles" ).getEntity( context.getRequest(), name ); if ( entity != null ) { em.addUserToRole( user.getUuid(), entity.getName() ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); } return new ServiceResults( this, context, Type.COLLECTION, Results.fromRef( entity ), null, null ); }
@Test public void verifyConfigureOk() throws Exception { Application application = setup.getEmf().getEntityManager( applicationId ).getApplication(); Map fbProps = MapUtils.hashMap( "api_url", "localhost" ); FacebookProvider fp = ( FacebookProvider ) providerFactory.facebook( application ); assertNotNull( fp ); fp.saveToConfiguration( "facebookProvider", fbProps ); fp.configure(); Map map = fp.loadConfigurationFor( "facebookProvider" ); assertEquals( "localhost", map.get( "api_url" ) ); } }
@Override public ServiceResults postItemById( ServiceContext context, UUID id ) throws Exception { User user = em.get( context.getOwner(), User.class ); Entity entity = sm.getService( "/roles" ).getEntity( context.getRequest(), id ); if ( entity != null ) { em.addUserToRole( user.getUuid(), entity.getName() ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); } return new ServiceResults( this, context, Type.COLLECTION, Results.fromRef( entity ), null, null ); }
@Test public void verifyLiveConnect() throws Exception { Application application = setup.getEmf().getEntityManager( applicationId ).getApplication(); Map pingProps = MapUtils.hashMap( "api_url", "" ).map( "client_secret", "" ) .map( "client_id", "dev.app.appservicesvalidation" ); PingIdentityProvider pingProvider = ( PingIdentityProvider ) setup.getProviderFactory().pingident( application ); pingProvider.saveToConfiguration( pingProps ); pingProvider.configure(); User user = pingProvider.createOrAuthenticate( "u0qoW7TS9eT8Vmt7UzrEWrhHbhDK" ); assertNotNull( user ); } }
@Test @Category(ExperimentalTest.class) public void verifyGetOrCreateOk() throws Exception { Application application = setup.getEmf().getEntityManager( applicationId ).getApplication(); Map fb_user = MapUtils.hashMap( "id", "12345678" ).map( "name", "Facebook User" ).map( "username", "fb.user" ); FacebookProvider facebookProvider = ( FacebookProvider ) providerFactory.facebook( application ); String fb_access_token = "CAAE...NJIZD"; User user1 = facebookProvider.createOrAuthenticate( fb_access_token ); assertNotNull( user1 ); }
@Test public void appDefaultExpiration() throws Exception { ApplicationInfo appInfo = newOrgAppAdminRule.getApplicationInfo(); EntityManager em = setup.getEmf().getEntityManager( appInfo.getId() ); Application app = em.getApplication(); AuthPrincipalInfo userPrincipal = new AuthPrincipalInfo( AuthPrincipalType.APPLICATION_USER, UUIDUtils.newTimeUUID(), app.getUuid() ); String token = setup.getTokenSvc().createToken( TokenCategory.ACCESS, null, userPrincipal, null, 0 ); assertNotNull( token ); TokenInfo tokenInfo = setup.getTokenSvc().getTokenInfo( token ); assertNotNull( tokenInfo ); assertEquals( TokenServiceImpl.LONG_TOKEN_AGE, tokenInfo.getDuration() ); }