小编cod*_*iot的帖子

如何在使用Facebook Javascript SDK时验证用户登录

我已经解决了这个问题,但我的问题不同了.我不确定javascript登录如何确定,以及其他人如何不登录其他帐户.

根据入门 FB.authResponse是在登录成功时调用,但当然在客户端.

然后我们可以得到userIdaccessToken退出响​​应,我们也可以打电话/me获取更多信息.为了将该用户置于会话中,所有关于成功javascript登录的信息必须被发送到服务器,这是我感到困惑的地方.毕竟它是HTTP,每个其他请求都是不同的,可以复制.

可能只是因为我很困惑,关于某人如何不能破解并模仿任何其他用户的脸书ID来登录他的帐户.

例如,在身份验证成功之后,我对我的服务器进行ajax调用,提供fb-user-id然后我将其与数据库匹配并将相应的用户放入会话中,但不是因为这是fb-user-id在后端没有再次验证(或者它是否经过验证?,我没有找到任何关于它的信息)这个特定用户是实际注册我的应用程序的用户,然后是与其他人的fb相同的登录请求-user-id可以登录到他的帐户.

我敢肯定,我不是第一个有这种困惑的人.请帮助清除这种混乱,因为我现在已多次阅读文档,但仍无法弄清楚为什么其他人无法登录其他人的帐户.

编辑 我发现了这个,similar question但这里的人没有回答他如何验证后端登录或可能是我无法理解.

facebook login facebook-graph-api facebook-javascript-sdk

7
推荐指数
1
解决办法
3165
查看次数

如何使用jquery验证插件验证名称中带点的输入字段?

我正在使用这个jquery验证插件

<s:textfield cssClass="form-control input-default" name="contest.title" id="title" placeholder="Enter Title"
                             />
Run Code Online (Sandbox Code Playgroud)

验证不适用于此,但如果我将名称更改为title- 验证工作.

我尝试搜索,但无法找到一种方法来验证.其名称中的字段.

请帮忙

更新

脚本

<script type="text/javascript">
            jQuery(document).ready(function() {
                jQuery("#contestform").validate({
                    submitHandler: function(form) {
//                        return false;  // block the default submit action
                    },
                    rules: {
                        title: {
                            required: true
                        },
                        link: {
                            required: true
                        },
                        startdt: {
                            required: true
                        },
                        enddt: {
                            required: true
                        },
                        descr: {
                            required: true
                        },
                    },
                    messages: {
                        title: "Please enter a title",
                        link: "Please enter the sponser redirection link", …
Run Code Online (Sandbox Code Playgroud)

javascript jquery struts2 jquery-validate

6
推荐指数
1
解决办法
8296
查看次数

如何在自定义非谷歌登录webapp中使用GoogleAuthenticator进行tfa(双因素身份验证)

好吧,我花了2个小时在谷歌上搜索它是什么以及如何在网络应用程序中使用它!但没有成功.

大多数链接都会讨论扫描代码或在GoogleAuthenticar移动应用中输入一些密钥,它会每30秒返回一次更改验证码.

一些事情 :

  1. Web应用程序有自己的登录名.这意味着用户不会使用Google登录到webapp.
  2. 如果攻击者获得了用户的密码,他会将QRcode视为下一步,他可以直接使用手机中的GoogleAuthenticator应用程序进行扫描(据我所知).它是如何仅与用户的手机相关联的?
  3. 在各个网站中,它提到用户和服务器之间的共享秘密,这意味着在注册时,我们向用户提供共享密钥,他可以在她的移动GoogleAuthenticator应用程序中使用,然后在阅读QR代码时使用它?
  4. 在上述情况下,如果用户丢失或遗忘了秘密,该如何处理?使用忘记密码再次将密码发送给用户的电子邮件?

我很困惑,如果它是一个非谷歌非Android应用程序,它怎么能以一种方式实现!

我得到的只是,这只是一个概念,要求我们自己的实现,并在GoogleAuthenticator的源代码中提供一些帮助.请纠正我?

我认为这是解决的办法是,我们必须写我们自己的移动应用,就像提到的这个家伙在这里,但我仍然不知道如何将移动应用与服务器之间的秘密将是独一无二的,每个安装该应用程序,以便它只识别特定用户或有没有办法编写我们自己的应用程序并使用GoogleAuthenticator移动应用程序而无需在我们的webapp中登录Google?

oauth google-api google-authentication google-api-client google-authenticator

5
推荐指数
1
解决办法
2133
查看次数

如何在struts2中映射长REST URL - 使用struts2 rest插件

我过去几天一直在学习使用struts2 rest插件.但没有 - 我在哪里找到了如何映射长休息URL.

例如,如果我想映射如下的URL:

/profiles/user-test/orders/64/item/4
Run Code Online (Sandbox Code Playgroud)

哪里

username is user-test
order id is 64
item id is 4
Run Code Online (Sandbox Code Playgroud)

如何将这样的内容映射到struts2动作?

我在互联网上找到的只是一个级别被编辑/显示等.但如果我想在多个级别上显示某些内容 - 那么如何继续?请指导.

java rest friendly-url struts2 java-ee

4
推荐指数
1
解决办法
1453
查看次数

即使在孩子被保存后,Spring Data Jpa 测试也会返回空列表

@Test
public void testAddPlayerToGame() {
    gameRepository.save(createTestGame());
    Game game = gameRepository.findOne(1l);
    assertTrue(game.getId() > 0);
    Player p = new Player();
    p.setName("test 1");
    p.setGame(game);
    p.setChips(5000);
    assertTrue(p.getId() == null);
    playerRepository.saveAndFlush(p);
    assertTrue(p.getId() != null);

    flushAndClear();
    Game game2 = gameRepository.findOne(1l);
    assertEquals(1, game2.getPlayers().size());
}
Run Code Online (Sandbox Code Playgroud)

上述测试失败,因为game2.getPlayers() returns null.

已经通过JpaRepository 缓存新创建的对象。如何刷新?但想不出如何解决。

flushAndClear上面代码中使用的方法为空,如下:

protected void flushAndClear() {
//        sessionFactory.getCurrentSession().flush();
//        sessionFactory.getCurrentSession().clear();
    }
Run Code Online (Sandbox Code Playgroud)

任何帮助都非常感谢。

更新

游戏和玩家映射代码:

@Entity
@Table(name="game")
public class Game implements Serializable {

    private static final long serialVersionUID = -495064662454346171L;
    private long id;
    private int …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa spring-data spring-data-jpa

4
推荐指数
1
解决办法
2109
查看次数

struts2 junit 2.3.12插件 - 无法在struts2 junit4中编写成功的测试

我正在使用struts2 junit 2.3.12插件.

  1. 如果我直接运行测试,那么我得到:

java.lang.NoClassDefFoundError: javax/servlet/ServletContext

所以我包括

<dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

在我的POM中,之后我得到:

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
Run Code Online (Sandbox Code Playgroud)

所以,我删除上面的依赖项并添加:

 <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <version>1.0.0.Final</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

之后我得到了

SEVERE:   [53:22.549] Dispatcher initialization failed
Run Code Online (Sandbox Code Playgroud)

以下是我的测试:

public class TestAction extends StrutsTestCase {

    @Test
    public void testRegister() throws Exception {
        ActionProxy proxy = getActionProxy("/gotoregister");
        assertNotNull(proxy);

        proxy = getActionProxy("/registeraction");
        UserAction action = (UserAction) proxy.getAction();
        assertNotNull(action);
        request.setParameter("usernameexists", "true");
        request.setParameter("emailexists", "false");
        request.setParameter("basicinfo.firstname", "fname");
        request.setParameter("basicinfo.lastname", "lname"); …
Run Code Online (Sandbox Code Playgroud)

struts2 junit4 java-ee maven struts2-junit-plugin

2
推荐指数
1
解决办法
1797
查看次数

Struts2.3.12 junit4 testcase请求和会话为空

我已经完成了这个解决方案: Struts 2 JUnit Plugin v2.2.3:Test Class Extending StrutsTestCase; 'request'为空

但是我已经没有struts2-spring插件,而且我的应用程序中都没有使用spring.

我有3个测试用例,2个请求失败,为null,一个失败,会话为null

第一个Stacktrace

java.lang.NullPointerException
    at org.apache.struts2.interceptor.MessageStoreInterceptor.before(MessageStoreInterceptor.java:228)
    at org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:193)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at actions.TestIoOptimizationAction.login(TestIoOptimizationAction.java:29)
Run Code Online (Sandbox Code Playgroud)

对应于

            Collection actionErrors = (Collection) session.get(actionErrorsSessionKey);
Run Code Online (Sandbox Code Playgroud)

第二和第三测试堆栈跟踪

java.lang.NullPointerException
    at org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.StrutsJUnit4TestCase.getActionProxy(StrutsJUnit4TestCase.java:149)
Run Code Online (Sandbox Code Playgroud)

对应于

        String contextPath = ServletActionContext.getRequest().getContextPath();
Run Code Online (Sandbox Code Playgroud)

我相信存在一些依赖性问题.我尝试逐个删除一些依赖项并组合使用,但都没有工作.

这是我的POM的样子:

<dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.paypal.sdk</groupId>
            <artifactId>rest-api-sdk</artifactId>
            <version>0.7.1</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.htmlunit</groupId>
            <artifactId>htmlunit</artifactId>
            <version>2.12</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils-core</artifactId>
            <version>1.8.3</version> …
Run Code Online (Sandbox Code Playgroud)

java spring struts2 maven struts2-junit-plugin

2
推荐指数
1
解决办法
3399
查看次数

如何在上下文加载时自动运行java Web应用程序中的servlet /动作(tomcat启动)

我想在我的web-app部署时执行一些代码.

如果我重新启动tomcat,也会发生同样的情况.

这应该只在整个Web应用程序的生命周期中完成一次.

有没有我可以在web.xml中设置的东西,比如启动条目,每次我部署我的web应用程序或重启tomcat时都会执行?

请帮忙.

java jsp servlets struts2

1
推荐指数
1
解决办法
1157
查看次数

node express module throw'没有方法urlencoded'错误

var express=require('express')
var app=express();

console.log("Encoded ",express.urlencoded());

app.use(express.urlencoded());
Run Code Online (Sandbox Code Playgroud)

上面的代码抛出以下错误:

[user@localhost nodejs]$ node program.js

/home/user/Desktop/nodejs/program.js:41
console.log("Encoded ",express.urlencoded());
                               ^
TypeError: Object function createApplication() {
  var app = function(req, res, next) {
    app.handle(req, res, next);
  };

  mixin(app, proto);
  mixin(app, EventEmitter.prototype);

  app.request = { __proto__: req, app: app };
  app.response = { __proto__: res, app: app };
  app.init();
  return app;
} has no method 'urlencoded'
    at Object.<anonymous> (/home/user/Desktop/nodejs/program.js:41:32)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup …
Run Code Online (Sandbox Code Playgroud)

node.js express

1
推荐指数
1
解决办法
2773
查看次数

杰克逊通用json到List <T>转换器方法不起作用

public static <T> List<T> convertJSONStringTOListOfT(String jsonString, Class<T> t){
        if(jsonString == null){
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        try
        {
            List<T> list = mapper.readValue(jsonString, new TypeReference<List<T>>() {});
            return list;
        } catch (JsonGenerationException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
Run Code Online (Sandbox Code Playgroud)

我有以上方法,当我尝试使用以下方法调用它时:

list = convertJSONStringTOListOfT(str, CustomAssessmentQuestionSetItem.class);
Run Code Online (Sandbox Code Playgroud)

返回的列表List<LinkedHashMap>不是List<CustomAssessmentQuestionSetItem>

虽然如果我不使用泛型,那么下面的代码工作正常:

list = mapper.readValue(str, new TypeReference<List<CustomAssessmentQuestionSetItem>>() {});
Run Code Online (Sandbox Code Playgroud)

这两个调用对我来说都是一样的.无法理解为什么通用的创建List<LinkedHashMap>而不是List<CustomAssessmentQuestionSetItem>

仅供参考:我也尝试将方法签名更改为

public static <T> List<T> convertJSONStringTOListOfT(String jsonString, T …
Run Code Online (Sandbox Code Playgroud)

java json jackson fasterxml

1
推荐指数
1
解决办法
1706
查看次数