创建新用户时自动使用用户名和随机密码生成电子邮件

创建新用户时自动使用用户名和随机密码生成电子邮件,第1张

创建新用户时自动使用用户名和随机密码生成电子邮件

以下是一个可行的解决方案。

资源/alfresco/extension/new-user-email-context.xml:

<?xml version='1.0' encoding='UTF-8'?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="http://www.springframework.org/schema/beans          http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">        <bean id="newUserEmail" >        <property name="policyComponent" ref="policyComponent"/>        <property name="nodeService" ref="nodeService"/>        <property name="personService" ref="personService"/>        <property name="passwordGenerator" ref="passwordGenerator"/>        <property name="authenticationService" ref="authenticationService"/>    </bean></beans>

demo.NewUserEmail.java:

package demo;import org.alfresco.model.ContentModel;import org.alfresco.repo.node.NodeServicePolicies;import org.alfresco.repo.policy.*;import org.alfresco.repo.security.authentication.PasswordGenerator;import org.alfresco.service.cmr.repository.*;import org.alfresco.service.cmr.security.*;import org.alfresco.util.PropertyCheck;import org.springframework.beans.factory.InitializingBean;public class NewUserEmail implements     NodeServicePolicies.OnCreateNodePolicy, InitializingBean {    @Override    public void onCreateNode(ChildAssociationRef childAssocRef) {        notifyUser(childAssocRef);    }    private void notifyUser(ChildAssociationRef childAssocRef) {        NodeRef personRef = childAssocRef.getChildRef();        // get the user name        String username = (String) this.nodeService.getProperty( personRef, ContentModel.PROP_USERNAME);        // generate the new password (Alfresco's rules)        String newPassword = passwordGenerator.generatePassword();        // set the new password        authenticationService.setAuthentication(username, newPassword.toCharArray());        // send default notification to the user        personService.notifyPerson(username, newPassword);    }    private PolicyComponent policyComponent;    private NodeService nodeService;    private PersonService personService;    private PasswordGenerator passwordGenerator;    private MutableAuthenticationService authenticationService;    public void setPolicyComponent(PolicyComponent policyComponent) {        this.policyComponent = policyComponent;    }    public void setNodeService(NodeService nodeService) {        this.nodeService = nodeService;    }    public void setPersonService(PersonService personService) {        this.personService = personService;    }    public void setPasswordGenerator(PasswordGenerator passwordGenerator) {        this.passwordGenerator = passwordGenerator;    }    public void setAuthenticationService(AuthenticationService authenticationService) {        if (authenticationService instanceof MutableAuthenticationService) { this.authenticationService = (MutableAuthenticationService) authenticationService;        }    }    @Override    public void afterPropertiesSet() throws Exception {        PropertyCheck.mandatory(this, "policyComponent", policyComponent);        PropertyCheck.mandatory(this, "nodeService", nodeService);        PropertyCheck.mandatory(this, "passwordGenerator", passwordGenerator);        PropertyCheck.mandatory(this, "authenticationService", authenticationService);        PropertyCheck.mandatory(this, "personService", personService);        this.policyComponent.bindClassBehaviour(     NodeServicePolicies.OnCreateNodePolicy.QNAME,     ContentModel.TYPE_PERSON,     new JavaBehaviour(this,  NodeServicePolicies.OnCreateNodePolicy.QNAME.getLocalName(),  Behaviour.NotificationFrequency.TRANSACTION_COMMIT     )        );    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5478664.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存