스택된 JAAS 로그인 모듈을 사용하여 UsernameToken 이용자의 인증 방법 대체

기본적으로 웹 서비스 보안 UsernameToken 이용자, UNTConsumeLoginModule은 항상 WebSphere 레지스트리에서 토큰에 포함된 사용자 이름 및 비밀번호의 유효성을 검증합니다. 이 인증 방법을 우회하도록 GenericSecurityTokenFactory에서 제공하는 SPI를 사용할 수 있습니다.

이 태스크 정보

UNTConsumeLoginModule이 사용하는 인증 방법을 대체하려면 인증을 수행하도록 고유한 사용자 정의 JAAS 로그인 모듈을 제공해야 합니다. 사용자 정의 로그인 모듈은 사용자 정의 JAAS 구성의 UNTConsumeLoginModule 아래 스택됩니다. UNTConsumeLoginModule은 토큰 XML을 이용하고 유효성을 검증합니다. 사용자 이름 및 비밀번호에 제공된 값의 유효성 검증은 사용자 정의 스택된 로그인 모듈에 따릅니다.

UNTConsumeLoginModule을 사용하면 사용자 이름 및 비밀번호를 인증한다는 가정을 수반하므로, 동적 토큰 기능의 제공만 의도하는 로그인 모듈보다 이 기능을 수행하려는 스택된 로그인 모듈에 더 많은 요구사항이 부과됩니다.

사용자 이름 및 비밀번호를 인증할 수 없음을 UNTConsumeLoginModule에 표시하려면 구성된 콜백 핸들러에서 다음 특성을 설정해야 합니다.

com.ibm.wsspi.wssecurity.token.UsernameToken.authDeferred=true

대부분의 WS-Security 로그인 모듈과 마찬가지로, UNTConsumeLoginModule은 공유 상태 맵의 이용자 토큰을 항상 스택의 모든 로그인 모듈에서 액세스하도록 합니다. authDeferred=true를 지정한 경우 커미트 단계에서 UNTConsumeLoginModule은 원래 공유 상태로 설정된 동일한 UsernameToken 오브젝트를 다른 위치에서 공유 상태로 설정하도록 보장합니다. 이 UsernameToken 오브젝트를 찾을 수 없으면 LoginException이 발생합니다. 따라서 동반되는 로그인 모듈이 토큰을 공유 상태로 되돌리지 않고는 콜백 핸들러에서 authDeferred=true만 설정할 수 없습니다.

프로시저

  1. JAAS 로그인 모듈을 개발하여 인증을 수행하고 애플리케이션 코드에서 사용 가능하도록 설정하십시오. 이 새 로그인 모듈은 com.ibm.ws.wssecurity.wssapi.token.impl.UNTConsumeLoginModule 아래 스택됩니다.

    이 로그인 모듈은 다음을 만족해야 합니다.

    1. 다음 메소드를 사용하여 UNTConsumeLoginModule에서 이용하는 UsernameToken을 가져오십시오.
      UsernameToken unt = (UsernameToken)factory.getConsumerTokenFromSharedState(sharedState,UsernameToken.ValueType);
      이 코드 예제에서 팩토리는 com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory의 인스턴스입니다.
    2. 사용자가 선택한 방식으로 사용자 이름 및 비밀번호를 확인하십시오.

      unt.getUsername() 및 unt.getPassword()를 호출하여 사용자 이름 및 비밀번호를 가져올 수 있습니다.

      인증 오류가 있는 경우 로그인 모듈에서 LoginException이 발생되어야 합니다.

    3. 이전 하위 단계에서 가져온 UsernameToken을 다시 공유 상태로 설정하십시오.

      다음 메소드를 사용하여 UsernameToken을 다시 공유 상태로 설정합니다.

      factory.putAuthenticatedTokenToSharedState(sharedState, unt);

    다음은 로그인 모듈의 예제입니다.

    package test.tokens;
    
    import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
    import com.ibm.websphere.wssecurity.wssapi.WSSUtilFactory;
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.security.auth.Subject;
    import javax.security.auth.callback.CallbackHandler;
    import javax.security.auth.login.LoginException;
    import javax.security.auth.spi.LoginModule;
    import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
    
    import java.util.ArrayList;
    
    import com.ibm.wsspi.security.registry.RegistryHelper;
    import com.ibm.websphere.security.UserRegistry;
    
    public class MyUntAuthenticator implements LoginModule {
    
      private Map _sharedState;
      private Map _options;
      private CallbackHandler _handler;
    
      public void initialize(Subject subject, CallbackHandler callbackHandler,
                             Map<String, ?> sharedState, Map<String, ?> options) {
    
        this._handler = callbackHandler;
        this._sharedState = sharedState;
        this._options = options;  
      }
    
      public boolean login() throws LoginException {
        //For the sake of readability, this login module does not
        //protect against all NPE's
    
        GenericSecurityTokenFactory factory = null;
        WSSUtilFactory utilFactory = null;
        try {
          factory = GenericSecurityTokenFactory.getInstance();
          utilFactory = WSSUtilFactory.getInstance();
        } catch (Exception e) {
          throw new LoginException(e.toString());
        }
        if (factory == null) {
          throw new LoginException("GenericSecurityTokenFactory.getInstance() returned null");
        }
    
        UsernameToken unt = (UsernameToken)factory.getConsumerTokenFromSharedState(this._sharedState,UsernameToken.ValueType);
    
        String username = unt.getUsername();
        char [] password = unt.getPassword();
    
        //authenticate the username and password
        //to validate a PasswordDigest password 
        //String pw = yourCodeToLookUpPasswordForUsername(username);
        //boolean match = utilFactory.verifyDigestedPassword(unt, pw.toCharArray());
        //if (!match) throw new LoginException("Digested passwords do not match");
        //Example:
        try {
          simpleUserGroupCheck(username, password, "cn=group1,o=ibm,c=us");
        } catch (Exception e) {
          LoginException le = new LoginException(e.getMessage());
          le.initCause(e);
          throw le;
        }
    
        //Put the authenticated token to the shared state
        factory.putAuthenticatedTokenToSharedState(this._sharedState, unt);
    
        return true;
      }
    
      private boolean simpleUserGroupCheck(String username, char [] password, String group) throws Exception {
        String allowedGroup = null;
    
        //get the default user registry
        UserRegistry user_reg = RegistryHelper.getUserRegistry(null);
    
        //authenticate the user against the user registry
        user_reg.checkPassword(username, new String(password));
    
        //get the list of groups that the user belongs to
        java.util.List<String> groupList = user_reg.getGroupsForUser(username);
    
        //you can either use a hard-coded group
        allowedGroup = group;
    
        //or get the value from your own custom property on the callback handler
        //WSSUtilFactory util = WSSUtilFactory.getInstance();
        //Map map = util.getCallbackHandlerProperties(this._handler);
        //allowedGroup = (String) map.get("MY_ALLOWED_GROUP_1");
    
        //check if the user belongs to an allowed group
        if (!groupList.contains(allowedGroup)) {
          throw new LoginException("user ["+username+"] is not in allowed group ["+allowedGroup+"]");
        }
        return true;
    }
      //implement the rest of the methods required by the
      //LoginModule interface
    }
  2. 새 JAAS 로그인 구성을 작성하십시오.
    1. 관리 콘솔에서 보안 > 글로벌 보안을 선택하십시오.
    2. 인증에서 JAAS(Java Authentication and Authorization Service)를 선택하십시오.
    3. 시스템 로그인을 선택하십시오.
    4. 새로 작성을 클릭하고 Alias = test.consume.unt를 지정하십시오.
    5. 새로 작성을 클릭한 다음 Module class name = com.ibm.ws.wssecurity.wssapi.token.impl.UNTConsumeLoginModule을 선택하십시오.
    6. 새로 작성을 클릭하고 Module class name = test.tokens.MyUntAuthenticator를 지정하십시오.
    7. 로그인 모듈 프록시 사용을 선택하십시오.
    8. 적용, 저장을 차례로 클릭하십시오.
  3. 새 JAAS 구성을 사용하도록 UsernameToken 토큰 이용자를 구성하십시오.
    1. 변경하려는 바인딩 구성을 여십시오.

      관리 콘솔에서 WS-Security > 인증 및 보호를 선택하십시오.

    2. 인증 토큰에서 변경하려는 UsernameToken 인바운드 토큰을 선택하십시오.
    3. JAAS login = test.consume.unt를 선택하십시오.
  4. UsernameToken 이용자에 대해 구성된 필수 특성을 콜백 핸들러에서 설정하십시오.
    1. 콜백 핸들러를 클릭하십시오.
    2. com.ibm.wsspi.wssecurity.token.UsernameToken.authDeferred=true 사용자 정의 특성을 추가하십시오.
    3. 확인을 클릭하십시오.
  5. 저장을 클릭하십시오.
  6. 애플리케이션 서버를 다시 시작하여 JAAS 구성 변경사항을 적용하십시오.
  7. 서비스를 테스트하십시오.

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



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