小编dur*_*dur的帖子

如何在Spring Security中为REST API调用返回401?

以下是我的示例Spring Security配置。

我希望所有人/api返回HTTP 401代码,而不是将302重定向到登录页面。

我也想保留旧网页的重定向功能。

<security:http auto-config='true' use-expressions="true" >
    <security:intercept-url pattern="/api*" access="hasRole('USER')" />
    <security:intercept-url pattern="/oldweb*" access="hasRole('USER')" />

    <security:form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?login_error=1" default-target-url="/home"/>    
</security:http>
Run Code Online (Sandbox Code Playgroud)

spring spring-security

5
推荐指数
2
解决办法
3918
查看次数

使用 Spring Boot 进行 inMemoryAuthentication

我使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎生成了一个 Spring Boot Web 应用程序,并将其打包为可执行 JAR 文件。

使用的技术:

Spring Boot 1.4.2.RELEASE、Spring 4.3.4.RELEASE、Thymeleaf 2.1.5.RELEASE、Tomcat Embed 8.5.6、Maven 3、Java 8

这是我的安全配置类:

@Configuration
@EnableWebSecurity
@PropertySource("classpath:/com/tdk/iot/config/app-${APP-KEY}.properties")
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${securityConfig.formLogin.loginPage}")
    private String loginPage;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .formLogin()
                .loginPage(loginPage)
                .permitAll()
                .loginProcessingUrl("/login")
                .failureUrl("/login.html?error=true")
                .defaultSuccessUrl("/books/list")
                .and()
            .exceptionHandling()
                .accessDeniedPage("/denied")
                .and()
            .authorizeRequests()
                .antMatchers("/mockup/**").permitAll()
                .antMatchers("/books/**").permitAll()
                .antMatchers("/welcome/**").authenticated()
                .and()
            .logout()
                .permitAll()
                .logoutSuccessUrl("/index.html");
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .passwordEncoder(new StandardPasswordEncoder())
                .withUser("test1").password("test1").roles("ADMIN").and()
                .withUser("test2").password("test2").roles("USER").and()
                .withUser("test3").password("test3").roles("SUPERADMIN");
    }

    @Bean …
Run Code Online (Sandbox Code Playgroud)

authentication spring spring-mvc spring-security spring-boot

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

WebMvcConfigurer和WebSecurityConfigurerAdapter之间的区别

两者之间有什么区别?什么时候可以使用另一个?

Spring Security文档中,它说WebMvcConfigurer具有以下功能:

要求对应用程序中的每个URL进行身份验证

WebSecurityConfigurerAdapter所示例子HttpSecurity说:

确保对我们应用程序的任何请求都需要对用户进行身份验证。

是不是一样?

编辑

这两种类型的配置似乎有不同的用途,我只是不太了解何时使用哪种配置:每种配置类型的两种不同情况是什么?

HttpSecuriy部分的简介中,它说

Spring Security如何知道我们要要求所有用户进行身份验证?Spring Security如何知道我们要支持基于表单的身份验证?

所以现在我在想:第一个提示对用户进行身份验证时会发生什么,第二个提示在什么情况下需要对用户进行身份验证。那是对的吗?

例如,第一个配置“为您生成一个登录表单”,第二个配置确定何时应显示该登录表单?

spring-security

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

使用Wss4jSecurityInterceptor会抛出WRONG_DOCUMENT_ERR:与创建该节点的节点不同的节点用于另一文档中

我正在将应用程序升级到Java 11和Spring boot 2.1.2,并在尝试通过SOAP与外部合作伙伴通信时遇到以下错误。导致此问题的原因是Wss4jSecurityInterceptor。在运行Java 8和Spring Boot 1之前可以工作

REQUEST: ExampleSoapClient.sendRequest([javax.xml.bind.JAXBElement@5bba179f]). 
ERROR: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
at java.xml/com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:356)
at java.xml/com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(ParentNode.java:287)
at java.xml/com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:237)
at org.apache.wss4j.dom.util.WSSecurityUtil.prependChildElement(WSSecurityUtil.java:314)
at org.apache.wss4j.dom.util.WSSecurityUtil.findWsseSecurityHeaderBlock(WSSecurityUtil.java:435)
at org.apache.wss4j.dom.message.WSSecHeader.insertSecurityHeader(WSSecHeader.java:165)
at org.apache.wss4j.dom.handler.WSHandler.doSenderAction(WSHandler.java:117)
at org.springframework.ws.soap.security.wss4j2.Wss4jHandler.doSenderAction(Wss4jHandler.java:63)
at org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor.secureMessage(Wss4jSecurityInterceptor.java:574)
at org.springframework.ws.soap.security.AbstractWsSecurityInterceptor.handleRequest(AbstractWsSecurityInterceptor.java:210)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:597)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:378)
at com.example.domain.integration.provider.ExampleSoapClient.sendRequest(ExampleportSoapClient.java:61)
Run Code Online (Sandbox Code Playgroud)

Java 11和Spring Boot 2.1.2升级

import com.sun.xml.wss.impl.callback.PasswordCallback;
import com.sun.xml.wss.impl.callback.UsernameCallback;
import …
Run Code Online (Sandbox Code Playgroud)

java soap-client spring-boot

5
推荐指数
2
解决办法
1374
查看次数

在Maven 2中,是否可以为所有内容指定镜像,但允许故障转移到直接存储库?

我理解设置Maven镜像的部分吸引力,如下所示:

<mirror>
  <id>nexus</id>
  <name>Maven Repository</name>
  <mirrorOf>*</mirrorOf>
  <url>http://server:8081/nexus/content/groups/public</url>
</mirror>
Run Code Online (Sandbox Code Playgroud)

......是文件说明:

您可以通过使Maven镜像所有存储库请求来强制Maven使用单个存储库.

但是,这是否表明通过*设置镜像必须强制每个工作站通过镜像?

我问,因为我希望每个工作站都能进行故障转移,并在Nexus无法解析依赖关系或插件的情况下直接连接到它知道的任何公共存储库.(在一个完美的世界中,每个开发人员都有必要的访问权限,可以根据需要添加其他代理存储库.但是,有时访问不可用;有时Nexus服务器会关闭;有时它会遇到Java堆错误.)

这是"镜像,但可以直接连接到公共存储库",可以在Maven 2中进行故障转移配置吗?它会在Maven 3中吗?

java maven-2 nexus

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

XSLT XML to XML如果不存在特定子项,则删除节点

我是XSL的新手,无法找到有关此问题的信息.这仅适用于XSLT 1.0,最终将从XSLTproc运行.

这是一个示例XML

<root>
    <node>
        <data />
        <child>
            <grandchild />
        </child>
        <step-child action="removenode" />
    </node>
    <node>
        <data />
        <step-child action="removenode" />
    </node>
</root>
Run Code Online (Sandbox Code Playgroud)

基本上,我想保留以下所有内容:

  • 删除没有的任何节点 <child>
  • 移除所有 <step-child>

我只能弄清楚如何删除不需要的节点,但即便如此也是有问题的.我真的很感激任何帮助.

xml xslt

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

RabbitMQ SSL 与 Apring AMQP 1.4.3 连接

我正在尝试通过 SSL 连接到 RabbitMQ。我已按照[此处}(https://www.rabbitmq.com/ssl.html)链接的 RabbitMQ SSL 文档进行操作。

根据 RabbitMQ SSL 文档,由于已知漏洞,不建议使用 SSLv3 和 TLSv1 连接。因此,我按照说明在 RabbitMQ 上禁用了这些协议。

我正在使用 Spring AMQP 1.4.3 连接到 RabbitMQ。

ApplicationContext context = new GenericXmlApplicationContext("classpath:/testConfig/testrabbit-context.xml");
RabbitTemplate template = context.getBean(RabbitTemplate.class);
MessageProperties messageProperties = new MessageProperties();
org.springframework.amqp.core.Message amqpMessage = new org.springframework.amqp.core.Message("Test".getBytes(), messageProperties);
String routingKey = "TEST.businessevent.route";
template.send(routingKey, amqpMessage);
Run Code Online (Sandbox Code Playgroud)

我的配置:

<rabbit:connection-factory id="rabbitConnectionFactory"
    connection-factory="clientConnectionFactory"        
    host="localhost" 
    port="5671" 
    username="username"
    password="password" 
    virtual-host="test_host" />

<rabbit:admin connection-factory="rabbitConnectionFactory" />

<rabbit:template id="rabbitTemplate"
    connection-factory="rabbitConnectionFactory" exchange="test_topic" />

<rabbit:topic-exchange name="test_topic" durable="true" />  

<bean id="clientConnectionFactory" class="org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean">
    <property name="useSSL" value="true" />
    <property name="sslPropertiesLocation" …
Run Code Online (Sandbox Code Playgroud)

ssl spring-amqp

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

如果缺少PDF的字体,为什么jasper报告不会抛出JRFontNotFoundException?

我读

我希望Jasper Reports会抛出一个JRFontNotFoundException如果机器上没有安装字体的话.

但我的应用程序并没有抛出JRFontNotFoundException,虽然我没有在任何(Jaspersoft Studios,JasperReports,Adobe Acrobat Reader)机器上安装使用过的字体"Helvetica".

JRXML:

<parameter name="timestamp" class="java.util.Date"/>
[...]
<textField>
    <reportElement x="0" y="0" width="50" height="16" uuid="0007846a-26f1-457a-a198-67a2f7c8417c">
        <property name="local_mesure_unitwidth" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.width" value="px"/>
        <property name="local_mesure_unitx" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.x" value="px"/>
        <property name="local_mesure_unity" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.y" value="px"/>
        <property name="local_mesure_unitheight" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.height" value="px"/>
    </reportElement>
    <box padding="2"/>
    <textElement textAlignment="Left" verticalAlignment="Top">
        <font size="8" pdfFontName="Helvetica" pdfEncoding="Cp1250" isPdfEmbedded="true"/>
    </textElement>
    <textFieldExpression><![CDATA[DATEFORMAT($P{timestamp},"dd.MM HH:mm")]]></textFieldExpression>
</textField>
Run Code Online (Sandbox Code Playgroud)

Maven依赖:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>5.6.0</version>
</dependency>
<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-functions</artifactId>
    <version>5.6.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

Java的:

private byte[] …
Run Code Online (Sandbox Code Playgroud)

java fonts pdf-generation jasper-reports export-to-pdf

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

将存储库从Sonatype Nexus 1.9迁移到3.0

我们目前有一个Nexus存储库(版本1.9),用于将我们的Maven工件存储在旧服务器中.在我们的新服务器中,我们安装了最新版本的Nexus存储库(3.0.2).显然,版本1.9根据Maven坐标树(org/apache/commons/...)直接在文件系统中存储Maven工件,但版本3.0.2将工件存储在弹性搜索存储库中,作为blob对象.

所以我的问题是:如何将所有工件从版本1.9轻松迁移到新版本3.0.2?迁移工具应该附带3.1版本,但我担心它只涉及从2.x到3.1的迁移.它是这个进程的一组shell命令吗?

migration repository nexus

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

如何在 Camunda Spring Boot 应用程序的 Junit 测试中使用 ProcessEngineRule?

我尝试为 Camunda Spring Boot 应用程序运行 JUnit 测试。我跟着测试

JUnit 4

使用 JUnit 4 编写单元测试的风格,必须使用 ProcessEngineRule。通过此规则,流程引擎和服务可通过 getter 获得。与 ProcessEngineTestCase(见上文)一样,包含此规则将在类路径上查找默认配置文件。当使用相同的配置资源时,流程引擎静态缓存在多个单元测试上。

以下代码片段显示了使用 JUnit 4 测试风格和 ProcessEngineRule 用法的示例。

public class MyBusinessProcessTest {

  @Rule
  public ProcessEngineRule processEngineRule = new ProcessEngineRule();

  @Test
  @Deployment
  public void ruleUsageExample() {
    RuntimeService runtimeService = processEngineRule.getRuntimeService();
    runtimeService.startProcessInstanceByKey("ruleUsage");

    TaskService taskService = processEngineRule.getTaskService();
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("My Task", task.getName());

    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
  }
}
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [activiti.cfg.xml]; nested exception is java.io.FileNotFoundException: class path …
Run Code Online (Sandbox Code Playgroud)

junit4 camunda spring-boot

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