인증 데이터를 얻기 위해 프로그래밍 방식 로그인 개발

JAAS(Java Authentication and Authorization Service) 로그인 프레임워크를 사용하여 애플리케이션으로부터 인증 데이터를 얻을 수 있습니다.

이 태스크 정보

애플리케이션은 DefaultPrincipalMapping JAAS 컨텍스트 항목 이름으로 JAAS 프로그래밍 방식 로그인을 수행하여 authData 요소에 대해 구성된 사용자 이름 및 비밀번호가 포함된 개인용 신임 정보 세트에서 javax.resource.spi.security.PasswordCredential 인스턴스를 가진 주제 오브젝트를 얻을 수 있습니다.

프로시저

  1. server.xml 파일에서 appSecurity-2.0, passwordUtilities-1.0jca-1.7 기능을 추가하십시오. appSecurity-2.0, passwordUtilities-1.0jca-1.6도 추가할 수 있습니다. 예를 들어 다음과 같습니다.
    <featureManager>
       <feature>appSecurity-2.0</feature>
       <feature>passwordUtilities-1.0</feature>
       <feature>jca-1.7</feature>
    </featureManager>
  2. server.xml 파일에서 authData 요소를 구성하십시오. 예를 들어 다음과 같습니다.
    <authData id="myAuthData" user="myUser" password="myPassword"/> <!-- password can also be encoded -->
    
    Encode the password within the configuration. You can get the encoded value by using the securityUtility encode command.
  3. 애플리케이션 서블릿 또는 엔터프라이즈 Bean에서 DefaultPrincipalMapping JAAS 로그인 컨텍스트 항목 이름으로 프로그래밍 방식 로그인을 수행하여 맵핑 별명을 필요한 항목으로 바꾸십시오. 예를 들어 다음과 같습니다.
    HashMap map = new HashMap();
    map.put(com.ibm.wsspi.security.auth.callback.Constants.MAPPING_ALIAS, "myAuthData"); // Replace value with your alias.
    CallbackHandler callbackHandler = new com.ibm.wsspi.security.auth.callback.WSMappingCallbackHandler(map, null);
    LoginContext loginContext = new LoginContext("DefaultPrincipalMapping", callbackHandler);
    loginContext.login();
    Subject subject = loginContext.getSubject();
    Set<javax.resource.spi.security.PasswordCredential> creds = subject.getPrivateCredentials(javax.resource.spi.security.PasswordCredential.class);
    PasswordCredential passwordCredential = creds.iterator().next();
    참고: 단순화하기 위해 오류 처리는 표시되지 않습니다. 요청된 인증 별명이 없거나 형식이 잘못된 경우 javax.security.auth.login.LoginException이 리턴됩니다.
  4. PasswordCredential로부터 사용자 이름 및 비밀번호를 얻으십시오. 예를 들어 다음과 같습니다.
    String userName = passwordCredential.getUserName();
    char[] password = passwordCredential.getPassword();
    // Do something with the userName and password.
  5. Java 2 보안이 사용으로 설정된 경우에는 애플리케이션에 javax.security.auth.PrivateCredentialPermission을 부여해야 합니다. 예를 들어, 애플리케이션의 META-INF/permissions.xml 파일에서 PasswordCredential 오브젝트에 액세스할 수 있는 권한을 부여하십시오.
    <?xml version="1.0" encoding="UTF-8"?>
    <permissions xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/permissions_7.xsd" version="7">
    
      <permission>
        <class-name>javax.security.auth.PrivateCredentialPermission</class-name>
        <name>javax.resource.spi.security.PasswordCredential * "*"</name>
        <actions>read</actions>
      </permission>
    
      <!-- Other permissions -->
    
    </permissions>

    Java 2 보안에 대한 자세한 정보는 Liberty: Java 2 보안을 참조하십시오.


주제의 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: Tuesday, 6 December 2016
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twlp_dev_prog_login_auth_data
파일 이름: twlp_dev_prog_login_auth_data.html