2016-12-01 2 views
0

Apache shiroとrest Webサービスの新機能です。私の要求に基づいて、私はShiroとrestサービスを使って簡単なPOCを作成しています。Apache Shiroを使用した認証のためのシンプルなPOC

私のアプリケーションでは、ログインページは使用していません。単に4つのWebサービスメソッドを持つTestService.javaを1つだけ用意しています 残りのクライアントを呼び出すことで、異なるロールで各Webサービスメソッドを制御したいと考えています。必要な

insertNewData()方法は、ロール 'を挿入' それ以外の場合は必要ないくつかのエラーメッセージ

updateNewData()方法 "更新の役割を示し、それ以外の場合は必要ないくつかのエラーメッセージ

deleteNewData()方法を示す「を削除する意味'ロール、そうでない場合は何らかのエラーメッセージを表示する

searchAllData()メソッドが必要です 'admin'ロール、そうでない場合は何らかのエラーメッセージが表示されます

私の要件と残りの設定にshiro.iniファイルを設定する方法についてはわかりません。

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" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0"> 

<display-name>SimpleRest</display-name> 

<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
</welcome-file-list> 

<servlet> 
    <servlet-name>Jersey Web Application</servlet-name> 
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Jersey Web Application</servlet-name> 
    <url-pattern>/test/*</url-pattern> 
</servlet-mapping> 

<listener> 
    <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class> 
</listener> 
<filter> 
    <filter-name>ShiroFilter</filter-name> 
    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>ShiroFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping> </web-app> 

/WEB-INF/shiro.iniここでは、Webサービスごとに異なる役割を設定する方法

[main] 

[users] 

[roles] 

[urls] 
/index.html = anon 

TestService.java

を打ちます

のpom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>SimpleRest</groupId> 
<artifactId>SimpleRest</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 

<properties> 
    <jdk.version>1.7</jdk.version> 
    <shiro.version>1.2.4</shiro.version> 
    <commons-logging.version>1.2</commons-logging.version> 
    <logback-classic.version>1.1.3</logback-classic.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.apache.shiro</groupId> 
     <artifactId>shiro-core</artifactId> 
     <version>${shiro.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.shiro</groupId> 
     <artifactId>shiro-web</artifactId> 
     <version>${shiro.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>${commons-logging.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-classic</artifactId> 
     <version>${logback-classic.version}</version> 
    </dependency> 


    <dependency> 
     <groupId>asm</groupId> 
     <artifactId>asm</artifactId> 
     <version>3.3.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-bundle</artifactId> 
     <version>1.19</version> 
    </dependency> 
    <dependency> 
     <groupId>org.json</groupId> 
     <artifactId>json</artifactId> 
     <version>20140107</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>1.19</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-core</artifactId> 
     <version>1.19</version> 
    </dependency> 
</dependencies> 

<build> 
    <finalName>SimpleRest</finalName> 
    <sourceDirectory>src</sourceDirectory> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.4</version> 
      <configuration> 
       <warSourceDirectory>WebContent</warSourceDirectory> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 
    </plugins> 
</build></project> 

この上で私を助けてください。 ありがとうございました

答えて

関連する問題