@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()).append(": "); sb.append("Dn: ").append(dn).append("; "); sb.append("Username: ").append(this.username).append("; "); sb.append("Password: [PROTECTED]; "); sb.append("Enabled: ").append(this.enabled).append("; "); sb.append("AccountNonExpired: ").append(this.accountNonExpired).append("; "); sb.append("CredentialsNonExpired: ").append(this.credentialsNonExpired) .append("; "); sb.append("AccountNonLocked: ").append(this.accountNonLocked).append("; "); if (this.getAuthorities() != null && !this.getAuthorities().isEmpty()) { sb.append("Granted Authorities: "); boolean first = true; for (Object authority : this.getAuthorities()) { if (first) { first = false; } else { sb.append(", "); } sb.append(authority.toString()); } } else { sb.append("Not granted any authorities"); } return sb.toString(); }
public void setUid(String uid) { ((InetOrgPerson) instance).uid = uid; if (instance.getUsername() == null) { setUsername(uid); } }
protected LdapUserDetailsImpl createTarget() { return new LdapUserDetailsImpl(); }
public LdapUserDetails createUserDetails() { Assert.notNull(instance, "Essence can only be used to create a single instance"); Assert.notNull(instance.username, "username must not be null"); Assert.notNull(instance.getDn(), "Distinguished name must not be null"); instance.authorities = Collections.unmodifiableList(mutableAuthorities); LdapUserDetails newInstance = instance; instance = null; return newInstance; }
public LdapUserDetails createUserDetails() { Assert.notNull(instance, "Essence can only be used to create a single instance"); Assert.notNull(instance.username, "username must not be null"); Assert.notNull(instance.getDn(), "Distinguished name must not be null"); instance.authorities = Collections.unmodifiableList(mutableAuthorities); LdapUserDetails newInstance = instance; instance = null; return newInstance; }
/** * SEC-303. Non-retrieved role attribute causes NullPointerException */ @Test public void testNonRetrievedRoleAttributeIsIgnored() throws Exception { LdapUserDetailsMapper mapper = new LdapUserDetailsMapper(); mapper.setRoleAttributes(new String[] { "userRole", "nonRetrievedAttribute" }); BasicAttributes attrs = new BasicAttributes(); attrs.put(new BasicAttribute("userRole", "x")); DirContextAdapter ctx = new DirContextAdapter(attrs, new DistinguishedName("cn=someName")); ctx.setAttributeValue("uid", "ani"); LdapUserDetailsImpl user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES); assertThat(user.getAuthorities()).hasSize(1); assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities())).contains("ROLE_X"); }
public void setUid(String uid) { ((InetOrgPerson) instance).uid = uid; if(instance.getUsername() == null) { setUsername(uid); } }
public LdapUserDetails createUserDetails() { Assert.notNull(instance, "Essence can only be used to create a single instance"); Assert.notNull(instance.username, "username must not be null"); Assert.notNull(instance.getDn(), "Distinguished name must not be null"); instance.authorities = Collections.unmodifiableList(mutableAuthorities); LdapUserDetails newInstance = instance; instance = null; return newInstance; }
protected LdapUserDetailsImpl createTarget() { return new LdapUserDetailsImpl(); }
@Test public void testMultipleRoleAttributeValuesAreMappedToAuthorities() throws Exception { LdapUserDetailsMapper mapper = new LdapUserDetailsMapper(); mapper.setConvertToUpperCase(false); mapper.setRolePrefix(""); mapper.setRoleAttributes(new String[] { "userRole" }); DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("userRole", new String[] { "X", "Y", "Z" }); ctx.setAttributeValue("uid", "ani"); LdapUserDetailsImpl user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES); assertThat(user.getAuthorities()).hasSize(3); }
public void setUid(String uid) { ((InetOrgPerson) instance).uid = uid; if (instance.getUsername() == null) { setUsername(uid); } }
protected LdapUserDetailsImpl createTarget() { return new LdapUserDetailsImpl(); }
public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()).append(": "); sb.append("Dn: ").append(dn).append("; "); sb.append("Username: ").append(this.username).append("; "); sb.append("Password: [PROTECTED]; "); sb.append("Enabled: ").append(this.enabled).append("; "); sb.append("AccountNonExpired: ").append(this.accountNonExpired).append("; "); sb.append("CredentialsNonExpired: ").append(this.credentialsNonExpired).append("; "); sb.append("AccountNonLocked: ").append(this.accountNonLocked).append("; "); if (this.getAuthorities() != null) { sb.append("Granted Authorities: "); boolean first = true; for (Object authority : this.getAuthorities()) { if (first) { first = false; } else { sb.append(", "); } sb.append(authority.toString()); } } else { sb.append("Not granted any authorities"); } return sb.toString(); }
private boolean holdBrowserTerminalUser(HttpServletRequest request) throws ShepherException { String userName = null; if (ShepherConstants.LOGIN_TYPE_LDAP.equals(loginType.toUpperCase())) { SecurityContextImpl context = (SecurityContextImpl) request.getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); if (context != null) { userName = ((LdapUserDetailsImpl) context.getAuthentication().getPrincipal()).getUsername(); } } else if (ShepherConstants.LOGIN_TYPE_CAS.equals(loginType.toUpperCase())) { Assertion assertion = (Assertion) request.getSession().getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION); userName = assertion.getPrincipal().getName(); } else if (ShepherConstants.LOGIN_TYPE_DEMO.equals(loginType.toUpperCase())) { SecurityContextImpl context = (SecurityContextImpl) request.getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); if (context != null) { userName = ((UserDetails) context.getAuthentication().getPrincipal()).getUsername(); } } else { throw ShepherException.createIllegalLoginTypeException(); } if (userName != null) { User user = userService.createIfNotExist(userName); userHolder.setUser(user); String requestURI = request.getRequestURI(); String httpMethod = request.getMethod(); logger.info("userId:{}, userName:{}, {}:{}", user.getId(), user.getName(), httpMethod, requestURI); } return true; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()).append(": "); sb.append("Dn: ").append(dn).append("; "); sb.append("Username: ").append(this.username).append("; "); sb.append("Password: [PROTECTED]; "); sb.append("Enabled: ").append(this.enabled).append("; "); sb.append("AccountNonExpired: ").append(this.accountNonExpired).append("; "); sb.append("CredentialsNonExpired: ").append(this.credentialsNonExpired) .append("; "); sb.append("AccountNonLocked: ").append(this.accountNonLocked).append("; "); if (this.getAuthorities() != null && !this.getAuthorities().isEmpty()) { sb.append("Granted Authorities: "); boolean first = true; for (Object authority : this.getAuthorities()) { if (first) { first = false; } else { sb.append(", "); } sb.append(authority.toString()); } } else { sb.append("Not granted any authorities"); } return sb.toString(); }