问题描述
我要为我的网络应用程序使用身份验证应用程序,以跳过用户的注册过程。我使用 java库auth的实现我遇到以下问题
1.我已经使用像twitter这样的授权提供者创建了密钥。但我有问题,而在我的系统上本地运行这个应用程序,因为我给我的网站生成秘密密钥所需的地址。
2.我不能配置我的主机文件,使它接受属性我生成秘密密钥时我给的地址。
这是执行的代码片。
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.action.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);
}
}
在行号23处是空指针异常
AuthProvider provider = AuthProviderFactory.getInstance(id);
抛出一个NPE, -file应该被加载,它不存在:
java.util.Properties.load(未知源)
但我不知道,哪一个缺失。我确定您必须包含某种属性文件。
编辑
在此示例项目中你可以看到一个名为oauth_consumer.properties的文件
可能是属性文件丢失了?
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.action.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::
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.
edithttp://code.google.com/p/socialauth/wiki/StrutsSampleIn this sample-project you ca see a file called oauth_consumer.propertiesMay be that property-file is missing?
这篇关于在Web应用程序中实现授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!