org.springframework.security.authentication.encoding.LdapShaPasswordEncoder Java Examples

The following examples show how to use org.springframework.security.authentication.encoding.LdapShaPasswordEncoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 6 votes vote down vote up
/**
     * Configure AuthenticationManager with inMemory credentials.
     *
     * NOTE:
     * Due to a known limitation with JavaConfig:
     * <a href="https://jira.spring.io/browse/SPR-13779">
     *     https://jira.spring.io/browse/SPR-13779</a>
     *
     * We cannot use the following to expose a {@link UserDetailsManager}
     * <pre>
     *     http.authorizeRequests()
     * </pre>
     *
     * In order to expose {@link UserDetailsManager} as a bean, we must create  @Bean
     *
     * @see {@link super.userDetailsService()}
     * @see {@link com.packtpub.springsecurity.service.DefaultCalendarService}
     *
     * @param auth       AuthenticationManagerBuilder
     * @throws Exception Authentication exception
     */
    @Override
    public void configure(final AuthenticationManagerBuilder auth) throws Exception {
        auth
                .ldapAuthentication()
                .userSearchBase("")
                .userSearchFilter("(uid={0})")
                .groupSearchBase("ou=Groups")
                .groupSearchFilter("(uniqueMember={0})")
                .userDetailsContextMapper(new InetOrgPersonContextMapper())
                .contextSource(contextSource())
//                .contextSource()
//                    .managerDn("uid=admin,ou=system")
//                    .managerPassword("secret")
//                    .url("ldap://localhost:33389/dc=jbcpcalendar,dc=com")
//                    .root("dc=jbcpcalendar,dc=com")
//                    .ldif("classpath:/ldif/calendar.ldif")
//                .and()
                    .passwordCompare()
                    // Supports {SHA} and {SSHA}
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword")
        ;
    }
 
Example #2
Source File: PasswordEncoderTest.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSsha(){
	LdapShaPasswordEncoder encoder = new LdapShaPasswordEncoder();
	
	String rawPass = "test";
	String salt = "@#%AS%&DF_=PJ}{EB23+42342*()*^%$)_(*%^)";
	String res = encoder.encodePassword(rawPass, salt.getBytes());
	System.out.println("res:"+res);
	boolean valid = encoder.isPasswordValid(res, rawPass, "aasd@#$@3");
	Assert.assertTrue(valid);
}
 
Example #3
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
/**
     * Configure AuthenticationManager with inMemory credentials.
     *
     * NOTE:
     * Due to a known limitation with JavaConfig:
     * <a href="https://jira.spring.io/browse/SPR-13779">
     *     https://jira.spring.io/browse/SPR-13779</a>
     *
     * We cannot use the following to expose a {@link UserDetailsManager}
     * <pre>
     *     http.authorizeRequests()
     * </pre>
     *
     * In order to expose {@link UserDetailsManager} as a bean, we must create  @Bean
     *
     * @see {@link super.userDetailsService()}
     * @see {@link com.packtpub.springsecurity.service.DefaultCalendarService}
     *
     * @param auth       AuthenticationManagerBuilder
     * @throws Exception Authentication exception
     */
    @Override
    public void configure(final AuthenticationManagerBuilder auth) throws Exception {
        auth
                .ldapAuthentication()
//                .ldapAuthoritiesPopulator(ldapAuthoritiesPopulator())
                .userSearchBase("")
                .userSearchFilter("(uid={0})")
                .groupSearchBase("ou=Groups")
                .groupSearchFilter("(uniqueMember={0})")
//                .userDetailsContextMapper(new InetOrgPersonContextMapper())
                .contextSource(contextSource())
                .passwordCompare()
                    // Supports {SHA} and {SSHA}
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword")
        ;
        /*
        <ldap-authentication-provider server-ref="ldapServer"
        user-search-filter="(uid={0})"
        group-search-base="ou=Groups"
        user-details-class="inetOrgPerson">


    <bean id="ldapAuthenticationProvider"
            class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
        <constructor-arg ref="ldapBindAuthenticator"/>
        <constructor-arg ref="ldapAuthoritiesPopulator"/>
        <property name="userDetailsContextMapper" ref="ldapUserDetailsContextMapper"/>
    </bean>

    <bean id="ldapBindAuthenticator"
            class="org.springframework.security.ldap.authentication.BindAuthenticator">
        <constructor-arg ref="ldapServer"/>
        <property name="userSearch" ref="ldapSearch"/>
    </bean>

//    <bean id="ldapSearch"
//            class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
//        <constructor-arg value=""/> <!-- use-search-base -->
//        <constructor-arg value="(uid={0})"/> <!-- user-search-filter -->
//        <constructor-arg ref="ldapServer"/>
//    </bean>

//    <bean id="ldapAuthoritiesPopulator"
//            class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
//        <constructor-arg ref="ldapServer"/>
//        <constructor-arg value="ou=Groups"/>
//        <property name="groupSearchFilter" value="(uniqueMember={0})"/>
//    </bean>

         */
    }
 
Example #4
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
/**
 * Configure AuthenticationManager with inMemory credentials.
 *
 * NOTE:
 * Due to a known limitation with JavaConfig:
 * <a href="https://jira.spring.io/browse/SPR-13779">
 *     https://jira.spring.io/browse/SPR-13779</a>
 *
 * We cannot use the following to expose a {@link UserDetailsManager}
 * <pre>
 *     http.authorizeRequests()
 * </pre>
 *
 * In order to expose {@link UserDetailsManager} as a bean, we must create  @Bean
 *
 * @see {@link super.userDetailsService()}
 * @see {@link com.packtpub.springsecurity.service.DefaultCalendarService}
 *
 * @param auth       AuthenticationManagerBuilder
 * @throws Exception Authentication exception
 */
@Override
public void configure(final AuthenticationManagerBuilder auth) throws Exception {
    auth
            .ldapAuthentication()
            .userSearchBase("")
            .userSearchFilter("(uid={0})")
            .groupSearchBase("ou=Groups")
            .groupSearchFilter("(uniqueMember={0})")
            .userDetailsContextMapper(new InetOrgPersonContextMapper())
            .contextSource(contextSource())
            .passwordCompare()
                // Supports {SHA} and {SSHA}
                .passwordEncoder(new LdapShaPasswordEncoder())
                .passwordAttribute("userPassword")
    ;
}