Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当cq5登录模块创建时,遇到org.apache.jackrabbit.core.security.simple.SimpleLoginModule的问题_Java_Aem_Jackrabbit_Jcr_Sling - Fatal编程技术网

Java 当cq5登录模块创建时,遇到org.apache.jackrabbit.core.security.simple.SimpleLoginModule的问题

Java 当cq5登录模块创建时,遇到org.apache.jackrabbit.core.security.simple.SimpleLoginModule的问题,java,aem,jackrabbit,jcr,sling,Java,Aem,Jackrabbit,Jcr,Sling,我想为我的CQ5应用程序编写登录模块,所以我申请了 我把这个api放到servlet代码中,但它不起作用。有人给我指路吗?以下是我的实现: @SlingServlet(paths = { "/bin/app/signin" }, methods = { "POST" }, metatype = true) public class SigninServlet extends SlingAllMethodsServlet { public static final Logger LOG

我想为我的CQ5应用程序编写登录模块,所以我申请了

我把这个api放到servlet代码中,但它不起作用。有人给我指路吗?以下是我的实现:

@SlingServlet(paths = { "/bin/app/signin" }, methods = { "POST" }, metatype = true)
public class SigninServlet extends SlingAllMethodsServlet {

    public static final Logger LOG = LoggerFactory
            .getLogger(SigninServlet.class);

    private static final long serialVersionUID = 1L;

    @SuppressWarnings("unchecked")
    @Override
    protected void doGet(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws ServletException,
            IOException {

        response.setContentType("text/html; charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        out.println("{message : start}");
        Session session = JcrUtils.getSession(request);
        try {

            UserManager userManager = AccessControlUtil.getUserManager(session);
            //check if contain input username.
            Authorizable authorizable = userManager.getAuthorizable("admin");

                    //create credential from input username and password
            Credentials credential = new SimpleCredentials("admin", "admin".toCharArray());

            Principal principal = authorizable.getPrincipal();

            Map<String, String> sharedState = new HashedMap();

            Map<String, String> options = new HashedMap();
            options.put(LoginModuleConfig.PARAM_ADMIN_ID, "admin");
            options.put(LoginModuleConfig.PARAM_PRINCIPAL_PROVIDER_CLASS, "org.apache.jackrabbit.core.security.principal.DefaultPrincipalProvider");

            SimpleLoginModule sim = new SimpleLoginModule();

            Subject subject = new Subject();
            subject.getPrincipals().add(principal);
            subject.getPublicCredentials().add(credential);

            sim.initialize(subject, null, sharedState, options);
            sim.login();
        } catch (Exception e) {
            out.println("{error message: " + e.getMessage() + "}");
            LOG.warn(e.getMessage());
        }

        out.flush();
    }

}

我不确定您想要实现什么,但这不是登录模块在CQ5中的工作方式。如果您的目标是实现自己的登录机制,那么位于的文档应该会有所帮助。

您是否在error.log中发现任何错误。请将错误粘贴到此处。您是否将其作为独立java代码运行?或者您是从OSGi捆绑包运行它?