Tabnine Logo
FieldUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
FieldUtils
in
org.springframework.security.util

Best Java code snippets using org.springframework.security.util.FieldUtils (Showing top 20 results out of 315)

origin: spring-projects/spring-security

  @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) {
    }
  }
}
origin: spring-projects/spring-security

public static Object getProtectedFieldValue(String protectedField, Object object) {
  Field field = FieldUtils.getField(object.getClass(), protectedField);
  try {
    field.setAccessible(true);
    return field.get(object);
  }
  catch (Exception ex) {
    ReflectionUtils.handleReflectionException(ex);
    return null; // unreachable - previous line throws exception
  }
}
origin: spring-projects/spring-security

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));
}
origin: spring-projects/spring-security

  private static <T> T getFieldValue(Object bean, String fieldName) throws IllegalAccessException {
    return (T) FieldUtils.getFieldValue(bean, fieldName);
  }
}
origin: spring-projects/spring-security

private MutableAcl initializeTransientFields(MutableAcl value) {
  if (value instanceof AclImpl) {
    FieldUtils.setProtectedFieldValue("aclAuthorizationStrategy", value,
        this.aclAuthorizationStrategy);
    FieldUtils.setProtectedFieldValue("permissionGrantingStrategy", value,
        this.permissionGrantingStrategy);
  }
  if (value.getParentAcl() != null) {
    initializeTransientFields((MutableAcl) value.getParentAcl());
  }
  return value;
}
origin: spring-projects/spring-security

@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();
}
origin: spring-projects/spring-security

private <T> T getFieldValue(Object target, String fieldName) {
  try {
    return (T) FieldUtils.getFieldValue(target, fieldName);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
origin: spring-projects/spring-security

private MutableAcl initializeTransientFields(MutableAcl value) {
  if (value instanceof AclImpl) {
    FieldUtils.setProtectedFieldValue("aclAuthorizationStrategy", value,
        this.aclAuthorizationStrategy);
    FieldUtils.setProtectedFieldValue("permissionGrantingStrategy", value,
        this.permissionGrantingStrategy);
  }
  if (value.getParentAcl() != null) {
    initializeTransientFields((MutableAcl) value.getParentAcl());
  }
  return value;
}
origin: spring-projects/spring-security

  public static void setProtectedFieldValue(String protectedField, Object object,
      Object newValue) {
    Field field = FieldUtils.getField(object.getClass(), protectedField);

    try {
      field.setAccessible(true);
      field.set(object, newValue);
    }
    catch (Exception ex) {
      ReflectionUtils.handleReflectionException(ex);
    }
  }
}
origin: apache/incubator-rya

/**
 * @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);
}
origin: spring-projects/spring-security

@Test
public void groupQueryIsParsedCorrectly() throws Exception {
  setContext("<jdbc-user-service id='myUserService' "
      + "data-source-ref='dataSource' "
      + "group-authorities-by-username-query='blah blah'/>" + DATA_SOURCE);
  JdbcUserDetailsManager mgr = (JdbcUserDetailsManager) appContext
      .getBean("myUserService");
  assertThat(FieldUtils.getFieldValue(mgr, "groupAuthoritiesByUsernameQuery")).isEqualTo("blah blah");
  assertThat((Boolean) FieldUtils.getFieldValue(mgr, "enableGroups")).isTrue();
}
origin: apache/servicemix-bundles

private MutableAcl initializeTransientFields(MutableAcl value) {
  if (value instanceof AclImpl) {
    FieldUtils.setProtectedFieldValue("aclAuthorizationStrategy", value,
        this.aclAuthorizationStrategy);
    FieldUtils.setProtectedFieldValue("permissionGrantingStrategy", value,
        this.permissionGrantingStrategy);
  }
  if (value.getParentAcl() != null) {
    initializeTransientFields((MutableAcl) value.getParentAcl());
  }
  return value;
}
origin: org.springframework.security/spring-security-core

public static Object getProtectedFieldValue(String protectedField, Object object) {
  Field field = FieldUtils.getField(object.getClass(), protectedField);
  try {
    field.setAccessible(true);
    return field.get(object);
  }
  catch (Exception ex) {
    ReflectionUtils.handleReflectionException(ex);
    return null; // unreachable - previous line throws exception
  }
}
origin: qcadoo/mes

  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);
    }
  }
}
origin: spring-projects/spring-security

@Test
public void usernameAndAuthorityQueriesAreParsedCorrectly() throws Exception {
  String userQuery = "select username, password, true from users where username = ?";
  String authoritiesQuery = "select username, authority from authorities where username = ? and 1 = 1";
  setContext("<jdbc-user-service id='myUserService' "
      + "data-source-ref='dataSource' " + "users-by-username-query='"
      + userQuery + "' " + "authorities-by-username-query='" + authoritiesQuery
      + "'/>" + DATA_SOURCE);
  JdbcUserDetailsManager mgr = (JdbcUserDetailsManager) appContext
      .getBean("myUserService");
  assertThat(FieldUtils.getFieldValue(mgr, "usersByUsernameQuery")).isEqualTo(userQuery);
  assertThat(FieldUtils.getFieldValue(mgr, "authoritiesByUsernameQuery")).isEqualTo(authoritiesQuery);
  assertThat(mgr.loadUserByUsername("rod") != null).isTrue();
}
origin: apache/servicemix-bundles

private MutableAcl initializeTransientFields(MutableAcl value) {
  if (value instanceof AclImpl) {
    FieldUtils.setProtectedFieldValue("aclAuthorizationStrategy", value,
        this.aclAuthorizationStrategy);
    FieldUtils.setProtectedFieldValue("permissionGrantingStrategy", value,
        this.permissionGrantingStrategy);
  }
  if (value.getParentAcl() != null) {
    initializeTransientFields((MutableAcl) value.getParentAcl());
  }
  return value;
}
origin: spring-projects/spring-security

/**
 * Returns the value of a (nested) field on a bean. Intended for testing.
 * @param bean the object
 * @param fieldName the field name, with "." separating nested properties
 * @return the value of the nested field
 */
public static Object getFieldValue(Object bean, String fieldName)
    throws IllegalAccessException {
  Assert.notNull(bean, "Bean cannot be null");
  Assert.hasText(fieldName, "Field name required");
  String[] nestedFields = StringUtils.tokenizeToStringArray(fieldName, ".");
  Class<?> componentClass = bean.getClass();
  Object value = bean;
  for (String nestedField : nestedFields) {
    Field field = getField(componentClass, nestedField);
    field.setAccessible(true);
    value = field.get(value);
    if (value != null) {
      componentClass = value.getClass();
    }
  }
  return value;
}
origin: apache/servicemix-bundles

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));
}
origin: spring-projects/spring-security

@Test
public void eventsArePublishedByDefault() throws Exception {
  ConfigurableApplicationContext appContext = this.spring.context(CONTEXT)
    .getContext();
  AuthListener listener = new AuthListener();
  appContext.addApplicationListener(listener);
  ProviderManager pm = (ProviderManager) appContext
      .getBeansOfType(ProviderManager.class).values().toArray()[0];
  Object eventPublisher = FieldUtils.getFieldValue(pm, "eventPublisher");
  assertThat(eventPublisher).isNotNull();
  assertThat(eventPublisher instanceof DefaultAuthenticationEventPublisher).isTrue();
  pm.authenticate(new UsernamePasswordAuthenticationToken("bob", "bobspassword"));
  assertThat(listener.events).hasSize(1);
}
origin: org.springframework.security/spring-security-core

  public static void setProtectedFieldValue(String protectedField, Object object,
      Object newValue) {
    Field field = FieldUtils.getField(object.getClass(), protectedField);

    try {
      field.setAccessible(true);
      field.set(object, newValue);
    }
    catch (Exception ex) {
      ReflectionUtils.handleReflectionException(ex);
    }
  }
}
org.springframework.security.utilFieldUtils

Javadoc

Offers static methods for directly manipulating fields.

Most used methods

  • getProtectedFieldValue
  • getField
    Attempts to locate the specified field on the class.
  • getFieldValue
    Returns the value of a (nested) field on a bean. Intended for testing.
  • setProtectedFieldValue
  • <init>

Popular in Java

  • Creating JSON documents from java classes using gson
  • onRequestPermissionsResult (Fragment)
  • startActivity (Activity)
  • getResourceAsStream (ClassLoader)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • ImageIO (javax.imageio)
  • JFrame (javax.swing)
  • JOptionPane (javax.swing)
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now