use of net.sf.acegisecurity.UserDetails in project alfresco-repository by Alfresco.
the class AuthenticationTest method assertCreateHashed.
private void assertCreateHashed(String rawString, String hash, char[] rawPassword, String user) {
dao.createUser(user, hash, rawPassword);
UserDetails userDetails = (UserDetails) dao.loadUserByUsername(user);
assertNotNull(userDetails);
assertNotNull(userDetails.getPassword());
assertTrue(compositePasswordEncoder.matches(compositePasswordEncoder.getPreferredEncoding(), rawString, userDetails.getPassword(), null));
dao.deleteUser(user);
}
use of net.sf.acegisecurity.UserDetails in project alfresco-repository by Alfresco.
the class TestAuthenticationServiceImpl method getUserDetails.
/**
* Default implementation that makes an ACEGI object on the fly
*
* @param userName
* @return
*/
protected UserDetails getUserDetails(String userName) {
GrantedAuthority[] gas = new GrantedAuthority[1];
gas[0] = new GrantedAuthorityImpl("ROLE_AUTHENTICATED");
UserDetails ud = new User(userName, "", true, true, true, true, gas);
return ud;
}
use of net.sf.acegisecurity.UserDetails in project alfresco-repository by Alfresco.
the class RepositoryAuthenticationDao method getUserEntryOrNullImpl.
private CacheEntry getUserEntryOrNullImpl(final String caseSensitiveSearchUserName) {
if (caseSensitiveSearchUserName == null || caseSensitiveSearchUserName.length() == 0) {
return null;
}
class SearchUserNameCallback implements RetryingTransactionCallback<CacheEntry> {
@Override
public CacheEntry execute() throws Throwable {
CacheEntry cacheEntry = authenticationCache.get(caseSensitiveSearchUserName);
// Check the cache entry if it exists
if (cacheEntry != null && !nodeService.exists(cacheEntry.nodeRef)) {
logger.warn("Detected state cache entry for '" + caseSensitiveSearchUserName + "'. Node does not exist: " + cacheEntry);
// We were about to give out a stale node. Something went wrong with the cache.
// The removal is guaranteed whether we commit or rollback.
removeAuthenticationFromCache(caseSensitiveSearchUserName);
cacheEntry = null;
}
// Check again
if (cacheEntry != null) {
// We found what we wanted
return cacheEntry;
}
// Not found, so query
List<ChildAssociationRef> results = nodeService.getChildAssocs(getUserFolderLocation(caseSensitiveSearchUserName), ContentModel.ASSOC_CHILDREN, QName.createQName(ContentModel.USER_MODEL_URI, caseSensitiveSearchUserName));
if (!results.isEmpty()) {
// Extract values from the query results
NodeRef userRef = tenantService.getName(results.get(0).getChildRef());
Map<QName, Serializable> properties = nodeService.getProperties(userRef);
Pair<List<String>, String> hashPassword = determinePasswordHash(properties);
// Report back the user name as stored on the user
String userName = DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_USER_USERNAME));
Serializable salt = properties.get(ContentModel.PROP_SALT);
GrantedAuthority[] gas = new GrantedAuthority[1];
gas[0] = new GrantedAuthorityImpl("ROLE_AUTHENTICATED");
boolean isAdminAuthority = authorityService.isAdminAuthority(userName);
Date credentialsExpiryDate = getCredentialsExpiryDate(userName, properties, isAdminAuthority);
boolean credentialsHaveNotExpired = (credentialsExpiryDate == null || credentialsExpiryDate.getTime() >= System.currentTimeMillis());
UserDetails ud = new RepositoryAuthenticatedUser(userName, hashPassword.getSecond(), getEnabled(userName, properties, isAdminAuthority), !getHasExpired(userName, properties, isAdminAuthority), credentialsHaveNotExpired, !getLocked(userName, properties, isAdminAuthority), gas, hashPassword.getFirst(), salt);
cacheEntry = new CacheEntry(userRef, ud, credentialsExpiryDate);
// Only cache positive results
authenticationCache.put(caseSensitiveSearchUserName, cacheEntry);
}
return cacheEntry;
}
}
// Always use a transaction
return transactionService.getRetryingTransactionHelper().doInTransaction(new SearchUserNameCallback(), true);
}
use of net.sf.acegisecurity.UserDetails in project alfresco-repository by Alfresco.
the class TestAuthenticationServiceImpl method setCurrentUser.
/**
* Explicitly set the current user to be authenticated.
*
* @param userName
* String
* @return Authentication
*/
public Authentication setCurrentUser(String userName) throws AuthenticationException {
if (userName == null) {
throw new AuthenticationException("Null user name");
}
try {
UserDetails ud = null;
if (userName.equals(SYSTEM_USER_NAME)) {
GrantedAuthority[] gas = new GrantedAuthority[1];
gas[0] = new GrantedAuthorityImpl("ROLE_SYSTEM");
ud = new User(SYSTEM_USER_NAME, "", true, true, true, true, gas);
} else if (userName.equalsIgnoreCase(AuthenticationUtil.getGuestUserName())) {
GrantedAuthority[] gas = new GrantedAuthority[0];
ud = new User(AuthenticationUtil.getGuestUserName().toLowerCase(), "", true, true, true, true, gas);
} else {
ud = getUserDetails(userName);
}
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud.getAuthorities());
auth.setDetails(ud);
auth.setAuthenticated(true);
return setCurrentAuthentication(auth);
} catch (net.sf.acegisecurity.AuthenticationException ae) {
throw new AuthenticationException(ae.getMessage(), ae);
}
}
Aggregations