湿热喝什么茶可以调理| 经常嘴苦是什么原因| 大排畸是什么检查| 幽默什么意思| 家里为什么会有蜘蛛| 干咳吃什么药好的快| 石榴什么时候开花| 雄鹰是什么意思| 石榴花什么时候开| 唐僧代表什么生肖| 宝宝经常发烧是什么原因| 中秋节吃什么| 乳头凹陷是什么原因| 傲气是什么意思| 青牛是什么牛| 霍家为什么娶郭晶晶| 大力出奇迹什么意思| 眼睛做激光手术有什么后遗症| 原汤化原食什么意思| 生理期吃什么水果比较好| 高烧拉肚子是什么原因| 尿尿泡沫多是什么原因| 一什么尺子| 卤水点豆腐的卤水是什么| 郑中基为什么叫太子基| 经常梦遗是什么原因| 小孩睡觉流鼻血是什么原因引起的| 国防部长什么级别| 肝炎吃什么药| 感染四项挂什么科| 明天是什么日子| 男人吃什么补肾壮阳效果最好| 气短咳嗽是什么原因引起的| 尿酸高适合吃什么菜| 女人吃猪肝有什么好处| 主动脉硬化什么意思| 麦冬的功效与作用是什么| 蝈蝈吃什么食物| 摩登女郎是什么意思| 泌乳是什么意思| 处女座和什么座最配| 附子理中丸治什么病| 栖字五行属什么| 运费险是什么意思| 发烧能吃什么水果| 变色龙指什么样的人| 长目飞耳是什么动物| 挖空细胞是什么意思啊| 虾不能跟什么一起吃| 裙裤配什么鞋子好看| 梦见自己掉头发是什么意思| mcm是什么意思| 胃老是恶心想吐是什么原因| 冰丝是什么材料| 胃糜烂是什么原因引起的| 女孩叫锦什么好听| 蚜虫长什么样| 艳羡是什么意思| 什么是裙带菜| 婴儿咳嗽用什么药| 即日是什么意思| 膝盖酸疼是什么原因| 健身rm是什么意思| 死海是什么| 氨味是什么味道| 尿糖弱阳性是什么意思| 医疗行业五行属什么| 自食其力是什么意思| 脚上长疣是什么原因| 月经每次都推迟是什么原因| 代孕是什么意思| 胃寒吃什么中成药| 黑乌龙茶属于什么茶| 一九三九年属什么生肖| 腿纹不对称有什么影响| 一九三七年属什么生肖| 飒的意思是什么| 揩油什么意思| 车顶放饮料是什么意思| c4是什么| 规培结束后是什么医生| 脱敏什么意思| 哀大莫过于心死是什么意思| 什么的水流| 耄耋之年是什么意思| 结扎是什么| 结核抗体弱阳性什么意思| 小孩几天不大便是什么原因怎么办| 取关是什么意思| 3月7日什么星座| feat什么意思| 幼儿园什么时候放暑假| 女人做梦哭醒预示什么| 什么样的梦才算是胎梦| 葵瓜子吃多了有什么危害| 恩施玉露属于什么茶| 微创人流和无痛人流有什么区别| 人为什么会脱发| 六月六是什么节日| 婴儿坐飞机需要什么证件| 今天什么日子老黄历| 朕是什么时候开始用的| 今年25岁属什么生肖的| 喝酒睡不着是什么原因| 身无什么| 送女朋友什么礼物| 基点是什么意思| 言外之意什么意思| 中国最早的文字是什么| 化干戈为玉帛是什么意思| 张的五行属性是什么| 红霉素软膏治什么病| 心梗什么症状| 睡着了放屁是什么原因| 蠢是什么意思| 十月二十八是什么星座| 心脏不好吃什么水果好| 什么人| 肝血管瘤挂什么科| 减肥最好的办法是什么| 茭头是什么| 尿频是什么原因导致的| 梦见种地是什么意思| 梦见红棺材是什么征兆| 满族八大碗都有什么菜| 三周年祭奠有什么讲究| 空气是由什么组成的| 川芎有什么功效与作用| 320是什么意思| 御守是什么意思| e代表什么数字| 白带黄吃什么药| tt是什么意思| 手心脚心出汗是什么原因| 天鹅吃什么| 申的五行属什么| 翊字是什么意思| 肾虚去医院挂什么科| 查甲状腺功能挂什么科| 浅卡其色裤子配什么颜色上衣| 娃娃鱼属于什么类动物| ab制是什么意思| 三文鱼又叫什么鱼| 四川耙耳朵是什么意思| 查微量元素挂什么科| 七叶一枝花主治什么病| 巅峰是什么意思| 户籍是指什么| 胃阴不足吃什么中成药| 左肩后背疼是什么原因| 什么的瞬间作文| 咳嗽吃什么好| 印度人为什么叫阿三| 荨麻疹擦什么药膏| 医学上cr是什么意思| 脂溢性皮炎是什么原因引起的| 丙氨酸氨基转移酶是什么| pr间期缩短什么意思| lalabobo是什么牌子| 裂纹舌是什么原因引起的| 壁虎怕什么| 脾胃不好吃什么食物| 坏血症什么症状| 青春永驻是什么意思| 女性为什么会肾结石| 手腕三条纹代表什么| 左手小指和无名指发麻是什么原因| 夏天脚冷是什么原因| 上嘴唇长痘痘是什么原因| 看指甲去医院挂什么科| 1962年属什么生肖| 补气血吃什么药效果好| 心疼是什么意思| 微笑是什么意思| jeans是什么意思| 痔疮不能吃什么东西| c1是什么意思| 多囊卵巢综合征是什么意思| 咳嗽挂什么科| 谦虚的什么| 巨蟹座是什么性格| 他长什么样| 糖尿病早期什么症状| 什么虎不吃人| 推背有什么好处和坏处| 长期服用丙戊酸钠有什么副作用| 凌迟是什么意思| 碱性磷酸酶高是什么病| 眼睛痛是什么病| 清清什么| 公约是什么意思| 血压高降不下来是什么原因| 肺气不足有什么症状| 红枣为什么要去核煮| 什么叫cd| 3.19号是什么星座| 增生期子宫内膜是什么意思| 做梦拉粑粑是什么意思| 啤酒有什么牌子| osprey是什么牌子| 跑步什么时候跑最好| 喝咖啡对身体有什么好处| 什么好像什么一样| rj是什么意思| 鲁智深的绰号是什么| 车前草长什么样| 母亲节送什么颜色的康乃馨| 美仑美奂什么意思| 30年婚姻叫什么婚| 痰多吃什么药| 痔疮是什么科室看的| 尿结石不能吃什么| 子母被是什么意思| 白带异常吃什么药| 过敏性咳嗽用什么药| 疱疹是什么| 永垂不朽什么意思| 女性胃火旺吃什么药| 体态是什么意思| 乐不思蜀是什么意思| 一座什么| 什么是roi| 红霉素软膏有什么作用| 什么行什么什么| 殖民地是什么意思| 清明节吃什么好| 怀孕14天有什么症状| 易经的易是什么意思| 胃不好的人吃什么养胃| 光天化日什么意思| 喉咙老是有白痰是什么原因| 无人区是什么意思| 爸爸的弟弟叫什么| 长痱子是什么原因| 苏铁属于什么植物| 晚上睡觉盗汗是什么原因| 送老师送什么礼物好| 闭合性跌打损伤是什么意思| 女生不来大姨妈是什么原因| 肠胃炎是什么| 痔疮嵌顿是什么意思| t和p是什么意思| 湿气重吃什么药最好| 白细胞满视野是什么意思| 蒲公英是什么样子| 凤毛麟角什么意思| 沙特是什么教派| 浆果是什么| 老是感冒是什么原因| 一个山一个空念什么| 被蚂蚁咬了怎么止痒消肿要擦什么药| cl是什么元素| 598是什么意思| 镇委书记是什么级别| 2019年属什么| 肛门指检能查出什么| 肾上腺素有什么用| 11月24是什么星座| 暂告一段落是什么意思| m什么意思| nicole是什么意思| 为什么会长斑| 经常头痛是什么原因| 子欲养而亲不待是什么意思| 百度
Skip to content

四川省农村“两权”抵押贷款试点 苍溪县分享成功经验

Introduction - What is JAAS authentication

百度 刘炳江说,据了解,北京把机动车污染治理作为今年工作的重点,我认为是精准施策、靶向治霾,对此我完全赞同。

The process of verifying the identity of a user or another system is authentication.

JAAS, as an authentication framework manages the authenticated user's identity and credentials from login to logout.

The JAAS authentication lifecycle:

  1. Create LoginContext.
  2. Read the configuration file for one or more LoginModules to initialize.
  3. Call LoginContext.initialize() for each LoginModule to initialize.
  4. Call LoginContext.login() for each LoginModule.
  5. If login successful then call LoginContext.commit() else call LoginContext.abort()

Configuration file

The JAAS configuration file contains a LoginModule stanza for each LoginModule available for logging on to the application.

A stanza from a JAAS configuration file:

Branches
{
    USNavy.AppLoginModule required
    debug=true
    succeeded=true;
}

Note the placement of the semicolons, terminating both LoginModule entries and stanzas.

The word required indicates the LoginContext's login() method must be successful when logging in the user. The LoginModule-specific values debug and succeeded are passed to the LoginModule.

They are defined by the LoginModule and their usage is managed inside the LoginModule. Note, Options are Configured using key-value pairing such as debug="true" and the key and value should be separated by a = sign.

Main.java (The client)

  • Execution syntax:
Java –Djava.security.auth.login.config==packageName/packageName.config
        packageName.Main Stanza1

Where:
    packageName is the directory containing the config file.
    packageName.config specifies the config file in the Java package, packageName.
    packageName.Main specifies Main.java in the Java package, packageName.
    Stanza1 is the name of the stanza Main() should read from the config file.
  • When executed, the 1st command-line argument is the stanza from the config file. The Stanza names the LoginModule to be used. The 2nd argument is the CallbackHandler.
  • Create a new LoginContext with the arguments passed to Main.java.
    • loginContext = new LoginContext (args[0], new AppCallbackHandler());
  • Call the LoginContext.Login Module:
    • loginContext.login();
  • The value in succeeded Option is returned from loginContext.login().
  • If the login was successful, a subject was created.

LoginModule.java

A LoginModule must have the following authentication methods:

  • initialize()
  • login()
  • commit()
  • abort()
  • logout()

initialize()

In Main(), after the LoginContext reads the correct stanza from the config file, the LoginContext instantiates the LoginModule specified in the stanza.

  • initialize() methods signature:
    • Public void initialize (Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options)
  • The arguments above should be saved as follows:
    • this.subject = subject;
    • this.callbackHandler = callbackHandler;
    • this.sharedState = sharedState;
    • this.options = options;
  • What the initialize() method does:
    • Builds a subject object of the Subject class contingent on a successful login().
    • Sets the CallbackHandler which interacts with the user to gather login information.
    • If a LoginContext specifies 2 or more LoginModules, which is legal, they can share information via a sharedState map.
    • Saves state information such as debug and succeeded in an options Map.

login()

Captures user supplied login information. The code snippet below declares an array of two callback objects which, when passed to the callbackHandler.handle method in the callbackHandler.java program, will be loaded with a username and password provided interactively by the user:

NameCallback nameCB = new NameCallback("Username");
PasswordCallback passwordCB = new PasswordCallback ("Password", false);
Callback[] callbacks = new Callback[] { nameCB, passwordCB };
callbackHandler.handle (callbacks);
  • Authenticates the user
  • Retrieves the user supplied information from the callback objects:
    • String ID = nameCallback.getName ();
    • char[] tempPW = passwordCallback.getPassword ();
  • Compare name and tempPW to values stored in a repository such as LDAP.
  • Set the value of the variable succeeded and return to Main().

commit()

Once the users credentials are successfully verified during login(), the JAAS authentication framework associates the credentials, as needed, with the subject.

There are two types of credentials, Public and Private:

  • Public credentials include public keys.
  • Private credentials include passwords and public keys.

Principals (i.e. Identities the subject has other than their login name) such as employee number or membership ID in a user group are added to the subject.

Below, is an example commit() method where first, for each group the authenticated user has membership in, the group name is added as a principal to the subject. The subject's username is then added to their public credentials.

Code snippet setting then adding any principals and a public credentials to a subject:

public boolean commit() {
    If (userAuthenticated) {
        Set groups = UserService.findGroups (username);
        for (Iterator itr = groups.iterator (); itr.hasNext (); {
            String groupName = (String) itr.next ();
            UserGroupPrincipal group = new UserGroupPrincipal (GroupName);
            subject.getPrincipals ().add (group);
        }
        UsernameCredential cred = new UsernameCredential (username);
        subject.getPublicCredentials().add (cred);
    }
}

abort()

The abort() method is called when authentication doesn't succeed. Before the abort() method exits the LoginModule, care should be taken to reset state including the username and password input fields.

logout()

The release of the users principals and credentials when LoginContext.logout is called:

public boolean logout() {
    if (!subject.isReadOnly()) {
        Set?principals?=?subject.getPrincipals(UserGroupPrincipal.class);
        subject.getPrincipals().removeAll(principals);
        Set?creds?=?subject.getPublicCredentials(UsernameCredential.class);
        subject.getPublicCredentials().removeAll(creds);
        return?true;
    } else {
        return false;
    }
}

CallbackHandler.java

The callbackHandler is in a source (.java) file separate from any single LoginModule so that it can service a multitude of LoginModules with differing callback objects:

  • Creates instance of the CallbackHandler class and has only one method, handle().
  • A CallbackHandler servicing a LoginModule requiring username & password to login:
public void handle(Callback[] callbacks) {
    for (int i = 0; i < callbacks.length; i++) {
        Callback callback = callbacks[i];
        if (callback instanceof NameCallback) {
            NameCallback nameCallBack = (NameCallback) callback;
            nameCallBack.setName(username);
    }  else if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallBack = (PasswordCallback) callback;
            passwordCallBack.setPassword(password.toCharArray());
        }
    }
}

Disclosure

All of the code in the attached JAAS cheat sheet has been copied verbatim from this free source.

大姨妈量少什么原因 血脂和血糖有什么区别 头孢主要治什么病 鸟为什么会飞 头晃动是什么病的前兆
有机会是什么意思 较重闭合性跌打损伤是什么意思 ac是什么 隐翅虫擦什么药膏 10mg是什么意思
孕妇吃猕猴桃对胎儿有什么好处 花心是什么意思 什么忙什么乱 戴珍珠手链有什么好处 白带是什么
小麻雀吃什么 舌头热灼是什么原因 男人经常熬夜炖什么汤 什么食物胆固醇高 赵本山什么时候去世的
为什么男的叫鸭子hcv8jop5ns1r.cn 牙龈肿痛挂什么科hcv9jop6ns6r.cn 变化无穷是什么生肖chuanglingweilai.com 什么鸟hcv8jop7ns9r.cn 结核菌是什么hcv9jop7ns2r.cn
胎儿左肾盂分离是什么意思xianpinbao.com hcg值低是什么原因hcv8jop8ns2r.cn 吃杨梅有什么好处hcv8jop3ns7r.cn 八卦是什么生肖hcv9jop4ns6r.cn 做梦梦到蛆是什么意思hcv8jop4ns5r.cn
爽是什么结构hcv9jop1ns2r.cn 陈小春什么星座hcv7jop9ns0r.cn 什么的关系hcv9jop0ns6r.cn 2019年是什么生肖hcv8jop9ns5r.cn 条索灶是什么意思hcv7jop7ns0r.cn
胃不消化吃什么药效果最好hcv9jop1ns7r.cn 什么醒酒最快hcv7jop5ns0r.cn 晚上9点到11点是什么时辰hcv8jop2ns2r.cn 体格检查是什么意思hcv9jop7ns1r.cn 下体痒是什么原因hcv9jop2ns8r.cn
百度