<%@ page import="org.apache.axis2.context.ConfigurationContextFactory" %>
<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
<%@ page import="org.wso2.carbon.authenticator.proxy.AuthenticationAdminClient" %>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    ConfigurationContext configCtx = ConfigurationContextFactory.createDefaultConfigurationContext();
    String serverURL = this.getServletConfig().getServletContext().getInitParameter("webServiceServerURL");
    boolean status = new AuthenticationAdminClient(configCtx, serverURL, null, session, true).login(username,
                                                                                                    password,
                                                                                                    request.getRemoteAddr());
    if (status) {
        session.setAttribute("logged-in", "true");
        session.setAttribute("username", username);
        response.sendRedirect("index.jsp");
    } else {
        session.invalidate();
        response.sendRedirect("index.jsp?failed=true");
    }
%>