gpt4 book ai didi

org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 16:25:05 26 4
gpt4 key购买 nike

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

WSUsernameTokenPrincipalImpl介绍

[英]This class implements the Principal interface and represents a UsernameToken user.

In addition to the principal's name this principal object also contains the nonce and created time of the UsernameToken (refer to the OASIS WS Security specification, UsernameToken profile). These values are set only if the password of UsernameToken was of type PasswordDigest.

Furthermore the password type is provided to the application. The password type is the string of the type attribute of the password element inside the username token. Refer to the OASIS WSS specification for predefined password types.

The equals() method use the prinicipal's name only and does not compare nonce or created time.

Modelled according to the example provided by JAAS documentation
[中]此类实现Principal接口并表示UsernameToken用户。
除了主体的名称之外,这个主体对象还包含UsernameToken的nonce和创建时间(请参阅OASIS WS-Security规范UsernameToken配置文件)。仅当UsernameToken的密码类型为PasswordDigest时,才会设置这些值。
此外,还会向应用程序提供密码类型。password type是用户名令牌中password元素的type属性的字符串。有关预定义的密码类型,请参阅OASIS WSS规范。
equals()方法只使用prinicipal的名称,不比较nonce或created time。
根据JAAS文档提供的示例建模

代码示例

代码示例来源:origin: apache/cxf

/**
 * Create a principal based on the authenticated UsernameToken.
 * @throws Base64DecodingException
 */
private Principal createPrincipal(
  String username,
  String passwordValue,
  String passwordType,
  String nonce,
  String createdTime
) {
  boolean hashed = false;
  if (WSS4JConstants.PASSWORD_DIGEST.equals(passwordType)) {
    hashed = true;
  }
  WSUsernameTokenPrincipalImpl principal = new WSUsernameTokenPrincipalImpl(username, hashed);
  if (nonce != null) {
    principal.setNonce(Base64.getMimeDecoder().decode(nonce));
  }
  principal.setPassword(passwordValue);
  principal.setCreatedTime(createdTime);
  principal.setPasswordType(passwordType);
  return principal;
}

代码示例来源:origin: spring-projects/spring-ws

@Override
protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback)
    throws IOException, UnsupportedCallbackException {
  UserDetails user = loadUserDetails(callback.getPrincipal().getName());
  WSUsernameTokenPrincipalImpl principal = callback.getPrincipal();
  UsernamePasswordAuthenticationToken authRequest =
      new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), user.getAuthorities());
  if (logger.isDebugEnabled()) {
    logger.debug("Authentication success: " + authRequest.toString());
  }
  SecurityContextHolder.getContext().setAuthentication(authRequest);
}

代码示例来源:origin: apache/cxf

protected void validate(Message message) throws WSSecurityException {
  AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
  if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
    String name = null;
    if (policy != null) {
      name = policy.getUserName();
    }
    String errorMsg = "No user name and/or password is available, name: " + name;
    LOG.warning(errorMsg);
    throw new SecurityException(errorMsg);
  }
  UsernameToken token = convertPolicyToToken(policy);
  Credential credential = new Credential();
  credential.setUsernametoken(token);
  RequestData data = new RequestData();
  data.setMsgContext(message);
  data.setCallbackHandler(callbackHandler);
  credential = getValidator().validate(credential, data);
  // Create a Principal/SecurityContext
  SecurityContext sc = null;
  if (credential != null && credential.getPrincipal() != null) {
    sc = createSecurityContext(message, credential);
  } else {
    Principal p = new WSUsernameTokenPrincipalImpl(policy.getUserName(), false);
    ((WSUsernameTokenPrincipalImpl)p).setPassword(policy.getPassword());
    sc = createSecurityContext(p);
  }
  message.put(SecurityContext.class, sc);
}

代码示例来源:origin: org.apache.cxf.services.sts/cxf-services-sts-core

/**
 * Create a principal based on the authenticated UsernameToken.
 * @throws Base64DecodingException
 */
private Principal createPrincipal(
  String username,
  String passwordValue,
  String passwordType,
  String nonce,
  String createdTime
) {
  boolean hashed = false;
  if (WSS4JConstants.PASSWORD_DIGEST.equals(passwordType)) {
    hashed = true;
  }
  WSUsernameTokenPrincipalImpl principal = new WSUsernameTokenPrincipalImpl(username, hashed);
  if (nonce != null) {
    principal.setNonce(Base64.getMimeDecoder().decode(nonce));
  }
  principal.setPassword(passwordValue);
  principal.setCreatedTime(createdTime);
  principal.setPasswordType(passwordType);
  return principal;
}

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

@Override
protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback)
    throws IOException, UnsupportedCallbackException {
  UserDetails user = loadUserDetails(callback.getPrincipal().getName());
  WSUsernameTokenPrincipalImpl principal = callback.getPrincipal();
  UsernamePasswordAuthenticationToken authRequest =
      new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), user.getAuthorities());
  if (logger.isDebugEnabled()) {
    logger.debug("Authentication success: " + authRequest.toString());
  }
  SecurityContextHolder.getContext().setAuthentication(authRequest);
}

代码示例来源:origin: org.apache.wss4j/wss4j-ws-security-dom

/**
 * Create a WSUsernameTokenPrincipal from this UsernameToken object
 */
public Principal createPrincipal() throws WSSecurityException {
  WSUsernameTokenPrincipalImpl principal =
    new WSUsernameTokenPrincipalImpl(getName(), isHashed());
  String nonce = getNonce();
  if (nonce != null) {
    principal.setNonce(org.apache.xml.security.utils.XMLUtils.decode(nonce));
  }
  principal.setPassword(getPassword());
  principal.setCreatedTime(getCreated());
  return principal;
}

代码示例来源:origin: apache/servicemix-bundles

@Override
protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback)
    throws IOException, UnsupportedCallbackException {
  UserDetails user = loadUserDetails(callback.getPrincipal().getName());
  WSUsernameTokenPrincipalImpl principal = callback.getPrincipal();
  UsernamePasswordAuthenticationToken authRequest =
      new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), user.getAuthorities());
  if (logger.isDebugEnabled()) {
    logger.debug("Authentication success: " + authRequest.toString());
  }
  SecurityContextHolder.getContext().setAuthentication(authRequest);
}

代码示例来源:origin: apache/cxf

protected UsernameTokenPrincipal parseTokenAndCreatePrincipal(Element tokenElement, boolean bspCompliant)
  throws WSSecurityException, Base64DecodingException {
  BSPEnforcer bspEnforcer = new org.apache.wss4j.common.bsp.BSPEnforcer(!bspCompliant);
  org.apache.wss4j.dom.message.token.UsernameToken ut =
    new org.apache.wss4j.dom.message.token.UsernameToken(tokenElement, false, bspEnforcer);
  WSUsernameTokenPrincipalImpl principal = new WSUsernameTokenPrincipalImpl(ut.getName(), ut.isHashed());
  if (ut.getNonce() != null) {
    principal.setNonce(XMLUtils.decode(ut.getNonce()));
  }
  principal.setPassword(ut.getPassword());
  principal.setCreatedTime(ut.getCreated());
  principal.setPasswordType(ut.getPasswordType());
  return principal;
}

代码示例来源:origin: org.apache.cxf/cxf-rt-ws-security

protected UsernameTokenPrincipal parseTokenAndCreatePrincipal(Element tokenElement, boolean bspCompliant)
  throws WSSecurityException, Base64DecodingException {
  BSPEnforcer bspEnforcer = new org.apache.wss4j.common.bsp.BSPEnforcer(!bspCompliant);
  org.apache.wss4j.dom.message.token.UsernameToken ut =
    new org.apache.wss4j.dom.message.token.UsernameToken(tokenElement, false, bspEnforcer);
  WSUsernameTokenPrincipalImpl principal = new WSUsernameTokenPrincipalImpl(ut.getName(), ut.isHashed());
  if (ut.getNonce() != null) {
    principal.setNonce(XMLUtils.decode(ut.getNonce()));
  }
  principal.setPassword(ut.getPassword());
  principal.setCreatedTime(ut.getCreated());
  principal.setPasswordType(ut.getPasswordType());
  return principal;
}

代码示例来源:origin: apache/cxf

public Credential validate(Credential credential, RequestData data) throws WSSecurityException {
    Credential cred = super.validate(credential, data);

    UsernameToken ut = credential.getUsernametoken();
    WSUsernameTokenPrincipalImpl principal =
      new WSUsernameTokenPrincipalImpl(ut.getName(), ut.isHashed());
    principal.setCreatedTime(ut.getCreated());
    principal.setNonce(principal.getNonce());
    principal.setPassword(ut.getPassword());
    principal.setPasswordType(ut.getPasswordType());

    Subject subject = new Subject();
    subject.getPrincipals().add(principal);
    if ("Alice".equals(ut.getName())) {
      subject.getPrincipals().add(new SimpleGroup("manager", ut.getName()));
    }
    subject.getPrincipals().add(new SimpleGroup("worker", ut.getName()));
    cred.setSubject(subject);

    return cred;
  }
}

代码示例来源:origin: org.apache.wss4j/wss4j-ws-security-dom

} else {
  WSUsernameTokenPrincipalImpl principal =
    new WSUsernameTokenPrincipalImpl(token.getName(), token.isHashed());
  if (token.getNonce() != null) {
    principal.setNonce(XMLUtils.decode(token.getNonce()));
  principal.setPassword(token.getPassword());
  principal.setCreatedTime(token.getCreated());
  principal.setPasswordType(token.getPasswordType());
  result.put(WSSecurityEngineResult.TAG_PRINCIPAL, principal);

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com