As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
import javax.transaction.UserTransaction; import net.sf.acegisecurity.AuthenticationManager; import net.sf.acegisecurity.providers.dao.SaltSource; import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.MD4PasswordEncoder; import org.alfresco.repo.security.authentication.MutableAuthenticationDao; import org.alfresco.repo.security.authentication.TicketComponent; import org.alfresco.repo.security.authentication.InMemoryTicketComponentImpl.Ticket; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.util.ApplicationContextHelper; import org.springframework.context.ApplicationContext; public class AuthCheck { private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); private NodeService nodeService; private SearchService searchService; private NodeRef rootNodeRef; private NodeRef systemNodeRef; private NodeRef typesNodeRef; private NodeRef personAndyNodeRef; private DictionaryService dictionaryService; private MD4PasswordEncoder passwordEncoder; private MutableAuthenticationDao dao; private AuthenticationManager authenticationManager; private SaltSource saltSource; private TicketComponent ticketComponent; private SimpleCache<String, Ticket> ticketsCache; private AuthenticationService authenticationService; private AuthenticationService pubAuthenticationService; private AuthenticationComponent authenticationComponent; private UserTransaction userTransaction; private AuthenticationComponent authenticationComponentImpl; /** * This class checks the filled in user info. * The idea is to use the LDAP. Otherwise anyone can access anyones info and modify it. */ public AuthCheck() { setUp(); } public void setUp(){ // authenticationService = (AuthenticationService)ctx.getBean("authenticationService"); // pubAuthenticationService = (AuthenticationService)ctx.getBean("AuthenticationService"); // authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent"); authenticationComponentImpl = (AuthenticationComponent)ctx.getBean("authenticationComponentImpl"); System.out.println(authenticationComponentImpl.getCurrentUserName()+ " From AuthCheck!!!!!"); }
public void setUp(){ FacesContext context = FacesContext.getCurrentInstance(); ServiceRegistry serviceRegistry = Repository.getServiceRegistry(context); AuthenticationService authenticationService = serviceRegistry.getAuthenticationService(); String username=authenticationService.getCurrentUserName(); this.username=username; System.out.println(username+" \t—> from AuthCheck!!!!!!!!!"); UserTransaction tx = null; try { //Start the transaction. Why this is required for such a simple operation is beyond me. TransactionService txs = (TransactionService) FacesContextUtils.getRequiredWebApplicationContext(context).getBean("transactionComponent"); tx = txs.getUserTransaction(); tx.begin(); PersonService personService = (PersonService)FacesContextUtils.getRequiredWebApplicationContext(context).getBean("personService"); NodeService nodeService = (NodeService)FacesContextUtils.getRequiredWebApplicationContext(context).getBean("nodeService"); PersonService ps = serviceRegistry.getPersonService(); System.out.println("\t"+ ps.getUserIdentifier(username)); NodeRef nr = personService.getPerson(username); String firstName = (String)nodeService.getProperty(nr, ContentModel.PROP_FIRSTNAME); String lastName = (String)nodeService.getProperty(nr, ContentModel.PROP_LASTNAME); System.out.println(firstName +" " +lastName+ " From the Repo!!!!!!!!!!!"); tx.commit(); }catch (Exception err) { try { if (tx != null) {tx.rollback();} } catch (Exception tex) {tex.printStackTrace();} err.printStackTrace(); } finally { //Normally I'd end the transaction, but it doesn't seem to feature such a method. } }