JBoss 7.1에서 작동하는 JSF 응용 프로그램 (Tomcat 7.0.34)을 배포하고 싶습니다. 지금까지 작동중인 데이터 소스를 구성했습니다. 하지만 컨테이너 관리 인증을 설정하여 문제가 있습니다. index.xhtml을 호출하면 모든 항목이 DB에서 제대로로드됩니다. 그러나 로그인 할 때 사용자는 아무런 역할을하지 못합니다. 따라서 고객 세부 정보 페이지에 액세스 할 수 없습니다. 따라서 나는 구성 할 것을 잊어 버렸는지 물어보고 싶다.JBoss 7.1에서 JSF 응용 프로그램 설치
내 구성 :
standalone.xml는
보안 도메인이 제대로 작동하는 것 같군. 선택한 열 'role'을 'r'로 변경하면 로그인 중에 예외가 발생합니다.
...
<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/bookstore</connection-url>
<driver>mysql</driver>
<security>
<user-name>bookstore</user-name>
<password>book$tore</password>
</security>
</datasource>
...
<security-domain name="SgpRealm" cache-type="default">
<authentication>
<login-module code="Database" flag="required">
<module-option name="dsJndiName" value="java:jboss/datasources/MySqlDS"/>
<module-option name="principalsQuery" value="SELECT pwd FROM customer where eMail=?"/>
<module-option name="rolesQuery" value="SELECT role, role FROM roles WHERE eMail=?"/>
<module-option name="unauthenticatedIdentity" value="anonymous"/>
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
</authentication>
</security-domain>
JBoss의-web.xml을
<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<security-domain>SgpRealm</security-domain>
</jboss>
은 web.xml
<security-constraint>
<web-resource-collection>
<web-resource-name>Authenticated admins only</web-resource-name>
<url-pattern>/faces/sections/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>ADMIN</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/faces/sections/authentication/login.xhtml</form-login-page>
<form-error-page>/faces/sections/authentication/loginFailed.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>ADMIN</role-name>
</security-role>
login.xhtml
<h:form prependId="false">
<table id="loginTable" >
<tr>
<td><h:outputLabel for="email" value="#{msgs.username}" />
</td>
<td><h:inputText id="email" value="#{login.eMail}"
required="true" style="width:100%" /></td>
</tr>
<tr>
<td><h:outputLabel for="password" value="#{msgs.password}" />
</td>
<td><h:inputSecret id="password" value="#{login.password}"
required="true" style="width:100%" /></td>
</tr>
<tr height="50px">
<td colspan="2"><h:commandButton value="#{msgs.login}"
actionListener="#{login.doLogin}" style="width:104%" /></td>
</tr>
</table>
</h:form>
Login.java doLogin # (. ..) 방법
public void doLogin(ActionEvent e) throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context
.getExternalContext().getRequest();
try {
// Try to login customer via container management
request.login(eMail, password);
/*
* Prints out the username (eMail) of the logged in user !!!
*/
System.out.println(request.getUserPrincipal());
if(request.isUserInRole("ADMIN")){
/*
* This part of source is never reached!!!!
*/
System.out.println("Role: ADMIN");
}
...
Tomcat 인스턴스를 사용하면 META-INF 디렉토리 내에 context.xml이라는 파일이 있습니다. (JBoss의 경우 삭제)
<Context>
<Resource name="jdbc/bookstore"
auth="Container"
type="javax.sql.DataSource"
username="bookstore"
password="book$tore"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/bookstore"/>
</Context>
sth가 필요합니까? JBoss와 비슷하거나 추가 구성 파일이 필요합니까?
감사합니다.