示例#1
0
  @Test
  public void verifyPasswordAsAuthenticationAttributeCanDecrypt() throws Exception {
    final Map<?, ?> attributes = renderView();
    assertTrue(attributes.containsKey(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL_CREDENTIAL));

    final String encodedPsw =
        (String) attributes.get(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL_CREDENTIAL);
    final String password = decryptCredential(encodedPsw);
    final UsernamePasswordCredential creds =
        org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
    assertEquals(password, creds.getPassword());
  }
  @Override
  public Principal resolve(Credential credential) {

    UsernamePasswordCredential usernamePasswordCredential = (UsernamePasswordCredential) credential;

    String username = usernamePasswordCredential.getUsername();

    String[] args = {username, username, username};

    List result = jdbcTemplate.queryForList(SQL, args);

    SSOPrincipal principal = new SSOPrincipal();

    for (Object obj : result) {
      Map map = (Map) obj;
      principal.setId((String) map.get("userId"));
      principal.setAttributes(map);
    }

    return principal;
  }