2017-02-16 18 views
1

認証にはApplication Server(Weblogic)セキュリティコンテキストを使用する必要があり、認可にはSpringセキュリティを使用する必要があるという特殊なケースがあります。私はSpring Bootを使ってアプリケーションを作成しています。 (通常web.xmlに含まれるであろう)は次のように私は、セキュリティ制約を追加するにはどうすればよいSpringブートで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-INFの中にweb.xmlを追加することができます。これは、春のブートJavaの設定と一緒に動作します。

@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> 
関連する問題