开发者

Implementing auth in web application

I want to use auth application for my web application to skip the registration process for user . I am using http://code.google.com/p/socialauth/ java library for implementation of auth.I am facing following problem

1.I have created the secret key with those auth provider like twitter. but i am having problem while running this app locally on my system as i give the address of my site required while generating the secret key.

2.I am not able to configure my host file so that it take the properties my the address which i gave while generating the secret key .

Here is the piece of code executing .

package com.auth.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.ac开发者_运维技巧tion.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.RequestUtils;
import org.brickred.socialauth.AuthProvider;
import org.brickred.socialauth.AuthProviderFactory;

import com.auth.form.AuthForm;

public class SocialAuthenticationAction extends Action {

        final Log LOG = LogFactory.getLog(SocialAuthenticationAction.class);

        @Override
        public ActionForward execute(final ActionMapping mapping,
                        final ActionForm form, final HttpServletRequest request,
                        final HttpServletResponse response) throws Exception {

                AuthForm authForm = (AuthForm) form;
                String id = authForm.getId();
                System.out.println("in authentieavtaonsdfsaf");
                AuthProvider provider = AuthProviderFactory.getInstance(id);
                String returnToUrl = RequestUtils.absoluteURL(request,"/socialAuthSuccessAction.do").toString();
                authForm.setProvider(provider);
                String url = provider.getLoginRedirectURL(returnToUrl);
                LOG.info("Redirecting to: " + url);
                if (url != null) {
                        ActionForward fwd = new ActionForward("openAuthUrl", url, true);
                        return fwd;
                }
                return mapping.findForward("failure");
        }
}

Here at line number 23 it is thowing null pointer exception saying that provider is coming as null

ERROR MSG::

Jan 23, 2011 12:26:23 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet action threw exception java.lang.NullPointerException at java.util.Properties$LineReader.readLine(Unknown Source) at java.util.Properties.load0(Unknown Source) at java.util.Properties.load(Unknown Source) at org.brickred.socialauth.AuthProviderFactory.getInstance(AuthProviderFactory.java:72) at com.auth.actions.SocialAuthenticationAction.execute(SocialAuthenticationAction.java:31) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source)


AuthProvider provider = AuthProviderFactory.getInstance(id); is throwing a NPE, because a property-file should be loaded, which does not exist: java.util.Properties.load(Unknown Source)

But I don't know, which one is missing. I am sure you have to include some kind of property-file.

edit http://code.google.com/p/socialauth/wiki/StrutsSample In this sample-project you ca see a file called oauth_consumer.properties May be that property-file is missing?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜