mysql - JSF+Hibernate在没有spring的情况下设置admin页面权限
问题描述
嘿大家
我正在尝试为管理员和普通用户构建一个基于 JSF+Hibernate 的产品管理系统。我正在尝试为管理员设置一些权限。我在我的 sql 中有一个用于用户类型的列并自动设置它们。我不允许使用任何弹簧属性,它必须只是 jsf 和休眠。有没有办法在没有弹簧安全的情况下设置 xhtml 页面可访问/不可访问?我有一个登录页面,但它只是让你进入。如果你使用手动 URL,你也可以进入。这就是我想要解决的问题。
这是我的管理员专用页面之一。我想让 usertype=admin 帐户可以访问它。
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
template="/template/site.xhtml"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:define name="content">
<main class="d-flex w-100">
<div class="container d-flex flex-column">
<div class="row vh-100">
<div class="col-sm-10 col-md-8 col-lg-6 mx-auto d-table h-100">
<div class="d-table-cell align-middle">
<div class="text-center mt-4">
<h1 class="h2">Kullanıcı Türü Kayıt Formu</h1>
<p class="lead">
Yeni yetki oluşturmak için adını ve izinlerini belirleyin.
</p>
</div>
<div class="card">
<div class="card-body">
<div class="m-sm-4">
<h:form>
<style>
.error{color:red}
</style>
<div class="form-group">
<label for="inputEmail4">Kullanıcı Türü Adı</label>
<h:inputText class="form-control" value="#{userType.type}"
id="type"
required="true"
requiredMessage="Kullanıcı türü adı boş olamaz!"
>
<f:validator validatorId="only_letter_validator"/>
</h:inputText>
<input type="checkbox" name="permission"> Kullanıcı türü değiştirme </input><br></br>
<input type="checkbox" name="permission1"> Ürün Silme ve Düzenleme </input><br></br>
<input type="checkbox" name="permission2"> Admin Paneline Ulaşabilme </input><br></br>
<input type="checkbox" name="permission3"> Yetki Türü ekleyebilme </input><br></br>
<h:message for="type" styleClass="error"/> <br></br>
</div>
<h:commandButton styleClass="btn btn-success" value="Kaydet" action="#{userTypeController.addUserType(userType)}">
</h:commandButton>
</h:form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</ui:define>
</ui:composition>
再次登录即可到达该页面。这是我的登录页面
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
template="/template/site.xhtml"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:define name="content">
<main class="d-flex w-100">
<div class="container d-flex flex-column">
<div class="row vh-100">
<div class="col-sm-10 col-md-8 col-lg-6 mx-auto d-table h-100">
<div class="d-table-cell align-middle">
<div class="text-center mt-4">
<h1 class="h2">Giriş Yap</h1>
</div>
<div class="card">
<div class="card-body">
<div class="m-sm-4">
<h:form>
<style>
.error{color:red}
</style>
<div class="form-group">
<label for="inputEmail4">Kullanıcı Adı</label>
<h:inputText class="form-control" value="#{user_bean.username}"
id="username"
required="true"
requiredMessage="Kullanıcı türü adı boş olamaz!"
>
</h:inputText>
<h:message for="username" styleClass="error"/> <br></br>
</div>
<div class="form-group">
<label for="inputEmail4">Şifre</label>
<h:inputText class="form-control" value="#{user_bean.password}"
id="password"
required="true"
requiredMessage="Kullanıcı türü adı boş olamaz!"
>
</h:inputText>
<h:message for="password" styleClass="error"/> <br></br>
</div>
<h:commandButton styleClass="btn btn-success" value="Login" action="#{userController.doLogin(user_bean)}"/>
<br></br><h:outputLabel value="#{userController.loginError}" rendered="true" style="color:red"/>
</h:form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</ui:define>
</ui:composition>
如果我能做到,他们会让我使用 Spring 框架,这对我来说就像天堂一样。如果您有任何想法,请与我分享。
解决方案
推荐阅读
- list - Flutter & Hive - 如何在 Hive 中保存重新排序的列表
- authentication - 两个 Web 应用程序之间的身份验证
- javascript - windows.scroll 在 chrome 中工作,但在 safari 中不工作
- reactjs - 上传失败时使用 dropzone-react-component 设置重试
- python - Docker:无法使用请求库请求另一个容器
- algorithm - 如何创建将两个值映射为一个的算法
- jquery - 有没有办法让 jQuery 函数在第一次加载时立即工作?
- php - Google reCaptcha 3 - 第一次失败后登录错误
- scheme - 如何得到这个函数的逆?
- r - 在 R ggplot2 中:如何将 scale_fill_manual 中的颜色分配给一个因子?