小编xen*_*ros的帖子

基于请求参数的Spring安全认证

我正在处理的应用程序已经有Spring Security来处理基于表单的身份验证.现在要求是如果在其中一个请求参数中找到令牌,则通过外部服务以编程方式登录用户.

换句话说,如果存在特定的请求参数,例如"令牌",则需要使用该令牌调用外部服务以验证它是否是有效令牌.如果是,那么用户将登录.

我无法弄清楚如何以及在何处"触发"或"挂钩"Spring Security来检查此参数并进行验证,然后在适当时对用户进行身份验证,因为没有登录表单.我认为Spring Security中应该有一些可以扩展或定制的东西来做到这一点?

我浏览了Spring Security文档,想知道AbstractPreAuthenticatedProcessingFilter是否是正确的开始?

authentication spring spring-security url-parameters

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

两者之间有区别吗?和*在cron表达式?奇怪的例子

我的系统中有以下cron表达式:

0 0 0/1 1/1 * ? *
Run Code Online (Sandbox Code Playgroud)

而你知道吗?我不知道这意味着什么.写这篇文章的人是他未来两周的假期,所以我必须自己找出答案.文档可以在这里找到

根据我们的文件:

* * * * * * *
| | | | | | | 
| | | | | | +-- Year              (range: 1970-2099)
| | | | | +---- Day of the Week   (range: 1-7 or SUN-SAT)
| | | | +------ Month of the Year (range: 0-11 or JAN-DEC)
| | | +-------- Day of the Month  (range: 1-31)
| | +---------- Hour              (range: …
Run Code Online (Sandbox Code Playgroud)

java cron spring quartz-scheduler

16
推荐指数
2
解决办法
6443
查看次数

找不到匹配项时返回JPA查询的值

Spring JPA named querys在我的存储库中使用.我的问题是,我无法找到任何信息,对于不匹配任何结果的查询,返回的值是什么.我认为它将为空,findOne()但我不知道它的findAllByName()功能是什么.

有谁知道他/她的经验或知道在文档中的位置?

java named-query spring-data-jpa spring-boot

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

如何在Spring Boot中设置预认证基于头的身份验证?

我的应用程序从Oracle Access Manager SSO获取带有用户名的AUTH_USER请求标头.Spring Security"附加主题"2.2.1有一个"PreAuth"的例子,它似乎是我需要的,但不是一个完整的工作示例.

下面的代码段来自docs/examples,而不是基于注释的配置.

Siteminder示例配置 - 使用带有RequestHeaderAuthenticationFilter的 XML 和PreAuthenticatedAuthenticationProvider以及UserDetailsS​​ervice来查找用户.

这如何映射到基于Java的配置?

<security:http>
  <!-- Additional http configuration omitted -->
  <security:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" />
</security:http>

<bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
  <property name="principalRequestHeader" value="AUTH_USER"/>
  <property name="authenticationManager" ref="authenticationManager" />
</bean>

<bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.    PreAuthenticatedAuthenticationProvider">
  <property name="preAuthenticatedUserDetailsService">
    <bean id="userDetailsServiceWrapper"
          class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
      <property name="userDetailsService" ref="userDetailsService"/>
    </bean>
  </property>
</bean>

<security:authentication-manager alias="authenticationManager">
   <security:authentication-provider ref="preauthAuthProvider" />
</security:authentication-manager>
Run Code Online (Sandbox Code Playgroud)

Spring Security preauth示例具有完全不同的设置(XML配置更加令人生畏).没有提到pre-auth过滤器或如何设置标题名称.

@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests() …
Run Code Online (Sandbox Code Playgroud)

java spring-security single-sign-on pre-authentication spring-boot

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

Spring boot - 将参数从拦截器传递给控制器​​中的方法

出于学习目的,我制作了一个自定义身份验证系统,我通过Authorization标头将令牌从客户端传递到服务器。

在服务器端,我想知道是否可以在拦截器中创建,在请求到达控制器中的方法之前,一个 User 对象,以来自令牌的电子邮件作为属性,然后将此用户对象传递给我需要的每一个请求。

这就是我想得到的,例如:

@RestController
public class HelloController {

    @RequestMapping("/")
    public String index(final User user) {
        return user.getEmail();
    }

}

public class User {
    private String email;
}
Run Code Online (Sandbox Code Playgroud)

其中user是我使用请求Authorization标头在预拦截器中创建的对象,然后我可以传递或不传递给RestController.

这可能吗?

spring spring-mvc interceptor spring-boot

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

Tomcat或Java中是否存在类似beforeCrash()或beforeExit()的函数

我有运行tomcat的服务器.它出于某种原因突然崩溃......但是我试图找到错误.

有没有在Tomcat中或Java类似的功能beforeExit()ifCrashed()我可以重写,写一些代码有一样,如果服务器崩溃,通知自己的某些原因.

java tomcat tomcat7 java-8 tomcat8

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

spring crud存储库按字段C按列表顺序按字段A和字段B查找前n个项目

我在 Spring Repo 中有这样的东西:

findTop10ItemsByCategIdInOrderByInsertDateDesc(List ids)
Run Code Online (Sandbox Code Playgroud)

我想要前 10 个项目,其中类别 id 在按插入日期排序的 id 列表中。

另一个类似的查询:

findTop10ItemsByDomainIdAndCategIdInOrderByInsertDateDesc(List ids, @Param Integer domainId)
Run Code Online (Sandbox Code Playgroud)

在这里,我希望域 id 等于给定的参数,并且 categId 位于给定的列表中。

我设法使用 @Query 解决了它,但我想知道上述查询是否有一个单行。

谢谢

编辑 顶部工作正常。最初我有findTop10ItemsByDomainIdAndCategIdOrderByInsertDateDesc. 现在我想要来自类别 ID 列表的结果。这就是新的要求。

第二次编辑 我的查询用于查找域 id 等于给定参数且类别 id 包含在给定列表中的集合 o 结果。但我发现 HQL 不支持 setMaxResult 类型的东西作为顶部或限制。

@Query("select i from Items i where i.domainId = :domainId and i.categId in :categoryIds order by i.insertDate desc")
Run Code Online (Sandbox Code Playgroud)

这个方法的参数是(@Param("domainid") Integer domainid,List<Integer> categoryIds)但它接缝我被允许对每个参数使用 @Param 注释或根本不使用 @Param (除了 Pageable 返回;不是我的情况)

我仍然不知道如何实现这个想法:提取前 n 个元素,其中字段 a …

spring spring-data-jpa spring-repositories

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

如何删除 http 302 响应中的授权标头

我正在使用 Java/Jersy 框架(Tomcat)进行 REST API 开发。此类 Web 服务的一项功能是将 (HTTP 302) 重定向到文件的 S3 签名 URL。我们使用“授权”标头来检查请求的有效性。调用此 Web 服务时,该服务会生成带有签名的签名 url,并重定向到已签名的 Url。

来自 REST Web 服务的 Java 代码(uri 是签名的 url)

return Response.status(HttpStatus.SCMOVEDTEMPORARILY).location(uri).build();
Run Code Online (Sandbox Code Playgroud)

当重定向发生时,授权标头也与签名一起传递。由于亚马逊接受签名 URL 中的授权或签名,但不是两者都接受,因此它会从 Amazon S3 中引发如下错误。

只允许一种身份验证机制;仅应指定 X-Amz-Algorithm 查询参数、签名查询字符串参数或授权标头

有没有办法在重定向发生时删除正在发送的这个标头......

我尝试添加一个过滤器,它使用自定义 HttpServletResponseWrapper 实现覆盖 ServletResponse 并在 addHeader 和 setHeader 方法中记录标头名称。它从不为 Authorization 标头调用此方法。

将标头设置为 nulll 或 "" 的修改代码都不起作用..

return Response.status(HttpStatus.SCMOVEDTEMPORARILY).location(uri).header("Authorization",null).build();
return Response.status(HttpStatus.SCMOVEDTEMPORARILY).location(uri).header("Authorization","").build();
Run Code Online (Sandbox Code Playgroud)

java http jersey

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

如何使用分页和spring数据jpa获取findAll()服务的所有记录?

如何findAll ()使用分页获取所有服务记录,Spring Data JPA 当我们不应用过滤器时,它应该返回所有记录,而不是按页面显示。我有findAll (Pageable pageable)服务,并从自定义存储库调用它。是否可以仅使用分页来将所有记录放在一页中?

java spring spring-data-jpa

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

Java - 指向同一个键的多个哈希映射

我有多个文件,其中包含key = value字符串对.文件之间的键是相同的,但值不同.每个文件可以有1000多个这样的对.

我想将每个文件存储在一个单独的hashmap中,即map<KeyString, ValueString>如果有五个文件,则会有五个hashmap.

为避免在每个散列映射中复制键,是否可以让每个映射引用相同的键?请注意,一旦将键添加到地图中,它将不会被删除.

我考虑将第一个文件设置为flyweight模式中的"base",此基数将是键/值的固有集合.其余剩余的文件将是外部值集,但我不知道如何将值与基本(内部)键相关联而不复制键?

我对更简单/更好的方法持开放态度.

java hashmap

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