Authentication java 是 Web 应用程序身份确认的安全术语。它是使用编程语言确认网站和网络应用程序的用户身份的功能。它确认用户的使用并允许他们使用 Java 技术访问网站、应用程序和软件相关产品。它是一种安全方法,用于使用 Java 语言的安全条款来识别授权用户并授予使用应用程序的权限。
开始您的免费软件开发课程
网络开发、编程语言、软件测试及其他
它是一个客户端和服务器端功能,使用唯一的内容并通过安全密码和用户身份进行确认。它在客户端使用用户id和密码,并使用Java编程语言以真实身份访问服务器端数据。这是一个保持 Web 应用程序安全并仅使用可访问的团队成员的文档流程。
语法
此语法用于验证用户的特定分支,例如学生、教师、非教学人员和校长。您可以使用用户名、电子邮件地址和密码登录并确认身份。
在此语法中,应用程序使用用户名和密码进行身份验证。
public class AppSecurityConfig extends AppSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder authentic) throws Exception { UserBuilder userid = User.withDefaultPasswordEncoder(); authentic.inMemoryAuthentication() .withUser(usersid.username("merry").password("test@123").roles("student")) } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/").hasRole("student") .and() .formLogin() .loginPage("/useLoginPage") .loginProcessingUrl("/authenticatationUser") .permitAll() .and() .logout().permitAll(); } }
Java 中的身份验证如何工作?
使用具有安全性和登录表单的网络应用程序。此表单重定向到 JSP 页面。
<form action="%24%7BpageContext.request.contextPath%7D/authenticateUser" method="POST"> <if test="${param.error ! = null}"> <b class="failed"> username/password does not authenticate here… </b> </if> <p> User ID: <input type="text" name="name"> </p> <p> Password: <input type="password" name="pswrd"> </p> <input type="submit" value="Submit"> </form>
使用网络应用程序对登录表单进行身份验证。此表单重定向到 JSP 页面。
<p> User: <authentication property="principal.username"></authentication> </p>
使用 java spring 框架使用 Java 身份验证语法。 Java使用Spring security来进行权限认证。
public class AppSecurityConfig extends AppSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder authentic) throws Exception { UserBuilder userid = User.withDefaultPasswordEncoder(); authentic.inMemoryAuthentication() .withUser (usersid.username ("merry") .password ("test@123") .roles ("student")) } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/") .hasRole("student") .and() .formLogin() .loginPage("/useLoginPage") .loginProcessingUrl("/authenticatationUser") .permitAll() .and() .logout().permitAll(); } }
Java 身份验证示例
以下是示例:
示例#1
基本示例如下所示。
代码:
文件:authenticationApp.java
public class authenticationApp extends AppSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder authentic) throws Exception { UserBuilder userid = User.withDefaultPasswordEncoder(); authentic.inMemoryAuthentication() .withUser (usersid.username ("sunny") .password ("school@123") .roles ("student")) } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/") .hasRole("student") .and() .formLogin() .loginPage("/useLoginPage") .loginProcessingUrl("/authenticatationUser") .permitAll() .and() .logout().permitAll(); } }
文件:main_login.jsp
<form action="%24%7BpageContext.request.contextPath%7D/authenticateUser" method="POST"> <if test="${param.error ! = null}"> <b class="failed"> username/password does not authenticate here… </b> </if> <p> User ID: <input type="text" name="name"> </p> <p> Password: <input type="password" name="pswrd"> </p> <input type="submit" value="Submit"> </form> File: authentication.jspUser name:
输出:
输出
说明:
- 在这里,您可以看到单个用户名中的单用户身份验证。
- “Sunny”仅通过 Java 身份验证访问学生门户。
- 您将获得单个真实用户的单一表格。
示例#2
Java 示例中的两个身份验证和输出如下所示。
代码:
文件:authenticationApp.java
public class authenticationApp extends AppSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder authentic) throws Exception { UserBuilder userid = User.withDefaultPasswordEncoder(); authentic.inMemoryAuthentication() .withUser (usersid.username ("merry") .password ("test@123") .roles ("student")) .withUser(users.username("sam") .password("exam@123") .roles("student", "teacher")) } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/").hasRole("student") .antMatchers("/teachers/**").hasRole("teacher") .and() .formLogin() .loginPage("/useLoginPage") .loginProcessingUrl("/authenticatationUser") .permitAll() .and() .logout().permitAll(); } }
文件:main_login.jsp
<form action="%24%7BpageContext.request.contextPath%7D/authenticateUser" method="POST"> <if test="${param.error ! = null}"> <b class="failed"> username/password does not authenticate here… </b> </if> <p> User ID: <input type="text" name="name"> </p> <p> Password: <input type="password" name="pswrd"> </p> <input type="submit" value="Submit"> </form> File: authentication.jspUser:
Teachrs portal
输出:
输出:
说明:
- 在这里,您可以在一个用户名中看到两个身份验证。
- “sam”通过 Java 身份验证访问教师和学生门户。
- 您将获得多个真实用户的单一表格。
示例 #3
Java 示例中的多重身份验证和输出如下所示。
代码:
文件:authenticationApp.java
public class authenticationApp extends AppSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder authentic) throws Exception { UserBuilder userid = User.withDefaultPasswordEncoder(); authentic.inMemoryAuthentication() .withUser (usersid.username ("merry") .password ("test@123") .roles ("student")) .withUser(users.username("sam") .password("exam@123") .roles("student", "teacher")) .withUser(users.username("Ram") .password("admin@123") .roles("student", "teacher", "principle")) } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/") .hasRole("student") .antMatchers("/teachers/**").hasRole("teacher") .antMatchers("/principles/**").hasRole("principle") .and() .formLogin() .loginPage("/useLoginPage") .loginProcessingUrl("/authenticatationUser") .permitAll() .and() .logout().permitAll(); } }
文件:main_login.jsp
<form action="%24%7BpageContext.request.contextPath%7D/authenticateUser" method="POST"> <if test="${param.error ! = null}"> <b class="failed"> username/password does not authenticate here… </b> </if> <p> User ID: <input type="text" name="name"> </p> <p> Password: <input type="password" name="pswrd"> </p> <input type="submit" value="Submit"> </form> File: authentication.jsp
输出:
输出:
说明:
- 在这里,您可以看到单个用户名中的多个身份验证。
- “Ram”通过 Java 身份验证访问教师、学生和管理门户。
- 您将获得多个真实用户的单一表格。
结论
Java中的身份验证提供了数据和权限的安全性、安全性和隐私性。身份验证用于访问相应用户和权限的数据库的一部分。它变得简单、有吸引力、用户友好且优雅的网站和 Web 应用程序。该函数根据用户的身份对文档进行排序,并仅返回所需的数据。它有助于轻松获取复杂的信息,同时又不会侵犯他人的隐私。
以上是认证Java的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

Dreamweaver Mac版
视觉化网页开发工具

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。