public void putInCache(MutableAcl acl) { Assert.notNull(acl, "Acl required"); Assert.notNull(acl.getObjectIdentity(), "ObjectIdentity required"); Assert.notNull(acl.getId(), "ID required"); if (this.aclAuthorizationStrategy == null) { if (acl instanceof AclImpl) { this.aclAuthorizationStrategy = (AclAuthorizationStrategy) FieldUtils .getProtectedFieldValue("aclAuthorizationStrategy", acl); this.permissionGrantingStrategy = (PermissionGrantingStrategy) FieldUtils .getProtectedFieldValue("permissionGrantingStrategy", acl); } } if ((acl.getParentAcl() != null) && (acl.getParentAcl() instanceof MutableAcl)) { putInCache((MutableAcl) acl.getParentAcl()); } cache.put(new Element(acl.getObjectIdentity(), acl)); cache.put(new Element(acl.getId(), acl)); }
@Test public void gettingAndSettingProtectedFieldIsSuccessful() throws Exception { new FieldUtils(); Object tc = new TestClass(); assertThat(FieldUtils.getProtectedFieldValue("protectedField", tc)).isEqualTo("x"); assertThat(FieldUtils.getFieldValue(tc, "nested.protectedField")).isEqualTo("z"); FieldUtils.setProtectedFieldValue("protectedField", tc, "y"); assertThat(FieldUtils.getProtectedFieldValue("protectedField", tc)).isEqualTo("y"); try { FieldUtils.getProtectedFieldValue("nonExistentField", tc); } catch (IllegalStateException expected) { } } }
@Test public void testDiskSerializationOfMutableAclObjectInstance() throws Exception { // Serialization test File file = File.createTempFile("SEC_TEST", ".object"); FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(acl); oos.close(); FileInputStream fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); MutableAcl retrieved = (MutableAcl) ois.readObject(); ois.close(); assertThat(retrieved).isEqualTo(acl); Object retrieved1 = FieldUtils.getProtectedFieldValue("aclAuthorizationStrategy", retrieved); assertThat(retrieved1).isNull(); Object retrieved2 = FieldUtils.getProtectedFieldValue( "permissionGrantingStrategy", retrieved); assertThat(retrieved2).isNull(); }
/** * @return The shell's {@link ConsoleReader}. */ public ConsoleReader getReader() { // XXX Spring Shell doesn't expose the reader that we need to use to // read values from a terminal, so use reflection to pull it out. return (ConsoleReader) FieldUtils.getProtectedFieldValue("reader", shell); }
private Session getCurrentSession() { DataDefinition dataDefinition = dataDefinitionService .get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY); Object dataAccessService = FieldUtils.getProtectedFieldValue("dataAccessService", dataDefinition); Object hibernateService = FieldUtils.getProtectedFieldValue("hibernateService", dataAccessService); try { return (Session) MethodUtils.invokeExactMethod(hibernateService, "getCurrentSession", new Object[0]); } catch (NoSuchMethodException e) { throw new IllegalStateException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new IllegalStateException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new IllegalStateException(e.getMessage(), e); } } }
public void putInCache(MutableAcl acl) { Assert.notNull(acl, "Acl required"); Assert.notNull(acl.getObjectIdentity(), "ObjectIdentity required"); Assert.notNull(acl.getId(), "ID required"); if (this.aclAuthorizationStrategy == null) { if (acl instanceof AclImpl) { this.aclAuthorizationStrategy = (AclAuthorizationStrategy) FieldUtils .getProtectedFieldValue("aclAuthorizationStrategy", acl); this.permissionGrantingStrategy = (PermissionGrantingStrategy) FieldUtils .getProtectedFieldValue("permissionGrantingStrategy", acl); } } if ((acl.getParentAcl() != null) && (acl.getParentAcl() instanceof MutableAcl)) { putInCache((MutableAcl) acl.getParentAcl()); } cache.put(new Element(acl.getObjectIdentity(), acl)); cache.put(new Element(acl.getId(), acl)); }
@SuppressWarnings("unchecked") @Autowired public SecuritySpringDataListener(final LocalContainerEntityManagerFactoryBean emf) { final SessionFactoryImpl sessionFactory = (SessionFactoryImpl) emf.getNativeEntityManagerFactory(); this.sqlFunctions = (Map<String, SQLFunction>) FieldUtils.getProtectedFieldValue("functionMap", sessionFactory.getSqlFunctionRegistry()); this.dialect = sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect(); }