java - Apache Shiro authc.loginUrl no redirect to my jersey services after login -


i want secure jersey jax-rs services apache shiro security with out jsp not working.

when use browser test services server redirect me login page expected , when insert username , password , press submit button the server not redirect me service after login.

i getting error: http error 404 problem accessing /rest/hello/some_text. reason: not found powered jetty://

the code working on can download here https://github.com/javajack/shiro-jersey.git , sub project "jersey-sample" modified shiro.ini , change the: "authcbasic" "authc".

i test browser: url: localhost:port/rest/hello/some_text

what missing ?

the following configuration:

shiro.ini:

[main] authc.loginurl = /connect.html  [users] root = secret,admin guest = guest,guest presidentskroob = 12345,president darkhelmet = ludicrousspeed,darklord,schwartz lonestarr = vespa,goodguy,schwartz  [roles] admin = * schwartz = lightsaber:* goodguy = winnebago:drive:eagle5  [urls] /connect.html = authc /rest/** = authc 

web.xml:

 <!doctype web-app public  "-//sun microsystems, inc.//dtd web application 2.3//en"  "http://java.sun.com/dtd/web-app_2_3.dtd" >  <web-app>     <display-name>rest web application jax-rs security framework</display-name>      <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>     </filter-mapping>      <listener>         <listener-class>org.apache.shiro.web.env.environmentloaderlistener</listener-class>     </listener>      <servlet>         <servlet-name>jersey-servlet</servlet-name>         <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class>         <init-param>             <param-name>com.sun.jersey.config.property.packages</param-name>             <param-value>org.apache.shiro.jersey.sample</param-value>         </init-param>         <init-param>             <param-name>com.sun.jersey.spi.container.resourcefilters</param-name>             <param-value>org.apache.shiro.jersey.shiroresourcefilterfactory</param-value>         </init-param>         <load-on-startup>1</load-on-startup>     </servlet>      <servlet-mapping>         <servlet-name>jersey-servlet</servlet-name>         <url-pattern>/rest/*</url-pattern>     </servlet-mapping> </web-app> 

adminsecretsresource.java

package org.apache.shiro.jersey.sample;  import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.core.response;  import org.apache.shiro.authz.annotation.requiresroles;  @path("/admin") @requiresroles("admin") public class adminsecretsresource {     @get    public response tellsecret() {       final string output = "shh, secret answer 41.";       return response.status(200).entity(output).build();    }  } 

helloworldresource .java

package org.apache.shiro.jersey.sample;  import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.pathparam; import javax.ws.rs.core.response;  @path("/hello") public class helloworldresource {     @get    @path("/{message}")    public response sayhello(@pathparam("message") string message) {       string output = "jersey says : " + message;       return response.status(200).entity(output).build();    }  } 

connect.html

<!doctype html> <html> <head>     <title>apache shiro tutorial webapp : login</title>     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">     <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css">     <style> body{padding-top:20px;} </style> </head> <body>     <div class="container">         <div class="row">             <div class="col-md-4 col-md-offset-4">                 <div class="panel panel-default">                     <div class="panel-heading">                         <h3 class="panel-title">please sign in</h3>                     </div>                     <div class="panel-body">                         <form name="loginform" action="" method="post" accept-charset="utf-8" role="form">                             <fieldset>                                 <div class="form-group">                                     <input class="form-control" placeholder="username or email" name="username" type="text">                                 </div>                                 <div class="form-group">                                     <input class="form-control" placeholder="password" name="password" type="password" value="">                                 </div>                                 <div class="checkbox">                                     <label>                                         <input name="rememberme" type="checkbox" value="true"> remember me                                     </label>                                 </div>                                 <input class="btn btn-lg btn-success btn-block" type="submit" value="login">                             </fieldset>                         </form>                     </div>                 </div>             </div>         </div>     </div>     <script src="https://code.jquery.com/jquery.js"></script>     <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script> </body> </html> 

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/maven-v4_0_0.xsd">     <parent>         <groupid>org.apache.shiro.jersey</groupid>         <artifactid>shiro-jersey-root</artifactid>         <version>1.0.0</version>         <relativepath>../pom.xml</relativepath>     </parent>      <modelversion>4.0.0</modelversion>     <groupid>org.apache.shiro</groupid>     <artifactid>jersey-sample</artifactid>     <name>apache shiro :: samples :: jersey</name>     <version>1.0.0</version>     <packaging>war</packaging>      <dependencies>         <dependency>             <groupid>org.apache.shiro</groupid>             <artifactid>shiro-core</artifactid>             <version>[1.2.1,2.0.0)</version>         </dependency>         <dependency>             <groupid>org.apache.shiro</groupid>             <artifactid>shiro-web</artifactid>             <version>[1.2.1,2.0.0)</version>         </dependency>         <dependency>             <groupid>org.apache.shiro</groupid>             <artifactid>shiro-jersey</artifactid>             <version>1.0.0</version>         </dependency>         <dependency>             <groupid>com.sun.jersey</groupid>             <artifactid>jersey-server</artifactid>             <version>[1.10,2.0)</version>         </dependency>         <dependency>             <groupid>com.sun.jersey</groupid>             <artifactid>jersey-servlet</artifactid>             <version>[1.10,2.0)</version>         </dependency>         <dependency>             <groupid>commons-logging</groupid>             <artifactid>commons-logging</artifactid>             <version>1.2</version>         </dependency>     </dependencies>       <build>         <plugins>             <plugin>                 <artifactid>maven-surefire-plugin</artifactid>                 <configuration>                     <forkmode>never</forkmode>                 </configuration>             </plugin>             <plugin>                 <groupid>org.mortbay.jetty</groupid>                 <artifactid>maven-jetty-plugin</artifactid>                 <version>6.1.26</version>                 <configuration>                     <contextpath>/</contextpath>                     <connectors>                         <connector implementation="org.mortbay.jetty.nio.selectchannelconnector">                             <port>9080</port>                             <maxidletime>60000</maxidletime>                         </connector>                     </connectors>                     <requestlog implementation="org.mortbay.jetty.ncsarequestlog">                         <filename>./target/yyyy_mm_dd.request.log</filename>                         <retaindays>90</retaindays>                         <append>true</append>                         <extended>false</extended>                         <logtimezone>gmt</logtimezone>                     </requestlog>                 </configuration>             </plugin>         </plugins>     </build>  </project> 

update shiro.ini configuration file add login page form authentication filter below:

  • shiro.ini:

    [urls] /connect.html = authc /rest/** = authc 

this shiro engine process request along authentication request (/connect.html) using formauthenticationfilter. paths complementory , should both specified work correctly.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -