2017-02-16 2 views
1

У меня есть особый случай, когда мне нужно использовать контекст безопасности Application Server (Weblogic) для аутентификации, но Spring Security для авторизации. Я использую Spring Boot для создания своего приложения.Используйте ограничения безопасности web.xml с Spring Boot

Как я могу добавить ограничение безопасности, как следует (которые обычно содержатся в web.xml):

<security-constraint> 
     <web-resource-collection> 
      <web-resource-name>portal</web-resource-name> 
      <description>This is the protected area of the application.</description> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <description>Requires users to be authenticated but does not require them to be authorized.</description> 
      <role-name>*</role-name> 
     </auth-constraint> 
     <user-data-constraint> 
      <description>Encryption is not required for this area.</description> 
      <transport-guarantee>NONE</transport-guarantee> 
     </user-data-constraint> 
</security-constraint> 

Помните, что мне это нужно, чтобы быть обработаны с моего Weblogic сервера и неSpring Security

ответ

1

Вы можете добавить web.xml внутри WEB-INF с вашими ограничениями безопасности. Это будет работать вместе с конфигурацией java Spring boot.

@ComponentScan 
@SpringBootApplication 
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer { 

    public static void main(String[] args) { 
     SpringApplication.run(Application.class, args); 
    } 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 
     return builder.sources(Application.class); 
    } 
} 

web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     metadata-complete="false" version="3.0"> 

    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>portal</web-resource-name> 
      <description>This is the protected area of the application.</description> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <description>Requires users to be authenticated but does not require them to be authorized.</description> 
      <role-name>*</role-name> 
     </auth-constraint> 
     <user-data-constraint> 
      <description>Encryption is not required for this area.</description> 
      <transport-guarantee>NONE</transport-guarantee> 
     </user-data-constraint> 
    </security-constraint> 

</web-app>