認証Java

PHPz
リリース: 2024-08-30 15:58:38
オリジナル
402 人が閲覧しました

認証 Java は、Web アプリケーションの本人確認に対するセキュリティの用語です。プログラミング言語を使用してWebサイト・Webアプリケーションの本人確認を行う機能です。ユーザーの使用を確認し、Java テクノロジーを使用した Web サイト、アプリケーション、ソフトウェア関連製品へのアクセスを許可します。 Java言語のセキュリティ規約を利用して、許可されたユーザーを特定し、アプリケーションの使用を許可するセキュリティ方式です。

無料ソフトウェア開発コースを始めましょう

Web 開発、プログラミング言語、ソフトウェア テスト、その他

これは、独自のコンテンツを使用し、セキュリティ パスワードとユーザー ID で確認するためのクライアントおよびサーバー側の機能です。クライアント側でユーザー ID とパスワードを使用し、Java プログラミング言語を使用して真の識別情報を使用してサーバー側データにアクセスします。これは、Web アプリケーションを安全に保ち、アクセス可能なチーム メンバーのみを使用するための文書化プロセスです。

構文

この構文は、生徒、教師、非教職員、校長など、ユーザーの特定のブランチを認証するために使用されます。ユーザー名、電子メール ID、パスワードを使用してログインし、本人確認を行うことができます。

この構文では、アプリケーションは認証にユーザー名とパスワードを使用します。

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 では認証はどのように機能しますか?

セキュリティとログインフォームを備えた Web アプリケーションを使用します。このフォームは JSP ページにリダイレクトされます。

<form:form action="${pageContext.request.contextPath}/authenticateUser"
Method = "POST">
<c:if test = "${param.error ! = null}">
<b class="failed"> username/password does not authenticate here… </b>
</c:if>
<p>
User ID: <input type = "text" name = "name" />
</p>
<p>
Password: <input type = "password" name = "pswrd" />
</p>
<input type = "submit" value = "Submit" />
</form:form>
ログイン後にコピー

ログインフォームの認証にはWebアプリケーションを使用します。このフォームは JSP ページにリダイレクトされます。

<p>
User: <security:authentication property = "principal.username" />
</p>
ログイン後にコピー

Java Spring フレームワークを使用して Java 認証構文を使用します。 Java は Spring セキュリティを使用して権限を認証します。

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:form action="${pageContext.request.contextPath}/authenticateUser"
Method = "POST">
<c:if test = "${param.error ! = null}">
<b class="failed"> username/password does not authenticate here… </b>
</c:if>
<p>
User ID: <input type = "text" name = "name" />
</p>
<p>
Password: <input type = "password" name = "pswrd" />
</p>
<input type = "submit" value = "Submit" />
</form:form>
File: authentication.jsp

User name:

ログイン後にコピー

出力:

認証Java

出力

認証Java

説明:

  • ここでは、単一のユーザー名での単一ユーザー認証が表示されます。
  • 「Sunny」は Java 認証を使用して学生ポータルにのみアクセスします。
  • 単一の正規ユーザーに対して単一のフォームを取得します。

例 #2

Java の例と出力における 2 つの認証を以下に示します。

コード:

ファイル: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:form action="${pageContext.request.contextPath}/authenticateUser"
Method = "POST">
<c:if test = "${param.error ! = null}">
<b class="failed"> username/password does not authenticate here… </b>
</c:if>
<p>
User ID: <input type = "text" name = "name" />
</p>
<p>
Password: <input type = "password" name = "pswrd" />
</p>
<input type = "submit" value = "Submit" />
</form:form>
File: authentication.jsp

User:
Teachrs portal

ログイン後にコピー

出力:

認証Java

出力:

認証Java

説明:

  • ここでは、1 つのユーザー名に 2 つの認証が表示されています。
  • 「サム」は Java 認証を使用して教師と生徒のポータルにアクセスします。
  • 複数の認証ユーザーに対して 1 つのフォームを取得できます。

例 #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:form action="${pageContext.request.contextPath}/authenticateUser"
Method = "POST">
<c:if test = "${param.error ! = null}">
<b class="failed"> username/password does not authenticate here… </b>
</c:if>
<p>
User ID: <input type = "text" name = "name" />
</p>
<p>
Password: <input type = "password" name = "pswrd" />
</p>
<input type = "submit" value = "Submit" />
</form:form>
File: authentication.jsp

User:
Teachers portal
Principle portal

ログイン後にコピー

出力:

認証Java

出力:

認証Java

説明:

  • ここでは、単一のユーザー名に複数の認証が表示されています。
  • 「Ram」は、Java 認証を使用して教師、生徒、管理者のポータルにアクセスします。
  • 複数の認証ユーザーに対して 1 つのフォームを取得できます。

結論

Java の認証は、データと権限のセキュリティ、安全性、プライバシーを提供します。認証は、各ユーザーおよび権限がデータベースの一部にアクセスするために使用します。簡単、魅力的、ユーザーフレンドリー、エレガントな Web サイトと Web アプリケーションになります。この関数は、ユーザーの ID ごとにドキュメントを並べ替え、必要なデータのみを返します。他人のプライバシーを侵害することなく、複雑な情報を簡単に入手するのに役立ちます。

以上が認証Javaの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!