本文整理汇总了Java中org.springframework.security.ldap.userdetails.LdapUserDetails类的典型用法代码示例。如果您正苦于以下问题:Java LdapUserDetails类的具体用法?Java LdapUserDetails怎么用?Java LdapUserDetails使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LdapUserDetails类属于org.springframework.security.ldap.userdetails包,在下文中一共展示了LdapUserDetails类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
LdapUserDetails userDetails = (LdapUserDetails) event.getAuthentication().getPrincipal();
log.info("Login Successful: {}", userDetails.getUsername());
Proprietario proprietario = proprietarioRepository.findByUsuarioIgnoreCase(userDetails.getUsername());
if (proprietario == null) {
log.debug("Primeiro acesso de {}", userDetails.getUsername());
proprietario = new Proprietario();
proprietario.setUsuario(userDetails.getUsername());
completarComNome(proprietario, userDetails);
}
proprietario.setDataLogin(new Date());
proprietarioRepository.save(proprietario);
}
示例2: getPassword
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
/**
* Get the current user password. Note to work the authentication manager
* has to set property erase-credentials="false" in spring application context xml file
*
* @return the current user's password or empty string
*/
public static String getPassword() {
String result = "";
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
Object principal = auth.getPrincipal();
if (principal instanceof LdapUserDetails) {
result = DigestUtils.shaHex(auth.getCredentials().toString());
}
else if (principal instanceof UserDetails) {
result = ((UserDetails) principal).getPassword();
}
}
return result;
}
示例3: getClearPassword
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
/**
* Get the current user clear password. Note to work the authentication manager
* has to set property erase-credentials="false" in spring application context xml file
*
* @return the current user's clear password or empty string
*/
public static String getClearPassword() {
String result = "";
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
Object principal = auth.getPrincipal();
if (principal instanceof LdapUserDetails) {
result = auth.getCredentials().toString();
}
else if (principal instanceof UserDetails) {
result = ((UserWithId) principal).getClearPassword();
}
}
return result;
}
示例4: view
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
@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";
}
示例5: view
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
@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";
}
示例6: mapUserFromContext
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
@Override
public UserDetails mapUserFromContext( DirContextOperations ctx, String username,
Collection<? extends GrantedAuthority> authorities ) {
LdapUserDetails ldap
= LdapUserDetails.class.cast( super.mapUserFromContext( ctx, username,
authorities ) );
SemossEssence essence = new SemossUser.SemossEssence( ldap );
SemossUser user = essence.createUserDetails();
user.setProperty( UserProperty.USER_EMAIL, ctx.getStringAttribute( "mail" ) );
user.setProperty( UserProperty.USER_FULLNAME, ctx.getStringAttribute( "cn" ) );
return user;
}
示例7: LdapUser
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
public LdapUser(LdapUserDetails details, String name, String email) {
this.details = details;
this.name = name;
this.email = email;
this.userName = details.getUsername();
AllocatorEntityService allocatorService = new AllocatorEntityService();
if(allocatorService.searchAllocator(this.userName)!=null){
this.setAllocator(true);
}else{
this.setAllocator(false);
}
}
示例8: mapUserFromContext
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
Collection<? extends GrantedAuthority> authorities) {
UserDetails userDetails= super.mapUserFromContext(ctx,username,authorities);
String fullName = ctx.getStringAttribute("givenName");
String email = ctx.getStringAttribute("mail");
return new LdapUser((LdapUserDetails)userDetails,fullName,email);
}
示例9: getCurrentUser
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
private User getCurrentUser(Authentication auth, UserManager userManager) {
User currentUser;
if (auth.getPrincipal() instanceof LdapUserDetails) {
LdapUserDetails ldapDetails = (LdapUserDetails) auth.getPrincipal();
String username = ldapDetails.getUsername();
currentUser = userManager.getUserByUsername(username);
} else if (auth.getPrincipal() instanceof UserDetails) {
currentUser = (User) auth.getPrincipal();
} else if (auth.getDetails() instanceof UserDetails) {
currentUser = (User) auth.getDetails();
} else {
throw new AccessDeniedException("User not properly authenticated.");
}
return currentUser;
}
示例10: LdapUser
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
public LdapUser(LdapUserDetails details, String name, String email) {
this.details = details;
this.name = name;
this.email = email;
this.userName = details.getUsername();
}
示例11: mapUserFromContext
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
// Default details
LdapUserDetails userDetails = (LdapUserDetails) super.mapUserFromContext(ctx, username, authorities);
return extendUserDetails(ctx, userDetails);
}
示例12: SemossEssence
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
public SemossEssence( LdapUserDetails copyMe ) {
super( copyMe );
}
示例13: extendUserDetails
import org.springframework.security.ldap.userdetails.LdapUserDetails; //导入依赖的package包/类
protected UserDetails extendUserDetails(DirContextOperations ctx, LdapUserDetails userDetails) {
// Full name
String fullNameAttribute = settings.getFullNameAttribute();
if (StringUtils.isBlank(fullNameAttribute)) {
fullNameAttribute = "cn";
}
String fullName = ctx.getStringAttribute(fullNameAttribute);
// Email
String emailAttribute = settings.getEmailAttribute();
if (StringUtils.isBlank(emailAttribute)) {
emailAttribute = "email";
}
String email = ctx.getStringAttribute(emailAttribute);
// Groups
String groupAttribute = settings.getGroupAttribute();
if (StringUtils.isBlank(groupAttribute)) {
groupAttribute = "memberOf";
}
String groupFilter = settings.getGroupFilter();
String[] groups = ctx.getStringAttributes(groupAttribute);
Set<String> parsedGroups;
if (groups != null && groups.length > 0) {
parsedGroups = Arrays.asList(groups).stream()
// Parsing of the group
.map(DistinguishedName::new)
// Filter on OU
.filter(dn -> {
String ou = getValue(dn, "OU");
return StringUtils.isBlank(groupFilter) || StringUtils.equalsIgnoreCase(ou, groupFilter);
})
// Getting the common name
.map(dn -> getValue(dn, "CN"))
// Keeps only the groups being filled in
.filter(StringUtils::isNotBlank)
// As a set
.collect(Collectors.toSet());
} else {
parsedGroups = Collections.emptySet();
}
// OK
return new ExtendedLDAPUserDetails(userDetails, fullName, email, parsedGroups);
}