use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class AbstractLdapAuthenticationProvider method authenticate.
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, this.messages.getMessage("LdapAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported"));
final UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication;
String username = userToken.getName();
String password = (String) authentication.getCredentials();
if (this.logger.isDebugEnabled()) {
this.logger.debug("Processing authentication request for user: " + username);
}
if (!StringUtils.hasLength(username)) {
throw new BadCredentialsException(this.messages.getMessage("LdapAuthenticationProvider.emptyUsername", "Empty Username"));
}
if (!StringUtils.hasLength(password)) {
throw new BadCredentialsException(this.messages.getMessage("AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password"));
}
Assert.notNull(password, "Null password was supplied in authentication token");
DirContextOperations userData = doAuthentication(userToken);
UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, authentication.getName(), loadUserAuthorities(userData, authentication.getName(), (String) authentication.getCredentials()));
return createSuccessfulAuthentication(userToken, user);
}
use of org.springframework.security.core.userdetails.UserDetails in project OpenClinica by OpenClinica.
the class UserPermissionInterceptor method handleRequest.
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
UserAccountBean userAccountBean = ((UserAccountBean) userAccountDao.findByUserName(username));
Boolean result = userAccountBean.getRunWebservices();
if (!result) {
SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
response.addClientOrSenderFault("Authorization is required to execute SOAP web services with this account.Please contact your administrator.", Locale.ENGLISH);
return false;
} else {
return result;
}
}
use of org.springframework.security.core.userdetails.UserDetails in project OpenClinica by OpenClinica.
the class StudySubjectEndpoint method getUserAccount.
/**
* Helper Method to get the user account
*
* @return UserAccountBean
*/
private UserAccountBean getUserAccount() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
return (UserAccountBean) userAccountDao.findByUserName(username);
}
use of org.springframework.security.core.userdetails.UserDetails in project OpenClinica by OpenClinica.
the class DataEndpoint method getUserAccount.
/**
* Helper Method to get the user account
*
* @return UserAccountBean
*/
private UserAccountBean getUserAccount() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
return (UserAccountBean) userAccountDao.findByUserName(username);
}
use of org.springframework.security.core.userdetails.UserDetails in project OpenClinica by OpenClinica.
the class EventEndpoint method getUserAccount.
/**
* Helper Method to get the user account
*
* @return UserAccountBean
*/
private UserAccountBean getUserAccount() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
return (UserAccountBean) userAccountDao.findByUserName(username);
}
Aggregations