小编che*_*ist的帖子

OAuth 2.0定义客户端

我正在为我们的系统开发基于REST的API.我们将有几种类型的客户:

  • Web浏览器 - 加载HTML5应用程序后将访问我们的API
  • 我们开发的移动应用程序
  • 由第三方开发的移动应用程序

我想问一下我们应该在定义客户端时使用什么策略.例如

  • 是否需要将我们系统中的每个用户定义为客户端,因为他们需要进行身份验证,或者Web客户端是否被视为一个客户端?

  • 我们将客户端分配给我们的iPhone应用程序,另一个客户端分配给我们的Android应

  • 使用我们的API的每个第三方开发者是否获得单独的客户端ID?

谢谢,

阿萨夫

oauth-2.0

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

具有复杂键的Spring @Cacheable仍然执行

我在Spring(3.1)中使用@Cacheable时有以下内容:

弹簧:

<?xml   version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
    xmlns:sec="http://www.springframework.org/schema/security"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 
                            http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
                            http://www.springframework.org/schema/data/mongo
                            http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
                            http://www.springframework.org/schema/cache 
                            http://www.springframework.org/schema/cache/spring-cache.xsd
                            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
                            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
                            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache" />
<!-- Ehcache library setup -->
<bean id="ehcache"  class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
    p:config-location="classpath:ehcache.xml" />
Run Code Online (Sandbox Code Playgroud)

Maven的:

    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-core</artifactId>
        <version>2.5.3</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

要缓存的方法:

@Cacheable(value="cahceName", key="concat(#param1).concat(‘-’).concat(#param2)")
    public String cachedMethod(String param1,String param2)
Run Code Online (Sandbox Code Playgroud)

唉,当我调试代码时,我发现即使param1和param2相同(即不使用cahce),缓存的方法也会被多次调用.

有任何想法吗?

java spring caching

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

Android异常 - 未知来源(可能是小部件)

我有以下Android异常.据Bugsense报道,我找不到它的来源,因为没有任何类我的应用程序的引用.

java.lang.IndexOutOfBoundsException:无效的索引0,在java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)中的大小为0,位于android.widget.HeaderViewListAdapter的java.util.ArrayList.get(ArrayList.java:304). isEnabled(HeaderViewListAdapter.java:164)位于android.widget.LinearLayout.onInitializeAccessibilityNodeInfo(LinearLayout)的android.widget.AbsListView $ ListItemAccessibilityDelegate.onInitializeAccessibilityNodeInfo(AbsListView.java:2512)android.view.View.onInitializeAccessibilityNodeInfo(View.java:4849) .java:1768)android.view.AccessibilityInteractionController上的android.view.View.createAccessibilityNodeInfo(View.java:4812)android.view.AccessibilityInteractionController $ AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController)中的AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:825). java:848)在android.view.AccessibilityInteractionController $ AccessibilityNodePrefetcher.pref etchDescendantsOfRealNode(AccessibilityInteractionController.java:848)在android.view.AccessibilityInteractionController $ AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:848)在android.view.AccessibilityInteractionController $ AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:848)在android.view.AccessibilityInteractionController $ AccessibilityNodePrefetcher位于android.view.AccessibilityController.access上的android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:205)中的.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:734)$ 400(AccessibilityInteractionController.java:49)android.view.AccessibilityInteractionController $ PrivateHandler.handleMessage (AccessibilityInteractionController.java:985)android.os.Handler.dispatchMessage(Handler.java:99)在android.os.Looper.loop(Looper.java:137)在android.app.ActivityThread.main(ActivityThread.java:4867)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1007)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)at dalvik.system.NativeStart.main(Native方法)

我怀疑它与更新小部件有关.关于如何追踪的任何想法?

android exception

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

Android 工具栏弹出菜单不显示图标

我正在尝试为我的工具栏显示一个下拉菜单,其中包含文本和图标:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/menu_add"
        android:title="@string/menu.add"
        android:icon="@drawable/ic_add_black_24dp"
        app:showAsAction="always" />

    <item
        android:id="@+id/menu_edit"
        android:title="@string/menu.edit"
        android:icon="@drawable/ic_create_black_24dp"
        app:showAsAction="never" />

</menu>
Run Code Online (Sandbox Code Playgroud)

menu_add 确实与工具栏上的图标一起显示,但 menu_edit 只显示没有图标的文本。

这个答案:https : //stackoverflow.com/a/19750717/197127说谷歌已经按设计删除了它,但没有提到你可以如何覆盖它。

编辑

我还需要设备“菜单”按钮来显示相同​​的菜单。

android android-menu android-toolbar

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

Spring Oauth2 - 每个客户端ID的多个令牌

我们使用spring-oauth2实现了一个服务器API.我注意到,即使从单独的设备调用,服务器也会为每个用户/客户端ID组合生成相同的令牌.这会导致问题,因为我的客户端可以运行多个实例:例如android和ios应用程序.我需要一种方法将令牌链接到特定实例,而不是重复使用相同的令牌.

需要这样的示例是GCM(或推送通知),其中API需要知道它正在与哪个实例进行通信.

这是我目前的春季配置:

<http pattern="/oauth/token" create-session="stateless"
    authentication-manager-ref="clientAuthenticationManager"
    entry-point-ref="oauthAuthenticationEntryPoint" xmlns="http://www.springframework.org/schema/security">
    <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
    <anonymous enabled="false" />
    <http-basic entry-point-ref="oauthAuthenticationEntryPoint" />
    <!-- include this only if you need to authenticate clients via request parameters -->
    <custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" />
    <access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<oauth:authorization-server
    client-details-service-ref="mongoclientDetails" token-services-ref="tokenServices"
    user-approval-handler-ref="userApprovalHandler">
    <!-- authorization-endpoint-url="/oauth/authorize"  token-endpoint-url="/oauth/token"> -->
    <oauth:authorization-code />
    <oauth:implicit />
    <oauth:refresh-token />
    <oauth:client-credentials />
    <oauth:password />
</oauth:authorization-server>
Run Code Online (Sandbox Code Playgroud)

我不愿意为每个客户提供不同的ID,因为这是不切实际的.有任何想法吗?

spring-security-oauth2

6
推荐指数
2
解决办法
4964
查看次数

如何使 ListHeaderComponent 的一部分粘在 React Native FlatList 上

我有一个 React Native FlatList,带有一个带有 2 个内部文本的 ListHeaderComponent。结构是:

  • 标头
    • 第 1 部分 - 非粘性
    • 第 2 部分 - 粘性
  • 列出项目

这意味着当列表向上滚动时,第 1 部分应该消失(非粘性),而第 2 部分应该保留在列表顶部(粘性)。

这是代码:

<FlatList
  data={ items }
  renderItem={ renderItem }
  ListHeaderComponent={
     <View>
         <Text>Section 1</Text>
         <Text>Section 2</Text>
     </View>
  }
  stickyHeaderIndices={[0]}
/>
Run Code Online (Sandbox Code Playgroud)

我必须将索引设置为 [0],以便它选择标题,但无法选择标题中的第二个。有任何想法吗?

顺便说一句 - 我想在列表滚动时捕获垂直偏移,然后放在 HeaderComponent main <View style={{marginTop: -offset }}> 上,以便模拟滚动。但我的理解是Android不支持负边距。

BTW-2 - 我正在使用react-native-draggable-flatlist,所以我不想将文本放入列表本身,因为这会使列表项的逻辑变得复杂。谢谢!

react-native react-native-flatlist react-native-draggable-flatlist

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

Spring Security登录:用户必须在登录前激活他们的帐户

我已经实施了spring security以保护我们网站的各个部分.我使用DB(MongoDB)来存储用户名/密码.我实现了org.springframework.security.core.userdetails.UserDetailsS​​ervice来查找数据库中的帐户详细信息.

我还需要添加其他功能:帐户激活.注册后,我们会向用户发送激活电子邮件,如果他点击它,我们会在DB中将该帐户标记为已激活.未激活其帐户的用户不应该被允许登录,应该被重定向到该页面.

有关如何实施的任何想法?我需要以某种方式挂钩登录过程.

谢谢!

java security authentication spring

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

Spring加载基于tomcat servlet上下文定义的application.properties

我需要为我们的春季项目进行开发和生产设置.我知道您可以使用弹簧配置文件,但这不是我们可以做的事情.

我想要做的是在开发环境中放置一个test-application.properties文件,并在生产中放置一个prod-application.properties文件.在tomcat上下文定义中,我们发送了以下内容:

<Context>
    <context-param>
        <param-name>properties_location</param-name>
        <param-value>file:C:\Users\Bill\test-application.properties</param-value>
    </context-param>
</Context>
Run Code Online (Sandbox Code Playgroud)

我们可以为生产服务器更改值.在spring配置中我们有这样的东西:

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>${properties_location}</value>
        </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="false" />
</bean>
Run Code Online (Sandbox Code Playgroud)

但我们不断收到如下错误:

org.springframework.beans.factory.BeanInitializationException:无法加载属性; 嵌套异常是java.io.FileNotFoundException:无法打开ServletContext资源[/ $ {properties_location}]

关于如何解决的任何想法?

java spring properties configuration-files

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

MongoDB Map Reduce - Finalize跳过一些结果

我有一个适用于集合的map reduce函数,如下所示:

function Map() {
    emit (
        this.name, 
        { 
            count : 1,
            flag : this.flag

        }
    );
}
function Reduce(key, values) {
    var count = 0;
    var flag = false;

    for (var i in values){
        count = count + 1;
        if (i.flag)
             flag = true;
    }

    var reduced = {
        count : count,
        flag  : flag
    }
    return reduced;
}
function Finalize(key, reduced) {

    if (reduced.count>10 || reduced.flag){
        var finalized = {
            "count" : reduced.count 
        }
        return reduced;
    }

    return …
Run Code Online (Sandbox Code Playgroud)

mapreduce finalize mongodb

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

Spring Social Google - 将一次性授权代码转换为服务器上的访问令牌/刷新令牌

服务器从移动应用程序接收一次性授权代码.我需要将其转换为spring-social访问令牌并刷新令牌并将其保存在服务器数据库中以供以后使用.

我目前的代码:

String oneTimeAuthorizationCode= "xxx"; // provided by mobile client

ConnectionData cd = new ConnectionData("google", null, null, null, null, oneTimeAuthorizationCode, null, null, null);
GoogleConnectionFactory googleConnectionFactory = (GoogleConnectionFactory) connectionFactoryLocator.getConnectionFactory("google");
Connection<Google> connection = googleConnectionFactory.createConnection(cd);

// get the google API and work with it
Google  google = (Google) connection.getApi();
Run Code Online (Sandbox Code Playgroud)

oneTimeAuthorizationCode是错误的,因为ConnectionData期望访问令牌而不是一次授权代码.任何想法如何让spring-social-google交换访问令牌的一次性代码并刷新令牌?

java spring google-login spring-social spring-social-google

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