org.springframework.security.ldap.userdetails.InetOrgPerson Java Examples
The following examples show how to use
org.springframework.security.ldap.userdetails.InetOrgPerson.
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: AuthService.java From egeria with Apache License 2.0 | 5 votes |
default TokenUser getTokenUser(Authentication authentication) { TokenUser tokenUser; Object principal = authentication.getPrincipal(); if (principal instanceof TokenUser) { tokenUser = (TokenUser) principal; } else { tokenUser = new TokenUser((InetOrgPerson) principal); } return tokenUser; }
Example #2
Source File: TokenUser.java From egeria with Apache License 2.0 | 5 votes |
public TokenUser(InetOrgPerson inetOrgPerson) { super(inetOrgPerson.getUsername(), "" , inetOrgPerson.getAuthorities()); this.user = new User(); this.user.setUsername(inetOrgPerson.getUsername()); this.user.setRoles(inetOrgPerson.getAuthorities().stream().map((e -> e.getAuthority())).collect(Collectors.toList())); this.user.setName(inetOrgPerson.getSn()); }
Example #3
Source File: AccountController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = userDetailsService.loadUserByUsername(authentication.getName()); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #4
Source File: AccountController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = authentication.getPrincipal(); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #5
Source File: AccountController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = userDetailsService.loadUserByUsername(authentication.getName()); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #6
Source File: AccountController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = userDetailsService.loadUserByUsername(authentication.getName()); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #7
Source File: AccountController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = authentication.getPrincipal(); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #8
Source File: AccountController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = userDetailsService.loadUserByUsername(authentication.getName()); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #9
Source File: AccountController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = authentication.getPrincipal(); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #10
Source File: AccountController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = authentication.getPrincipal(); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #11
Source File: AccountController.java From maven-framework-project with MIT License | 5 votes |
@RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) { throw new IllegalStateException("authentication cannot be null. Make sure you are logged in."); } Object principal = authentication.getPrincipal(); model.addAttribute("user", principal); model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails); model.addAttribute("isLdapPerson", principal instanceof Person); model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson); return "accounts/show"; }
Example #12
Source File: LdapAuthFilter.java From para with Apache License 2.0 | 4 votes |
private UserAuthentication getOrCreateUser(App app, Authentication ldapAuth) { LOG.debug("LDAP response: {}", ldapAuth); if (ldapAuth == null) { return null; } UserAuthentication userAuth = null; User user = new User(); InetOrgPerson profile = (InetOrgPerson) ldapAuth.getPrincipal(); if (profile != null && profile.isEnabled() && profile.isAccountNonLocked() && profile.isAccountNonExpired()) { String ldapAccountId = profile.getUsername(); String email = profile.getMail(); String name = StringUtils.join(profile.getCn(), ", "); String adDomain = (String) app.getSetting("security.ldap.active_directory_domain"); String groups = getGroupsFromDN(profile.getDn(), app); if (StringUtils.isBlank(email)) { if (Utils.isValidEmail(ldapAccountId)) { email = ldapAccountId; } else if (!StringUtils.isBlank(adDomain)) { LOG.warn("The AD doesn't have email attribute. Instead, it uses domain name for email address: " + "{}@{}.", ldapAccountId, adDomain); email = ldapAccountId.concat("@").concat(adDomain); } else { LOG.warn("Blank email attribute for LDAP user '{}'.", ldapAccountId); email = ldapAccountId + "@paraio.com"; } } if (Boolean.parseBoolean(app.getSetting("security.ldap.username_as_name") + "")) { name = email.split("@")[0]; } user.setAppid(getAppid(app)); user.setIdentifier(Config.LDAP_PREFIX.concat(ldapAccountId)); user.setEmail(email); user = User.readUserForIdentifier(user); if (user == null) { //user is new user = new User(); user.setActive(true); user.setAppid(getAppid(app)); user.setEmail(email); user.setGroups(groups); user.setName(StringUtils.isBlank(name) ? "No Name" : name); user.setPassword(Utils.generateSecurityToken()); user.setIdentifier(Config.LDAP_PREFIX.concat(ldapAccountId)); String id = user.create(); if (id == null) { throw new AuthenticationServiceException("Authentication failed: cannot create new user."); } } else { if (updateUserInfo(user, email, name, groups)) { user.update(); } } userAuth = new UserAuthentication(new AuthenticatedUserDetails(user)); } else { LOG.error("Failed to create account - is the LDAP user active? principal={}", profile); } return userAuth; }