05-29-2008 11:04 AM
05-29-2008 12:45 PM
05-30-2008 07:23 AM
06-04-2008 09:45 AM
authenticationDao.updateUser(userIdentifier, password);
This writes the hashed password into the users' property.06-05-2008 02:30 AM
06-05-2008 11:30 AM
package com.XXX.repo.security.authentication;
import java.io.Serializable;
import java.util.Map;
import net.sf.acegisecurity.GrantedAuthority;
import net.sf.acegisecurity.GrantedAuthorityImpl;
import net.sf.acegisecurity.UserDetails;
import net.sf.acegisecurity.providers.dao.User;
import net.sf.acegisecurity.providers.dao.UsernameNotFoundException;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.QName;
import org.springframework.dao.DataAccessException;
/**
* This RepositoryAuthenticationDao servers for CIFS authentication. Based on alfresco's RepositoryAuthenticationDao
* with some modification/fixes.
*
*
*
* @author RVycital
*/
public class RepositoryAuthenticationDao extends org.alfresco.repo.security.authentication.RepositoryAuthenticationDao{
//private static final StoreRef STOREREF_USERS = new StoreRef("user", "alfrescoUserStore");
private StoreRef userStoreRef;
private NodeService nodeService;
private TenantService tenantService;
private SearchService searchService;
private boolean userNamesAreCaseSensitive;
/**
* People are stored like type PERSON in our cases (not a USR).
* Perhaps an alfresco bug. Also corrects the PROP_USER_USERNAME to PROP_USERNAME for this case.
*/
@Override
public NodeRef getUserOrNull(String searchUserName)
{
if(searchUserName == null)
{
return null;
}
if(searchUserName.length() == 0)
{
return null;
}
SearchParameters sp = new SearchParameters();
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND "
+ " (@\\{http\\://www.alfresco.org/model/content/1.0\\}userName:\''+searchUserName+'\")");
//old impl
//sp.setQuery("@usr\\:username:\"" + searchUserName + "\"");
try
{
sp.addStore(tenantService.getName(searchUserName, userStoreRef));
}
catch (AlfrescoRuntimeException e)
{
return null; // no such tenant or tenant not enabled
}
sp.excludeDataInTheCurrentTransaction(false);
ResultSet rs = null;
try
{
rs = searchService.query(sp);
NodeRef returnRef = null;
for (ResultSetRow row : rs)
{
NodeRef nodeRef = row.getNodeRef();
if (nodeService.exists(nodeRef))
{
String realUserName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(
nodeRef, ContentModel.PROP_USERNAME)); //used to be PROP_USER_USERNAME
if (userNamesAreCaseSensitive)
{
if (realUserName.equals(searchUserName))
{
if(returnRef == null)
{
returnRef = nodeRef;
}
else
{
throw new AlfrescoRuntimeException("Found more than one user for "+searchUserName+ " (case sensitive)");
}
}
}
else
{
if (realUserName.equalsIgnoreCase(searchUserName))
{
if(returnRef == null)
{
returnRef = nodeRef;
}
else
{
throw new AlfrescoRuntimeException("Found more than one user for "+searchUserName+ " (case insensitive)");
}
}
}
}
}
return returnRef;
}
finally
{
if (rs != null)
{
rs.close();
}
}
}
@Override
public UserDetails loadUserByUsername(String incomingUserName) throws UsernameNotFoundException, DataAccessException {
NodeRef userRef = getUserOrNull(incomingUserName);
if (userRef == null) {
throw new UsernameNotFoundException("Could not find user by userName: " + incomingUserName);
}
Map<QName, Serializable> properties = nodeService.getProperties(userRef);
String password = DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_PASSWORD));
// Report back the user name as stored on the user
String userName = DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_USERNAME));
GrantedAuthority[] gas = new GrantedAuthority[1];
gas[0] = new GrantedAuthorityImpl("ROLE_AUTHENTICATED");
UserDetails ud = new User(userName, password, getEnabled(userRef), !getAccountHasExpired(incomingUserName), !getCredentialsHaveExpired(incomingUserName), !getAccountlocked(incomingUserName), gas);
return ud;
}
@Override
public boolean getEnabled(String userName)
{
return getEnabled(getUserOrNull(userName));
}
private boolean getEnabled(NodeRef userNode)
{
if (userNode == null)
{
return false;
}
Serializable ser = nodeService.getProperty(userNode, ContentModel.PROP_ENABLED);
if (ser == null)
{
return true;
}
else
{
return DefaultTypeConverter.INSTANCE.booleanValue(ser);
}
}
/**
* Always return false.
*/
@Override
public boolean getAccountHasExpired(String userName)
{
return false;
}
@Override
public boolean getAccountlocked(String userName)
{
return false;
}
@Override
public boolean getCredentialsExpire(String userName)
{
return false;
}
@Override
public boolean getCredentialsHaveExpired(String userName)
{
return false;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
super.setNodeService(nodeService);
}
public void setTenantService(TenantService tenantService) {
this.tenantService = tenantService;
super.setTenantService(tenantService);
}
public void setSearchService(SearchService searchService) {
this.searchService = searchService;
super.setSearchService(searchService);
}
public void setUserNamesAreCaseSensitive(boolean userNamesAreCaseSensitive) {
this.userNamesAreCaseSensitive = userNamesAreCaseSensitive;
super.setUserNamesAreCaseSensitive(userNamesAreCaseSensitive);
}
public void setUserStoreRef(String userStoreRef) {
this.userStoreRef = new StoreRef(userStoreRef);
}
}
06-19-2008 12:45 PM
<alias name="authenticationDao" alias="alfDaoImpl"/> <!– TODO: Remove –>
<bean id="authenticationDao" class="org.alfresco.repo.security.authentication.RepositoryAuthenticati$
<property name="nodeService">
<ref bean="nodeService" />
</property>
<property name="dictionaryService">
<ref bean="dictionaryService" />
</property>
<property name="namespaceService">
<ref bean="namespaceService" />
</property>
<property name="searchService">
<ref bean="admSearchService" />
</property>
<property name="userNamesAreCaseSensitive">
<value>${user.name.caseSensitive}</value>
</property>
<property name="passwordEncoder">
<ref bean="passwordEncoder" />
</property>
</bean>
<!– The DAO also acts as a salt provider. –>
<alias alias="saltSource" name="authenticationDao"/>
<!– Passwords are encoded using MD4 –>
<!– This is not ideal and only done to be compatible with NTLM –>
<!– authentication against the default authentication mechanism. –>
So if I understand, I need to copy/paste with a different name eg.:authenticationDaoFull and on the same file write authenticationDao.updateUser(userIdentifier, password);
authenticationDao.updateUser(userIdentifier, password);
authenticationDaofull.updateUser(userIdentifier, password);
??? 04-20-2009 08:30 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.