private static <T> T getFieldValue(Object bean, String fieldName) throws IllegalAccessException { return (T) FieldUtils.getFieldValue(bean, fieldName); } }
/** * Creates a UserDetailsResourceFactoryBean with a resource from the provided String * * @param users the string representing the users * @return the UserDetailsResourceFactoryBean */ public static UserDetailsResourceFactoryBean fromString(String users) { InMemoryResource resource = new InMemoryResource(users); return fromResource(resource); } }
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; }
@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(expected = IllegalArgumentException.class) public void exceptionIsRaisedIfArgInfoOmittedAndMethodNameIsNotUnique() { MethodInvocationUtils.createFromClass(BusinessServiceImpl.class, "methodReturningAList"); }
@Test(expected = IllegalArgumentException.class) public void rejectsNullAuthentication() { new AuthorizationFailureEvent(new SimpleMethodInvocation(), attributes, null, exception); }
@Test public void createFromObjectLocatesExistingMethods() throws Exception { AdvisedTarget t = new AdvisedTarget(); // Just lie about interfaces t.setInterfaces(new Class[] { Serializable.class, MethodInvocation.class, Blah.class }); MethodInvocation mi = MethodInvocationUtils.create(t, "blah"); assertThat(mi).isNotNull(); t.setProxyTargetClass(true); mi = MethodInvocationUtils.create(t, "blah"); assertThat(mi).isNotNull(); assertThat(MethodInvocationUtils.create(t, "blah", "non-existent arg")).isNull(); }
/** * Create a ReactiveUserDetailsServiceResourceFactoryBean with a String that is in the * format defined in {@link UserDetailsResourceFactoryBean}. * * @param users the users in the format defined in {@link UserDetailsResourceFactoryBean} * @return the ReactiveUserDetailsServiceResourceFactoryBean */ public static ReactiveUserDetailsServiceResourceFactoryBean fromString(String users) { ReactiveUserDetailsServiceResourceFactoryBean result = new ReactiveUserDetailsServiceResourceFactoryBean(); result.setResource(new InMemoryResource(users)); return result; } }
@Test public void createFromClassReturnsMethodIfArgInfoOmittedAndMethodNameIsUnique() { MethodInvocation mi = MethodInvocationUtils.createFromClass( BusinessServiceImpl.class, "methodReturningAnArray"); assertThat(mi).isNotNull(); }
@Test(expected = IllegalArgumentException.class) public void rejectsNullException() { new AuthorizationFailureEvent(new SimpleMethodInvocation(), attributes, foo, null); }
private <T> T getFieldValue(Object target, String fieldName) { try { return (T) FieldUtils.getFieldValue(target, fieldName); } catch (Exception e) { throw new RuntimeException(e); } }
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; }
/** * Create a UserDetailsManagerResourceFactoryBean with a String that is in the * format defined in {@link UserDetailsResourceFactoryBean}. * * @param users the users in the format defined in {@link UserDetailsResourceFactoryBean} * @return the UserDetailsManagerResourceFactoryBean */ public static UserDetailsManagerResourceFactoryBean fromString(String users) { UserDetailsManagerResourceFactoryBean result = new UserDetailsManagerResourceFactoryBean(); result.setResource(new InMemoryResource(users)); return result; } }
@Test public void createFromClassReturnsMethodIfGivenArgInfoForMethodWithArgs() { MethodInvocation mi = MethodInvocationUtils.createFromClass(null, String.class, "compareTo", new Class<?>[] { String.class }, new Object[] { "" }); assertThat(mi).isNotNull(); }
@Test(expected = IllegalArgumentException.class) public void rejectsNullAttributesList() { new AuthorizationFailureEvent(new SimpleMethodInvocation(), null, foo, exception); }
@Bean public ReactiveUserDetailsServiceResourceFactoryBean userDetailsService() { return ReactiveUserDetailsServiceResourceFactoryBean.fromResource(new InMemoryResource("user=password,ROLE_USER")); } }
@Bean public UserDetailsManagerResourceFactoryBean userDetailsService() { return UserDetailsManagerResourceFactoryBean.fromResource(new InMemoryResource("user=password,ROLE_USER")); } }
public InMemoryXmlWebApplicationContext(String xml, String secVersion, ApplicationContext parent) { String fullXml = BEANS_OPENING + secVersion + ".xsd'>\n" + xml + BEANS_CLOSE; inMemoryXml = new InMemoryResource(fullXml); setAllowBeanDefinitionOverriding(true); setParent(parent); }
public InMemoryXmlApplicationContext(String xml, String secVersion, ApplicationContext parent) { String fullXml = BEANS_OPENING + secVersion + ".xsd'>\n" + xml + BEANS_CLOSE; inMemoryXml = new InMemoryResource(fullXml); setAllowBeanDefinitionOverriding(true); setParent(parent); refresh(); }
@Test public void getObjectWhenPropertiesResourceSingleUserThenThrowsGetsSingleUser() throws Exception { factory.setResource(new InMemoryResource("user=password,ROLE_USER")); assertLoaded(); }