public Essence(DirContextOperations ctx) { super(ctx); setCarLicense(ctx.getStringAttribute("carLicense")); setDepartmentNumber(ctx.getStringAttribute("departmentNumber")); setDestinationIndicator(ctx.getStringAttribute("destinationIndicator")); setDisplayName(ctx.getStringAttribute("displayName")); setEmployeeNumber(ctx.getStringAttribute("employeeNumber")); setHomePhone(ctx.getStringAttribute("homePhone")); setHomePostalAddress(ctx.getStringAttribute("homePostalAddress")); setInitials(ctx.getStringAttribute("initials")); setMail(ctx.getStringAttribute("mail")); setMobile(ctx.getStringAttribute("mobile")); setO(ctx.getStringAttribute("o")); setOu(ctx.getStringAttribute("ou")); setPostalAddress(ctx.getStringAttribute("postalAddress")); setPostalCode(ctx.getStringAttribute("postalCode")); setRoomNumber(ctx.getStringAttribute("roomNumber")); setStreet(ctx.getStringAttribute("street")); setTitle(ctx.getStringAttribute("title")); setUid(ctx.getStringAttribute("uid")); }
public Essence(DirContextOperations ctx) { super(ctx); setCn(ctx.getStringAttributes("cn")); setGivenName(ctx.getStringAttribute("givenName")); setSn(ctx.getStringAttribute("sn")); setDescription(ctx.getStringAttribute("description")); setTelephoneNumber(ctx.getStringAttribute("telephoneNumber")); Object passo = ctx.getObjectAttribute("userPassword"); if (passo != null) { String password = LdapUtils.convertPasswordToString(passo); setPassword(password); } }
protected Object doMapFromContext(DirContextOperations ctx) { Person person = new Person(); person.setFullname(ctx.getStringAttribute("cn")); person.setLastname(ctx.getStringAttribute("sn")); person.setPhone(ctx.getStringAttribute("telephoneNumber")); person.setDescription(ctx.getStringAttribute("description")); return person; } }
public Essence(DirContextOperations ctx) { super(ctx); setCn(ctx.getStringAttributes("cn")); setGivenName(ctx.getStringAttribute("givenName")); setSn(ctx.getStringAttribute("sn")); setDescription(ctx.getStringAttribute("description")); setTelephoneNumber(ctx.getStringAttribute("telephoneNumber")); Object passo = ctx.getObjectAttribute("userPassword"); if (passo != null) { String password = LdapUtils.convertPasswordToString(passo); setPassword(password); } }
@Override public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<GrantedAuthority> authorities) { LdapUserDetails details = (LdapUserDetails)super.mapUserFromContext(ctx, username, authorities); LdapUserDetailsWithAttributes detailsWithAttributes = new LdapUserDetailsWithAttributes(details); for(String attributeName : attributeMappings.keySet()) { detailsWithAttributes.setAttribute(attributeName, ctx.getStringAttribute(attributeMappings.get(attributeName))); } return detailsWithAttributes; }
public Essence(DirContextOperations ctx) { super(ctx); setCn(ctx.getStringAttributes("cn")); setSn(ctx.getStringAttribute("sn")); setDescription(ctx.getStringAttribute("description")); setTelephoneNumber(ctx.getStringAttribute("telephoneNumber")); Object passo = ctx.getObjectAttribute("userPassword"); if(passo != null) { String password = LdapUtils.convertPasswordToString(passo); setPassword(password); } }
protected GeoServerUser createUser(DirContextOperations dco) { GeoServerUser gsUser = new GeoServerUser(dco.getStringAttribute(userNameAttribute)); for (String attName : populatedAttributes) { try { Attribute att = dco.getAttributes().get(attName.toLowerCase()); if (att != null) { Object value = att.get(); if (value instanceof String) { gsUser.getProperties().put(attName, value); } } } catch (NamingException e) { LOGGER.log( Level.WARNING, "Could not populate value for user attribute " + attName, e); } } return gsUser; }
/** * This method depends on a DirObjectFactory ( * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) * being set in the ContextSource. */ public void testThatPlainLookupWorksWithSpring20() { DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); } }
private void verifyBoundCorrectData() { DirContextOperations result = ldapTemplate.lookupContext(DN_STRING); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person4"); }
private void performTestAndShutdownContext(ClassPathXmlApplicationContext ctx, LdapTemplate tested) { try { DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); } finally { ctx.close(); } } }
@Override protected User doMapFromContext(DirContextOperations ctx) { LdapUser user = new LdapUser(ctx.getDn().toString()); user.setFirstname(ctx.getStringAttribute(LDAP_ATTRIBUTE_GIVENNAME)); user.setLastname(ctx.getStringAttribute(LDAP_ATTRIBUTE_SURNAME)); user.setEmail(ctx.getStringAttribute(LDAP_ATTRIBUTE_MAIL)); user.setDisplayName(ctx.getStringAttribute(LDAP_ATTRIBUTE_DISPLAYNAME)); //user.setUsername(ctx.getStringAttribute(LdapIdentityLookup.this.identifierAttribute)); if (user.getDisplayName() == null) { user.setDisplayName(user.getFirstname() + ' ' + user.getLastname()); } return user; } };
/** * This method depends on a DirObjectFactory ( * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) * being set in the ContextSource. */ @Test public void testThatPlainLookupWorksWithSpring30() { DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); } }
/** * This method depends on a DirObjectFactory ( * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) * being set in the ContextSource. */ @Test public void testThatPlainLookupWorksWithSpring30() { DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); } }
private void createRaveUserFromLdapInfo(DirContextOperations ctx, String username) { User newUser = new UserImpl(); newUser.setUsername(username); if (!ctx.attributeExists(mailAttributeName) || StringUtils.isBlank(ctx.getStringAttribute(mailAttributeName))) { throw new RuntimeException("Missing LDAP attribute for email for user " + username); } newUser.setEmail(ctx.getStringAttribute(mailAttributeName)); if (ctx.attributeExists(displayNameAttributeName)) { newUser.setDisplayName(ctx.getStringAttribute(displayNameAttributeName)); } newUser.setPassword(RandomStringUtils.random(16)); newUser.setDefaultPageLayoutCode(pageLayoutCode); try { newAccountService.createNewAccount(newUser); } catch (Exception e) { throw new RuntimeException("Could not bind LDAP username '{" + username + "}' to a user", e); } }
@Override public UserDetails mapUserFromContext( DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities ) { String usernameAttributeValue = ctx.getStringAttribute( getLdapUsernameAttribute() ); if ( usernameAttributeValue == null ) { throw new IllegalStateException( Messages.getInstance().getErrorString( "UseridAttributeLdapContextMapper.ERROR_0001_ATTRIBUTE_NOT_FOUND", getLdapUsernameAttribute() ) ); } // Pass along the attribute value, not the typed in value UserDetails rtn = super.mapUserFromContext( ctx, usernameAttributeValue, authorities ); return rtn; }
@Test public void testSearchForContext_LdapQuery() { DirContextOperations result = tested.searchForContext(query() .where("objectclass").is("person").and("sn").is("Person2")); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); }
@Test public void testSearchForContext_LdapQuery() { DirContextOperations result = tested.searchForContext(query() .where("objectclass").is("person").and("sn").is("Person2")); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); }
@Test public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() { DirContextOperations result = tested.searchForContext(query() .searchScope(SearchScope.ONELEVEL) .base("ou=company1,ou=Sweden") .where("objectclass").is("person").and("sn").is("Person2")); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); }
@Test @Category(NoAdTest.class) public void testAuthenticateWithLdapQueryAndMapper() { DirContextOperations ctx = tested.authenticate(query() .where("objectclass").is("person") .and("uid").is("some.person3"), "password", new LookupAttemptingCallback()); assertThat(ctx).isNotNull(); assertThat(ctx.getStringAttribute("uid")).isEqualTo("some.person3"); }
@Test public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() { DirContextOperations result = tested.searchForContext(query() .searchScope(SearchScope.ONELEVEL) .base("ou=company1,ou=Sweden") .where("objectclass").is("person").and("sn").is("Person2")); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); }