搜索

认证Java

Aug 30, 2024 pm 03:58 PM
java

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.jsp

User name:

输出:

认证Java

输出

认证Java

说明:

  • 在这里,您可以看到单个用户名中的单用户身份验证。
  • “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.jsp

User:
Teachrs portal

输出:

认证Java

输出:

认证Java

说明:

  • 在这里,您可以在一个用户名中看到两个身份验证。
  • “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

User:
Teachers portal
Principle portal

输出:

认证Java

输出:

认证Java

说明:

  • 在这里,您可以看到单个用户名中的多个身份验证。
  • “Ram”通过 Java 身份验证访问教师、学生和管理门户。
  • 您将获得多个真实用户的单一表格。

结论

Java中的身份验证提供了数据和权限的安全性、安全性和隐私性。身份验证用于访问相应用户和权限的数据库的一部分。它变得简单、有吸引力、用户友好且优雅的网站和 Web 应用程序。该函数根据用户的身份对文档进行排序,并仅返回所需的数据。它有助于轻松获取复杂的信息,同时又不会侵犯他人的隐私。

以上是认证Java的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Java平台独立性:与不同的操作系统的兼容性Java平台独立性:与不同的操作系统的兼容性May 13, 2025 am 12:11 AM

JavaachievesPlatFormIndependencethroughTheJavavIrtualMachine(JVM),允许Codetorunondifferentoperatingsystemsswithoutmodification.thejvmcompilesjavacodeintoplatform-interploplatform-interpectentbybyteentbytybyteentbybytecode,whatittheninternterninterpretsandectectececutesoneonthepecificos,atrafficteyos,Afferctinginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginging

什么功能使Java仍然强大什么功能使Java仍然强大May 13, 2025 am 12:05 AM

JavaispoperfulduetoitsplatFormitiondence,对象与偏见,RichstandardLibrary,PerformanceCapabilities和StrongsecurityFeatures.1)Platform-dimplighandependectionceallowsenceallowsenceallowsenceallowsencationSapplicationStornanyDevicesupportingJava.2)

顶级Java功能:开发人员的综合指南顶级Java功能:开发人员的综合指南May 13, 2025 am 12:04 AM

Java的顶级功能包括:1)面向对象编程,支持多态性,提升代码的灵活性和可维护性;2)异常处理机制,通过try-catch-finally块提高代码的鲁棒性;3)垃圾回收,简化内存管理;4)泛型,增强类型安全性;5)ambda表达式和函数式编程,使代码更简洁和表达性强;6)丰富的标准库,提供优化过的数据结构和算法。

Java真的平台独立吗? '写一次,在任何地方运行”如何起作用Java真的平台独立吗? '写一次,在任何地方运行”如何起作用May 13, 2025 am 12:03 AM

javaisnotirelyPlatemententduetojvmvariationsandnativecodinteintration,butitlargelyupholdsitsitsworapromise.1)javacompilestobytecoderunbythejvm

揭示JVM:您了解Java执行的关键揭示JVM:您了解Java执行的关键May 13, 2025 am 12:02 AM

thejavavirtualmachine(JVM)IsanabtractComputingmachinecrucialforjavaexecutionasitrunsjavabytecode,使“ writeononce,runanywhere”能力

Java仍然是基于新功能的好语言吗?Java仍然是基于新功能的好语言吗?May 12, 2025 am 12:12 AM

Javaremainsagoodlanguageduetoitscontinuousevolutionandrobustecosystem.1)Lambdaexpressionsenhancecodereadabilityandenablefunctionalprogramming.2)Streamsallowforefficientdataprocessing,particularlywithlargedatasets.3)ThemodularsystemintroducedinJava9im

是什么使Java很棒?关键特征和好处是什么使Java很棒?关键特征和好处May 12, 2025 am 12:11 AM

Javaisgreatduetoitsplatformindependence,robustOOPsupport,extensivelibraries,andstrongcommunity.1)PlatformindependenceviaJVMallowscodetorunonvariousplatforms.2)OOPfeatureslikeencapsulation,inheritance,andpolymorphismenablemodularandscalablecode.3)Rich

前5个Java功能:示例和解释前5个Java功能:示例和解释May 12, 2025 am 12:09 AM

Java的五大特色是多态性、Lambda表达式、StreamsAPI、泛型和异常处理。1.多态性让不同类的对象可以作为共同基类的对象使用。2.Lambda表达式使代码更简洁,特别适合处理集合和流。3.StreamsAPI高效处理大数据集,支持声明式操作。4.泛型提供类型安全和重用性,编译时捕获类型错误。5.异常处理帮助优雅处理错误,编写可靠软件。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

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

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器