jboss-as-7.1.1.Final\standalone\configuration:

1, standalone.xml中 <security-domains>标签里面添加:

<security-domain name="myRealm" cache-type="default">
<authentication>
<login-module code="Remoting" flag="required">
<module-option name="usersProperties" value="${jboss.server.config.dir}/application-users.properties"/>
<module-option name="rolesProperties" value="${jboss.server.config.dir}/application-roles.properties"/>
<module-option name="realm" value="ApplicationRealm"/>
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
</authentication>
</security-domain>

使用application-users.properties,application-roles.properties中定义的用户和角色。

2,在war中 WEB-INF 中加入文件 jboss-web.xml:

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

3,在 web.xml中加入:

<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>guest</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>myRealm</realm-name>
</login-config>
<security-role>
<description> A user </description>
<role-name>guest</role-name>
</security-role>

另外需注意,如果使用 primefaces,bootsfaces,由于他们使用css样式或者js,ttf等文件,如果他们位于需要认证的目录,但是login.xhtml又需要访问。这时需要在web.xml中排除掉 secure-constaint. 由于这个原因,登录页面的用户图标一直不显示,还得我调试了一天b:icon。

用bootfaces做的登录页面:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:b="http://bootsfaces.net/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<title>Sign In Template for BootsFaces</title>
<meta name="author" content="Riccardo Massera"></meta>
<style type="text/css">
.form-signin {
margin: 0 auto;
max-width: 330px;
padding: 15px;
}
</style>
</h:head>
<h:body style="padding-top: 60px; background-color: #add;">
<b:container>
<h:form id="login" onsubmit="action='j_security_check';" styleClass="form-signin">
<h2 class="form-signin-heading">请登陆</h2>
<b:inputText id="j_username1" placeholder="Email address" fieldId="j_username" name="j_username">
<f:facet name="prepend">
<b:icon name="user" />
</f:facet>
</b:inputText>
<b:inputText id="j_password1" placeholder="Password" type="password" fieldId="j_password" name="j_password">
<f:facet name="prepend">
<b:iconAwesome name="key" />
</f:facet>
</b:inputText> <b:commandButton look="primary btn-block" id="submit" value="登录" ajax="false" size="lg"/>
</h:form>
</b:container>
</h:body>
</html>

primefaces使用这个登录页面:

<h:form id="login" onsubmit="action='j_security_check';" prependId="false">
<h:panelGrid columns="2">
<p:outputLabel for="j_username" value="Username" />
<p:inputText id="j_username" />
<p:outputLabel for="j_password" value="Password" />
<p:password id="j_password" />
<p:commandButton id="submit" value="Login" ajax="false"/>
</h:panelGrid>
</h:form>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/faces/index.xhtml</welcome-file>
</welcome-file-list> <security-constraint>
<display-name>Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/faces/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Manager</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint> <login-config>
<auth-method>FORM</auth-method>
<realm-name>dbdomain</realm-name>
<form-login-config>
<form-login-page>/faces/views/login.xhtml</form-login-page>
<form-error-page>/faces/views/loginError.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>Manager</role-name>
</security-role> <!-- not secure page -->
<security-constraint>
<display-name>UnSecuredPages</display-name>
<web-resource-collection>
<!-- *.js no use. -->
<web-resource-name>login-required</web-resource-name>
<url-pattern>*.js</url-pattern>
</web-resource-collection>
<web-resource-collection>
<web-resource-name>ttf</web-resource-name>
<url-pattern>/faces/fonts/*</url-pattern>
</web-resource-collection>
<web-resource-collection>
<web-resource-name>login-required1</web-resource-name>
<url-pattern>/faces/javax.faces.resource/*</url-pattern>
</web-resource-collection>
</security-constraint> <context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param> <session-config>
<session-timeout>
0
</session-timeout>
</session-config> <context-param>
<param-name>net.bootsfaces.get_fontawesome_from_cdn</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bootstrap</param-value>
</context-param>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>

参考:

http://blog.sina.com.cn/s/blog_7253d65401018syh.html

http://www.cnblogs.com/davidwang456/p/3897684.html

Jboss7.1 加入realm auth认证 bootsfaces 美化的登录页面的更多相关文章

  1. Http basic Auth 认证方式帮助类

    BasicAuthenticationUtil import java.io.IOException; import java.security.MessageDigest; import javax ...

  2. java 发送带Basic Auth认证的http post请求

    构造http header private static final String URL = "url"; private static final String APP_KEY ...

  3. Bootstrap+Thinkphp3.2+Auth认证+jquery-validator后台

    Auth权限认证 本例采用auth权限认证,用户和用户组采用多对多关系处理,自动添加rule规则,带有jquery-validator插件,自动控制菜单显示或隐藏.   config.php中的配置 ...

  4. Django学习之九: auth 认证组件

    目录 Django auth 认证组件 配置使用auth组件及其中间件 request.user 可以直接在template模版中使用 auth组件常用api 获取认证model类 认证检测装饰器@l ...

  5. Django auth认证

    Django自带的用户认证 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能,这还真是个麻烦的事情呢. Djang ...

  6. Django auth认证系统

    Django自带的用户认证 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能,这还真是个麻烦的事情呢. Djang ...

  7. Django认证系统auth认证

    使用Django认证系统auth认证 auth认证系统可以处理范围非常广泛的任务,且具有一套细致的密码和权限实现.对于需要与默认配置不同需求的项目,Django支持扩展和自定义认证;会将用户信息写入到 ...

  8. django之auth认证系统

    Django自带的用户认证 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能,这还真是个麻烦的事情呢. Djang ...

  9. laravel中的Auth认证:

    简介 Laravel 5.3 的 Auth 认证在 5.2 的基础上又有一些改变,本文说明如何在 Laravel 5.3 下做不同用户表的登录认证. Auth 认证原理简述 Laravel 的认证是使 ...

随机推荐

  1. 【python游戏编程之旅】第九篇---嗷大喵快跑小游戏开发实例

    本系列博客介绍以python+pygame库进行小游戏的开发.有写的不对之处还望各位海涵. 前几期博客我们一起学习了,pygame中的冲突检测技术以及一些常用的数据结构. 这次我们来一起做一个简单的酷 ...

  2. X240s安装Win7 以及如何启用ExpressCache

    新买了一台X240S笔记本,尝试了带的Win8正版一个月后,实在无法适应Win8,干脆退回Win7完事,以下为安装过程, 第一步:制作启动U盘 首先,下载一个iso格式的Win7安装镜像文件,利用微软 ...

  3. [Codevs 1421]秋静叶&秋穣子(最大-最小博弈)

    题目:http://codevs.cn/problem/1421/ 分析:有向树上的最大-最小博弈 先手与后手的策略不同: 先手A:让对方取得尽量少的前提下,自己取得尽量大 后手B:让自己取得尽量多的 ...

  4. JavaScript学习笔记- 正则表达式常用字符集及方法

    正则表达式修饰符(修饰符 可以在全局搜索中不区分大小写) i(ignoreCase)执行对大小写不敏感的匹配 g (global)     执行全局匹配(查找所有匹配而非在找到第一个匹配后停止) m( ...

  5. Hibernate原生SQL映射MySQL的CHAR(n)类型到String时出错

    今天在用Hibernate通过原生SQL和ResultTransformer映射时,出现数据类型不匹配的错误.但是通过Entity映射,没有问题.在网上找了好多答案,终于解决了. 核心代码: Stri ...

  6. SpringMVC学习--springmvc和mybatis整合

    简介 springMVC是表现层,service充当业务层,mybatis作为持久层,通过spring将这三层整合起来.如下图: 第一步:整合dao层 mybatis和spring整合,通过sprin ...

  7. Android无线调试及手机设备与PC同屏工具——Chrome插件Vysor

    我们平时用手机调试时,经常是手不离机,以前可以下载个jar包能把手机屏映射到电脑桌面,但是运行比较卡,后来就放弃了,再之,手机接数据线有时也不太方便 ,pc与手机(连wifi)如处同一网段,就可以通过 ...

  8. Java设计模式(五) 工厂模式

    1,定义抽象产品类 package com.pattern.factory; import java.util.ArrayList; public abstract class Pizza { Str ...

  9. 神经网络dropout

    训练集上面,加一个bool型的开关 做预测的时候,不需要打开开关,而是所有的数乘以p, 实际工业界做的时候是: 在训练的时候都除以p,在做预测的时候什么时候都不用干

  10. 初探psutil

    系统性能信息模块psutil 1,psutil简介 psutil是一个跨平台能够轻松获取系统的进程和系统利用率,主要应用在系统监控,分析和限制系统资源以及进程管理.它实现了很多系统管理的命令,如ps, ...