2016-11-07 6 views
1

のために動作しません、私はカスタムログインモジュールを持っている:JAASログアウトWildFly 9サーバー上で実行されている私のJava EEアプリケーションでは、カスタムログインモジュール

public class MyLoginModule extends AbstractServerLoginModule { 

    private Principal identity; 

    @Override 
    public boolean login() throws LoginException { 
     // do something 
     identity = new SimplePrincipal("test"); 
     subject.getPrincipals().add(identity); 
     // do something else 
     return true; 
    } 

    @Override 
    public boolean logout() throws LoginException { 
     subject.getPrincipals().remove(identity); 
     return true; 
    } 
} 

予想通りlogin方法で動作します。しかし、logoutメソッドでは同じではありません。私はServletまたはWebサービスからrequest.getSession(false).invalidate();のようなものを書くとき、logout方法がnerver達しています。

ここに私の設定ファイル:

web.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> 

    <display-name>customer-area</display-name> 

    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>restricted resources</web-resource-name> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>*</role-name> 
     </auth-constraint> 
    </security-constraint> 

    <security-role> 
     <role-name>*</role-name> 
    </security-role> 

    <login-config> 
     <auth-method>MY-AUTH</auth-method> 
    </login-config> 

</web-app> 

のjboss-web.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-web> 
    <security-domain>java:/jaas/MySecurityDomain</security-domain> 
</jboss-web> 

standalone.xml

<security-domain name="MySecurityDomain" cache-type="default"> 
    <authentication> 
     <login-module code="mypackage.MyLoginModule" flag="required"/> 
    </authentication> 
</security-domain> 

ServletExtensionクラス:

public class MyServletExtension implements ServletExtension { 

    @Override 
    public void handleDeployment(final DeploymentInfo deploymentInfo, ServletContext servletContext) { 

     deploymentInfo.addAuthenticationMechanism("MY-AUTH", new AuthenticationMechanismFactory() { 
      @Override 
      public AuthenticationMechanism create(String mechanismName, FormParserFactory formParserFactory, Map<String, String> properties) { 
       return new MyAuthenticationMechanism(); 
      } 
     }); 
    } 
} 

AuthenticationMechanismクラス:

public class MyAuthenticationMechanism implements AuthenticationMechanism { 

    @Override 
    public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) { 

     PasswordCredential credential = new PasswordCredential(new char[] {}); 
     Account account = identityManager.verify("test", credential); 
     if (account != null) { 
      return AUTHENTICATED; 
     } else { 
      return NOT_AUTHENTICATED; 
     } 
    } 
} 

は、私が何かを見逃していましたか?

+0

@Locあなたは 'でrequest.getSession(false)を.invalidate()' 'logout'メソッドを呼び出す方法ではないことを言っていますか?この場合、私はまだ理解していないことがあります。多分あなたは私を啓発することができます。 – cheb1k4

+0

おそらく問題に直接関係していない+私は間違っているかもしれません(私は長い間JAASを使用していませんでした)が、セッション固有の状態、つまり「プリンシパルID」をログインモジュールに保持するのは正しいですか? –

+0

@Locここでは、男が 'request.getSession(false).invalidate()'が 'logout'メソッドのトリガーであると言う例を示します:http://www.byteslounge.com/tutorials/jaas-logout-example。私が見つけたのはそれだけではありません。 @NikosParaskevopoulos良い質問です。私はそれはだと思うが、多分私は間違っている。私はこれを後でチェックします。 – cheb1k4

答えて

0

MyLoginModule.logout()request.logout()で到達できるようにする方法。私は自分でそれを見つけるべきだった!

関連する問題