use of org.springframework.security.provisioning.JdbcUserDetailsManager in project spring-security by spring-projects.
the class JdbcUserServiceBeanDefinitionParserTests method rolePrefixIsUsedWhenSet.
@Test
public void rolePrefixIsUsedWhenSet() {
setContext("<jdbc-user-service id='myUserService' role-prefix='PREFIX_' data-source-ref='dataSource'/>" + DATA_SOURCE);
JdbcUserDetailsManager mgr = (JdbcUserDetailsManager) appContext.getBean("myUserService");
UserDetails rod = mgr.loadUserByUsername("rod");
assertThat(AuthorityUtils.authorityListToSet(rod.getAuthorities())).contains("PREFIX_ROLE_SUPERVISOR");
}
use of org.springframework.security.provisioning.JdbcUserDetailsManager in project spring-security by spring-projects.
the class JdbcUserDetailsManagerConfigurer method groupAuthoritiesByUsername.
/**
* An SQL statement to query user's group authorities given a username. For example:
*
* <code>
* select
* g.id, g.group_name, ga.authority
* from
* groups g, group_members gm, group_authorities ga
* where
* gm.username = ? and g.id = ga.group_id and g.id = gm.group_id
* </code>
*
* @param query The query to use for selecting the authorities by group. Must contain
* a single parameter for the username.
* @return The {@link JdbcUserDetailsManagerConfigurer} used for additional
* customizations
* @throws Exception
*/
public JdbcUserDetailsManagerConfigurer<B> groupAuthoritiesByUsername(String query) throws Exception {
JdbcUserDetailsManager userDetailsService = getUserDetailsService();
userDetailsService.setEnableGroups(true);
userDetailsService.setGroupAuthoritiesByUsernameQuery(query);
return this;
}
use of org.springframework.security.provisioning.JdbcUserDetailsManager in project spring-security by spring-projects.
the class JdbcUserServiceBeanDefinitionParserTests method groupQueryIsParsedCorrectly.
@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();
}
use of org.springframework.security.provisioning.JdbcUserDetailsManager in project spring-security by spring-projects.
the class JdbcUserServiceBeanDefinitionParserTests method validUsernameIsFound.
@Test
public void validUsernameIsFound() {
setContext("<jdbc-user-service data-source-ref='dataSource'/>" + DATA_SOURCE);
JdbcUserDetailsManager mgr = (JdbcUserDetailsManager) appContext.getBean(BeanIds.USER_DETAILS_SERVICE);
assertThat(mgr.loadUserByUsername("rod")).isNotNull();
}
use of org.springframework.security.provisioning.JdbcUserDetailsManager in project spring-security by spring-projects.
the class JdbcUserServiceBeanDefinitionParserTests method usernameAndAuthorityQueriesAreParsedCorrectly.
@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();
}
Aggregations