Friday 22 June 2012

Alfresco reset admin password

One of the problems that people are having is when they forget admin password, and what to do :D.

One of solutions is to create simple servet and execute one http get request, in witch you will reset admin password to "admin", and then change it to something else.


public class ResetAdminPassword extends HttpServlet {

    private static final long serialVersionUID = 589583745167158768L;
    private static final String USERNAME = "admin";
    private static final String PASSWORD = "admin";

    public class TemplateContentWork implements RunAsWork<Object> {

public TemplateContentWork() {

}

@Override
public Object doWork() throws Exception {

   try {
Repository.getServiceRegistry(getServletContext())
.getAuthenticationService()
.createAuthentication(USERNAME, PASSWORD.toCharArray());
   } catch (Exception ex) {
Repository.getServiceRegistry(getServletContext())
.getAuthenticationService()
.setAuthentication(USERNAME, PASSWORD.toCharArray());
   }

   return null;
}

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
TemplateContentWork contentWork = new TemplateContentWork();

AuthenticationUtil.setRunAsUser(USERNAME);
try {
   contentWork.doWork();
} catch (Exception e) {
   e.printStackTrace();
}
    }
}




add code like this into web.xml

 <servlet>
  <servlet-name>resetpassword</servlet-name>
  <servlet-class>...ResetAdminPassword </servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>



 <servlet-mapping>
  <servlet-name> resetpassword </servlet-name>
  <url-pattern>/ resetpassword </url-pattern>
 </servlet-mapping>


This is one of the ways, you can add webscript and create action that will do this...
Hope this helps.


No comments:

Post a Comment