2013-05-23 5 views
4

SAML2 토큰을 생성하기 위해 OpenSAML 라이브러리를 사용하고 있습니다. 나는 토큰의 유효성 확인 서명이 분명히 그 유효하지 않은 만료를 확인한다는 인상을 받고있었습니다. 만료 여부를 확인할 때 사용할 수있는 라이브러리가 제공하는 API가 있습니까? 다음 코드에서 checkIfExpired()처럼 :OpenSAML 라이브러리에 SAML2 토큰 만료를 확인하는 API가 있습니까?

public static boolean validateSignature(String token, Credential credential) 
    { 
     try { 

     InputStream in = new ByteArrayInputStream(token.getBytes()); 
     Document inCommonMDDoc = ppMgr.parse(in); 
     AssertionUnmarshaller unmarshaller = new AssertionUnmarshaller(); 
     Assertion assertion = (Assertion) unmarshaller 
       .unmarshall(inCommonMDDoc.getDocumentElement()); 
     SignatureValidator validator = new SignatureValidator(credential); 
     try { 
      validator.validate(assertion.getSignature()); 

      return checkIfExpired(assertion) ; // -- Checks if assertion has expired and return true/false 

     } catch (ValidationException e) { 
      log.error("Invalid Signature", e); 
      return false; 
     } 
    } catch (Exception e) { 
     log.error("Unable to perform Signature Validation", e); 

    } 
} 

참고 : 나는 OpenSAML 이미에 대한 API가있는 경우 수동으로 그 일을 피하려고.

답변

4

어설 션이 만료되었는지 확인하는 방법은 어설 션의 조건을 확인하는 것입니다. 이 같은.

if (assertion.getConditions().getNotBefore() != null && assertion.getConditions().getNotBefore().isAfterNow()) { 
    throw new ValidationException("Condition states that assertion is not yet valid (is the server time correct?)"); 
} 

if (assertion.getConditions().getNotOnOrAfter() != null 
       && (assertion.getConditions().getNotOnOrAfter().isBeforeNow() || assertion.getConditions().getNotOnOrAfter().isEqualNow())) { 
    throw new ValidationException("Condition states that assertion is no longer valid (is the server time correct?)"); 
} 

지금까지 나는 이것을 수행하는 더 간단한 방법이 없습니다. 올바른 방법은 유효성 검사기를 작성하는 것일 수도 있고, ConditionsSpecValidator를 확장 할 수도 있습니다. 이 검사기는 모든 조건을 검사하지 않습니다.

+0

감사합니다. 스테판. 유용합니다. 공통된 사용 사례이기 때문에 표준 API에 포함 시키길 바랍니다. – nadirsaghar

+0

예, 내가 말했듯이 ConditionsSpecValidator가 있지만 불완전한 것처럼 보입니다. 나는 그들에게 메일 링리스트에 메일을 보내고 그들이 말하는 것을 보게 될 것이다. 매우 중요하지 않은 유효성 검사기를 출시하는 것이 이상하게 보입니다. –

+1

저는 dev 팀과 연락을했고 이후 릴리스에서 유효성 검사기를 모두 제거했습니다. 여기 메일 스레드입니다 http://marc.info/?t=137354098500007&r=1&w=2 –