@Test public void principalAndCredentialsAreEmptyWithNoAuthentication() { AuthenticationSource source = new SpringSecurityAuthenticationSource(); assertThat(source.getPrincipal()).isEqualTo(""); assertThat(source.getCredentials()).isEqualTo(""); }
@Test(expected = IllegalArgumentException.class) public void getPrincipalRejectsNonLdapUserDetailsObject() { AuthenticationSource source = new SpringSecurityAuthenticationSource(); SecurityContextHolder.getContext().setAuthentication( new TestingAuthenticationToken(new Object(), "password")); source.getPrincipal(); }
@Test public void expectedCredentialsAreReturned() { AuthenticationSource source = new SpringSecurityAuthenticationSource(); SecurityContextHolder.getContext().setAuthentication( new TestingAuthenticationToken(new Object(), "password")); assertThat(source.getCredentials()).isEqualTo("password"); }
@Test public void principalIsEmptyForAnonymousUser() { AuthenticationSource source = new SpringSecurityAuthenticationSource(); SecurityContextHolder.getContext().setAuthentication( new AnonymousAuthenticationToken("key", "anonUser", AuthorityUtils .createAuthorityList("ignored"))); assertThat(source.getPrincipal()).isEqualTo(""); }
/** * Checks if the target's principal is not empty; if not, the credentials * from the target is returned - otherwise return the * <code>defaultPassword</code>. * * @return the target's password if the target's principal is not empty, the * <code>defaultPassword</code> otherwise. */ public String getCredentials() { if (StringUtils.hasText(target.getPrincipal())) { return target.getCredentials(); } else { return defaultPassword; } }
@Test public void expectedPrincipalIsReturned() { LdapUserDetailsImpl.Essence user = new LdapUserDetailsImpl.Essence(); user.setUsername("joe"); user.setDn(new DistinguishedName("uid=joe,ou=users")); AuthenticationSource source = new SpringSecurityAuthenticationSource(); SecurityContextHolder.getContext().setAuthentication( new TestingAuthenticationToken(user.createUserDetails(), null)); assertThat(source.getPrincipal()).isEqualTo("uid=joe,ou=users"); } }
/** * Checks if the target's principal is not empty; if not, the credentials * from the target is returned - otherwise return the * <code>defaultPassword</code>. * * @return the target's password if the target's principal is not empty, the * <code>defaultPassword</code> otherwise. */ public String getCredentials() { if (StringUtils.hasText(target.getPrincipal())) { return target.getCredentials(); } else { return defaultPassword; } }
/** * Checks if the target's principal is not empty; if not, this is returned - * otherwise return the <code>defaultPassword</code>. * * @return the target's principal if it is not empty, the * <code>defaultPassword</code> otherwise. */ public String getPrincipal() { String principal = target.getPrincipal(); if (StringUtils.hasText(principal)) { return principal; } else { return defaultUser; } }
/** * Checks if the target's principal is not empty; if not, the credentials * from the target is returned - otherwise return the * <code>defaultPassword</code>. * * @return the target's password if the target's principal is not empty, the * <code>defaultPassword</code> otherwise. */ public String getCredentials() { if (StringUtils.hasText(target.getPrincipal())) { return target.getCredentials(); } else { return defaultPassword; } }
/** * Checks if the target's principal is not empty; if not, this is returned - * otherwise return the <code>defaultPassword</code>. * * @return the target's principal if it is not empty, the * <code>defaultPassword</code> otherwise. */ public String getPrincipal() { String principal = target.getPrincipal(); if (StringUtils.hasText(principal)) { return principal; } else { return defaultUser; } }
/** * Checks if the target's principal is not empty; if not, the credentials * from the target is returned - otherwise return the * <code>defaultPassword</code>. * * @return the target's password if the target's principal is not empty, the * <code>defaultPassword</code> otherwise. */ public String getCredentials() { if (StringUtils.hasText(target.getPrincipal())) { return target.getCredentials(); } else { return defaultPassword; } }
/** * Checks if the target's principal is not empty; if not, this is returned - * otherwise return the <code>defaultPassword</code>. * * @return the target's principal if it is not empty, the * <code>defaultPassword</code> otherwise. */ public String getPrincipal() { String principal = target.getPrincipal(); if (StringUtils.hasText(principal)) { return principal; } else { return defaultUser; } }
public DirContext getReadWriteContext() { return doGetContext( authenticationSource.getPrincipal(), authenticationSource.getCredentials(), DONT_DISABLE_POOLING); }
/** * Checks if the target's principal is not empty; if not, this is returned - * otherwise return the <code>defaultPassword</code>. * * @return the target's principal if it is not empty, the * <code>defaultPassword</code> otherwise. */ public String getPrincipal() { String principal = target.getPrincipal(); if (StringUtils.hasText(principal)) { return principal; } else { return defaultUser; } }
public DirContext getReadWriteContext() { return doGetContext( authenticationSource.getPrincipal(), authenticationSource.getCredentials(), DONT_DISABLE_POOLING); }
@Test public void testGetPrincipal_TargetHasNoPrincipal() { when(authenticationSourceMock.getPrincipal()).thenReturn(""); String principal = tested.getPrincipal(); assertThat(principal).isEqualTo(DEFAULT_USER); }
public DirContext getReadWriteContext() { return doGetContext( authenticationSource.getPrincipal(), authenticationSource.getCredentials(), DONT_DISABLE_POOLING); }
@Test public void testGetPrincipal_TargetHasPrincipal() { when(authenticationSourceMock.getPrincipal()).thenReturn("cn=someUser"); String principal = tested.getPrincipal(); assertThat(principal).isEqualTo("cn=someUser"); }
public DirContext getReadWriteContext() { return doGetContext( authenticationSource.getPrincipal(), authenticationSource.getCredentials(), DONT_DISABLE_POOLING); }
public DirContext getReadOnlyContext() { if (!anonymousReadOnly) { return doGetContext( authenticationSource.getPrincipal(), authenticationSource.getCredentials(), DONT_DISABLE_POOLING); } else { return createContext(getAnonymousEnv()); } }