public UUID getApplicationId() { return application.getUuid(); }
if ( app != null && app.getName() == null ) { throw new RuntimeException( "Name is null for application " + appId, throwable );
/** Get the max ttl per app. This is null safe,and will return the default in the case of missing data */ private long getMaxTtl( TokenCategory tokenCategory, AuthPrincipalInfo principal ) throws Exception { if ( principal == null ) { return maxPersistenceTokenAge; } long defaultMaxTtlForTokenType = getExpirationForTokenType( tokenCategory ); Application application = emf.getEntityManager( principal.getApplicationId() ) .get( principal.getApplicationId(), Application.class ); if ( application == null ) { return defaultMaxTtlForTokenType; } // set the max to the default long maxTokenTtl = defaultMaxTtlForTokenType; // it's been defined on the expiration, override it if ( application.getAccesstokenttl() != null ) { maxTokenTtl = application.getAccesstokenttl(); // it's set to 0 which equals infinity, set our expiration to // LONG.MAX if ( maxTokenTtl == 0 ) { maxTokenTtl = Long.MAX_VALUE; } } return maxTokenTtl; }
collectionName, em.getApplication().getName() ); setup.getEntityIndex().refresh(em.getApplicationId()); put( "path", organization.getName() + em.getApplication().getName()); put( "organizationId", organization.getUuid()); put( "applicationId", em.getApplication().getUuid() ); put( "collectionName", collectionName); put( "properties", new HashMap<String, Object>() {{
@Test public void appExpiration() throws Exception { ApplicationInfo appInfo = newOrgAppAdminRule.getApplicationInfo(); EntityManager em = setup.getEmf().getEntityManager( appInfo.getId() ); Application app = em.getApplication(); long appTokenAge = 1000; app.setAccesstokenttl( appTokenAge ); em.updateApplication( app ); AuthPrincipalInfo userPrincipal = new AuthPrincipalInfo( AuthPrincipalType.APPLICATION_USER, UUIDUtils.newTimeUUID(), app.getUuid() ); String token = setup.getTokenSvc().createToken( TokenCategory.ACCESS, null, userPrincipal, null, 0 ); long start = System.currentTimeMillis(); assertNotNull( token ); TokenInfo tokenInfo = setup.getTokenSvc().getTokenInfo( token ); assertNotNull( tokenInfo ); assertEquals( appTokenAge, tokenInfo.getDuration() ); /** * Sleep at least expirationTime millis to allow token to expire */ Thread.sleep( appTokenAge - ( System.currentTimeMillis() - start ) + 1000 ); boolean invalidTokenException = false; try { setup.getTokenSvc().getTokenInfo( token ); } catch ( ExpiredTokenException ite ) { invalidTokenException = true; } assertTrue( invalidTokenException ); }
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 ); }
/** * Create test entities of a specified type. * First two entities are connected. */ private void createTestEntities(final EntityManager em, Map<UUID, Entity> thingsMap, List<Entity> things, final String type) throws Exception { logger.debug("\n\nCreating new {} collection in application {}\n", type, em.getApplication().getName()); setup.getEntityIndex().refresh(em.getApplicationId()); List<Entity> created = new ArrayList<>(); for (int i = 0; i < 10; i++) { final int count = i; Entity e = em.create(type, new HashMap<String, Object>() {{ put("name", em.getApplication().getName() + "-" + type + "-" + count); put("originalAppId", em.getApplication().getUuid()); put("originalAppName", em.getApplication().getName()); }}); thingsMap.put(e.getUuid(), e); things.add(e); created.add(e); } // first two things are related to each other em.createConnection(new SimpleEntityRef(type, created.get(0).getUuid()), "related", new SimpleEntityRef(type, created.get(1).getUuid())); em.createConnection(new SimpleEntityRef(type, created.get(1).getUuid()), "related", new SimpleEntityRef(type, created.get(0).getUuid())); setup.getEntityIndex().refresh(em.getApplicationId()); }
app.setAccesstokenttl( appTokenAge ); new AuthPrincipalInfo( AuthPrincipalType.APPLICATION_USER, UUIDUtils.newTimeUUID(), app.getUuid() );
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 ); }
throw e; applicationId = application.getUuid();
logger.debug("\n\nImport into new app {}\n", em.getApplication().getName() ); final Import importEntity = importService.schedule(em.getApplication().getUuid(), new HashMap<String, Object>() {{ put( "path", organization.getName() + em.getApplication().getName() ); put( "organizationId", organization.getUuid() ); put( "applicationId", em.getApplication().getUuid() ); put( "properties", new HashMap<String, Object>() {{ put( "storage_provider", "s3" );
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 ); }
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() ); } }
public SignInAsProvider facebook( Application application ) { FacebookProvider facebookProvider = new FacebookProvider( emf.getEntityManager( application.getUuid() ), managementService ); facebookProvider.configure(); return facebookProvider; }
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 ); }
public SignInAsProvider pingident( Application application ) { PingIdentityProvider pingIdentityProvider = new PingIdentityProvider( emf.getEntityManager( application.getUuid() ), managementService ); pingIdentityProvider.configure(); return pingIdentityProvider; } }
@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 ); }
public SignInAsProvider foursquare( Application application ) { FoursquareProvider foursquareProvider = new FoursquareProvider( emf.getEntityManager( application.getUuid() ), managementService ); foursquareProvider.configure(); return foursquareProvider; }
@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 ); }