org.acegisecurity.Authentication.getCredentials()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中org.acegisecurity.Authentication.getCredentials()方法的一些代码示例,展示了Authentication.getCredentials()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Authentication.getCredentials()方法的具体详情如下:
包路径:org.acegisecurity.Authentication
类名称:Authentication
方法名:getCredentials

Authentication.getCredentials介绍

[英]The credentials that prove the principal is correct. This is usually a password, but could be anything relevant to the AuthenticationManager. Callers are expected to populate the credentials.
[中]证明委托人正确的凭证。这通常是一个密码,但可能是与AuthenticationManager相关的任何内容。呼叫者需要填充凭据。

代码示例

代码示例来源:origin: jenkinsci/jenkins

Assert.notNull(successfulAuthentication.getCredentials());
Assert.isInstanceOf(UserDetails.class, successfulAuthentication.getPrincipal());

代码示例来源:origin: org.mule.modules/mule-module-acegi

public Object getCredentials()
{
  return delegate.getCredentials();
}

代码示例来源:origin: org.acegisecurity/acegi-security

/**
   * If the callback passed to the 'handle' method is an instance of PasswordCallback, the
   * JaasPasswordCallbackHandler will call, callback.setPassword(authentication.getCredentials().toString()).
   *
   * @param callback
   * @param auth
   *
   * @throws IOException
   * @throws UnsupportedCallbackException
   */
  public void handle(Callback callback, Authentication auth)
    throws IOException, UnsupportedCallbackException {
    if (callback instanceof PasswordCallback) {
      PasswordCallback pc = (PasswordCallback) callback;
      pc.setPassword(auth.getCredentials().toString().toCharArray());
    }
  }
}

代码示例来源:origin: org.springframework/spring-ldap

public String getCredentials() {
  Authentication authentication = SecurityContextHolder.getContext()
      .getAuthentication();
  if (authentication != null) {
    return (String) authentication.getCredentials();
  } else {
    log.warn("No Authentication object set in SecurityContext - "
        + "returning empty String as Credentials");
    return "";
  }
}

代码示例来源:origin: net.sf.ldaptemplate/ldaptemplate

public String getCredentials() {
  Authentication authentication = SecurityContextHolder.getContext()
      .getAuthentication();
  if (authentication != null) {
    return (String) authentication.getCredentials();
  } else {
    log.warn("No Authentication object set in SecurityContext - "
        + "returning empty String as Credentials");
    return "";
  }
}

代码示例来源:origin: org.acegisecurity/acegi-security

public Authentication authenticate(Authentication authentication)
  throws AuthenticationException {
  String username = authentication.getPrincipal().toString();
  String password = authentication.getCredentials().toString();
  GrantedAuthority[] authorities = remoteAuthenticationManager.attemptAuthentication(username, password);
  return new UsernamePasswordAuthenticationToken(username, password, authorities);
}

代码示例来源:origin: org.acegisecurity/acegi-security

protected String retrievePassword(Authentication successfulAuthentication) {
  if (isInstanceOfUserDetails(successfulAuthentication)) {
    return ((UserDetails) successfulAuthentication.getPrincipal()).getPassword();
  }
  else {
    return successfulAuthentication.getCredentials().toString();
  }
}

代码示例来源:origin: org.acegisecurity/acegi-security

if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null)) {
  String base64 = auth.getName() + ":" + auth.getCredentials().toString();
  con.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64(base64.getBytes())));

代码示例来源:origin: org.acegisecurity/acegi-security

Assert.notNull(successfulAuthentication.getCredentials());

代码示例来源:origin: org.acegisecurity/acegi-security

private CasAuthenticationToken authenticateNow(Authentication authentication)
  throws AuthenticationException {
  // Validate
  TicketResponse response = ticketValidator.confirmTicketValid(authentication.getCredentials().toString());
  // Check proxy list is trusted
  this.casProxyDecider.confirmProxyListTrusted(response.getProxyList());
  // Lookup user details
  UserDetails userDetails = this.casAuthoritiesPopulator.getUserDetails(response.getUser());
  // Construct CasAuthenticationToken
  return new CasAuthenticationToken(this.key, userDetails, authentication.getCredentials(),
    userDetails.getAuthorities(), userDetails, response.getProxyList(), response.getProxyGrantingTicketIou());
}

代码示例来源:origin: org.acegisecurity/acegi-security

public Authentication buildRunAs(Authentication authentication, Object object, ConfigAttributeDefinition config) {
  List newAuthorities = new Vector();
  Iterator iter = config.getConfigAttributes();
  while (iter.hasNext()) {
    ConfigAttribute attribute = (ConfigAttribute) iter.next();
    if (this.supports(attribute)) {
      GrantedAuthorityImpl extraAuthority = new GrantedAuthorityImpl(getRolePrefix()
          + attribute.getAttribute());
      newAuthorities.add(extraAuthority);
    }
  }
  if (newAuthorities.size() == 0) {
    return null;
  } else {
    for (int i = 0; i < authentication.getAuthorities().length; i++) {
      newAuthorities.add(authentication.getAuthorities()[i]);
    }
    GrantedAuthority[] resultType = {new GrantedAuthorityImpl("holder")};
    GrantedAuthority[] newAuthoritiesAsArray = (GrantedAuthority[]) newAuthorities.toArray(resultType);
    return new RunAsUserToken(this.key, authentication.getPrincipal(), authentication.getCredentials(),
      newAuthoritiesAsArray, authentication.getClass());
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

Assert.notNull(successfulAuthentication.getCredentials());
Assert.isInstanceOf(UserDetails.class, successfulAuthentication.getPrincipal());

代码示例来源:origin: org.acegisecurity/acegi-security

if ((authentication.getCredentials() == null) || "".equals(authentication.getCredentials())) {
  throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.noServiceTicket",
      "Failed to provide a CAS service ticket to validate"));
  result = statelessTicketCache.getByTicketId(authentication.getCredentials().toString());

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  String username = authentication.getPrincipal().toString();
  String password = authentication.getCredentials().toString();
  try {
    UnixUser u = new PAM(serviceName).authenticate(username, password);
    Set<String> grps = u.getGroups();
    GrantedAuthority[] groups = new GrantedAuthority[grps.size()];
    int i=0;
    for (String g : grps)
      groups[i++] = new GrantedAuthorityImpl(g);
    EnvVars.setHudsonUserEnvVar(username);
    // I never understood why Acegi insists on keeping the password...
    return new UsernamePasswordAuthenticationToken(username, password, groups);
  } catch (PAMException e) {
    throw new BadCredentialsException(e.getMessage(),e);
  }
}

代码示例来源:origin: hudson/hudson-2.x

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  String username = authentication.getPrincipal().toString();
  String password = authentication.getCredentials().toString();
  try {
    UnixUser u = new PAM(serviceName).authenticate(username, password);
    Set<String> grps = u.getGroups();
    GrantedAuthority[] groups = new GrantedAuthority[grps.size()];
    int i=0;
    for (String g : grps)
      groups[i++] = new GrantedAuthorityImpl(g);
    EnvVars.setHudsonUserEnvVar(username);
    // I never understood why Acegi insists on keeping the password...
    return new UsernamePasswordAuthenticationToken(username, password, groups);
  } catch (PAMException e) {
    throw new BadCredentialsException(e.getMessage(),e);
  }
}

代码示例来源:origin: org.acegisecurity/acegi-security

/**
 * Creates a successful {@link Authentication} object.<p>Protected so subclasses can override.</p>
 *  <p>Subclasses will usually store the original credentials the user supplied (not salted or encoded
 * passwords) in the returned <code>Authentication</code> object.</p>
 *
 * @param principal that should be the principal in the returned object (defined by the {@link
 *        #isForcePrincipalAsString()} method)
 * @param authentication that was presented to the provider for validation
 * @param user that was loaded by the implementation
 *
 * @return the successful authentication token
 */
protected Authentication createSuccessAuthentication(Object principal, Authentication authentication,
  UserDetails user) {
  // Ensure we return the original credentials the user supplied,
  // so subsequent attempts are successful even with encoded passwords.
  // Also ensure we return the original getDetails(), so that future
  // authentication events after cache expiry contain the details
  UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(principal,
      authentication.getCredentials(), user.getAuthorities());
  result.setDetails(authentication.getDetails());
  return result;
}

代码示例来源:origin: org.acegisecurity/acegi-security

X509Certificate clientCertificate = (X509Certificate) authentication.getCredentials();

代码示例来源:origin: org.jenkins-ci.plugins/collabnet

/**
   * @param authentication request object
   * @return fully authenticated object, including credentials
   */
  public Authentication authenticate(Authentication authentication) 
    throws BadCredentialsException {
    String username = authentication.getName();
    String password = (String) authentication.getCredentials();
    try {
      CollabNetApp cna = new CollabNetApp(this.getCollabNetUrl(), username, password);
      return new CNAuthentication(authentication.getName(), cna);
    } catch (RemoteException re) {
      throw new BadCredentialsException("Failed to log into " + 
                       this.getCollabNetUrl() + ": " + 
                       re.getMessage());
    }
  }
}

相关文章