2017-03-10 2 views
0

Je travaille sur WSO2IS, et avait été en mesure d'obtenir un autonome jeton d'accès de WSO2IS par oauth2 type de subvention « mot de passe » en suivant this postWSO2 Self contained AccessToken revendique la configuration - « sous » champ

Je suis également en mesure de vérifier la signature du jeton dans l'application (see this post)

mais il reste encore une dernière étape que je ne peux pas passer

ici est un échantillon de jeton d'accès que j'ai de WSO2IS

{iss=https://localhost:9443/oauth2/token, [email protected], aud=[J3lbMMMJFwXB6neKzXv030S9lfga], exp=1488710173, iat=1488706573, azp=J3lbMMMJFwXB6neKzXv030S9lfga} 

Vous pouvez voir que la valeur de "sub" est un nom d'utilisateur, qui correspond à la revendication "http://wso2.org/claims/username".

Je souhaite modifier la configuration en WSO2IS pour que le « sous » correspondent à la revendication « http://wso2.org/claims/userid »

J'ai changé la « configuration de réclamation » sous la rubrique « fournisseurs de services »; J'ai également changé le "sous" dans le "http://wso2.org/oidc/claim" sous "Réclamations". mais ne peut pas avoir de succès.

Y a-t-il quelque chose que j'ai manqué?

s'il vous plaît conseiller

grâce

+0

quelle est la version du serveur d'identité que vous utilisez? –

+0

Pouvez-vous aller dans la section «Configuration de l'authentification locale et sortante» du fournisseur de services et décocher «Utiliser le domaine locataire dans l'identificateur de sujet local» et vérifier quel est le résultat. –

+0

J'utilise WSO2 IS 5.3.0 –

Répondre

0

J'ai enfin ce problème résolu par le codage au lieu de la configuration.

J'avais implémenté une extension pour un générateur de jeton d'accès autonome (JWT dans Oauth2) en suivant ce post. Je construis le pot, et télécharger le pot sous/répertoire/composants/lib/

Je checkout juste ce repo et fait les modifications suivantes

/** 
    * For a locally authenticated user, subject identifier is supposed to be as below. 
    * <userstore_domain>/<username>@<tenant_domain>. 
    * 
    * yet somehow, what I got is <username>@<tenant_domain> 
    * @param SubjectId 
    * @return 
    * @throws IdentityOAuth2Exception 
    */ 
    private static SubjectTriple parseSubjectId(String subjectId) throws IdentityOAuth2Exception{ 
     if (StringUtils.isBlank(subjectId)){ 
      throw new IdentityOAuth2Exception("invalid subject identifier"); 

     } 
     /* 
     * domain may not present 
     */ 
     String sid = null; 
     SubjectTriple st = new SubjectTriple(); 
     if(StringUtils.contains(subjectId, '/')){ 
      st.domain = StringUtils.substringBeforeLast(subjectId, "/"); 
      sid = StringUtils.substringAfterLast(subjectId, "/"); 
     }else{ 
      sid = subjectId; 
     } 

     st.username = StringUtils.substringBeforeLast(sid, "@"); 
     st.profile = StringUtils.substringAfterLast(sid, "@"); 

     return st; 
    } 

    /** 
    * To build id token from OauthToken request message context 
    * 
    * @param request Token request message context 
    * @return Signed jwt string. 
    * @throws IdentityOAuth2Exception 
    */ 
    protected String buildIDToken(OAuthTokenReqMessageContext request) 
      throws IdentityOAuth2Exception { 

     String issuer = OAuth2Util.getIDTokenIssuer(); 
     long lifetimeInMillis = OAuthServerConfiguration.getInstance(). 
       getApplicationAccessTokenValidityPeriodInSeconds() * 1000; 
     long curTimeInMillis = Calendar.getInstance().getTimeInMillis(); 


     SubjectTriple triple = parseSubjectId(request.getAuthorizedUser().getAuthenticatedSubjectIdentifier()); 
     String userId = null; 
     try { 
      userId = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager() 
        .getUserClaimValue(triple.username, Constants.LOCAL_CLAIM__UserID, triple.profile); 
     } catch (UserStoreException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     String clientId = request.getOauth2AccessTokenReqDTO().getClientId(); 
     // Set claims to jwt token. 
     JWTClaimsSet jwtClaimsSet = new JWTClaimsSet(); 
     jwtClaimsSet.setIssuer(issuer); 
     jwtClaimsSet.setSubject(userId); 
     jwtClaimsSet.setAudience(Arrays.asList(clientId)); 
     jwtClaimsSet.setClaim(Constants.AUTHORIZATION_PARTY, clientId); 
     jwtClaimsSet.setExpirationTime(new Date(curTimeInMillis + lifetimeInMillis)); 
     jwtClaimsSet.setIssueTime(new Date(curTimeInMillis)); 

     if (JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName())) { 
      return new PlainJWT(jwtClaimsSet).serialize(); 
     } 
     return signJWT(jwtClaimsSet, request); 
    } 

    /** 
    * Build a signed jwt token from authorization request message context 
    * 
    * @param request Oauth authorization message context 
    * @return Signed jwt string 
    * @throws IdentityOAuth2Exception 
    */ 
    protected String buildIDToken(OAuthAuthzReqMessageContext request) 
      throws IdentityOAuth2Exception { 

     String issuer = OAuth2Util.getIDTokenIssuer(); 
     long lifetimeInMillis = OAuthServerConfiguration.getInstance(). 
       getApplicationAccessTokenValidityPeriodInSeconds() * 1000; 
     long curTimeInMillis = Calendar.getInstance().getTimeInMillis(); 
     OAuth2AuthorizeReqDTO dto = request.getAuthorizationReqDTO(); 

     SubjectTriple triple = parseSubjectId(dto.getUser().getAuthenticatedSubjectIdentifier()); 

     String userId = null; 
     try { 
      userId = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager() 
        .getUserClaimValue(triple.username, Constants.LOCAL_CLAIM__UserID, triple.profile); 
     } catch (UserStoreException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     String consumerKey = dto.getConsumerKey(); 
     JWTClaimsSet jwtClaimsSet = new JWTClaimsSet(); 
     jwtClaimsSet.setIssuer(issuer); 
     jwtClaimsSet.setSubject(userId); 
     jwtClaimsSet.setAudience(Arrays.asList(consumerKey)); 
     jwtClaimsSet.setClaim(Constants.AUTHORIZATION_PARTY,consumerKey); 
     jwtClaimsSet.setExpirationTime(new Date(curTimeInMillis + lifetimeInMillis)); 
     jwtClaimsSet.setIssueTime(new Date(curTimeInMillis)); 

     if (JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName())) { 
      return new PlainJWT(jwtClaimsSet).serialize(); 
     } 
     return signJWT(jwtClaimsSet, request); 
    } 

les importations

import com.nimbusds.jose.Algorithm; 
import com.nimbusds.jose.JOSEException; 
import com.nimbusds.jose.JWSAlgorithm; 
import com.nimbusds.jose.JWSHeader; 
import com.nimbusds.jose.JWSSigner; 
import com.nimbusds.jose.crypto.RSASSASigner; 
import com.nimbusds.jwt.JWTClaimsSet; 
import com.nimbusds.jwt.PlainJWT; 
import com.nimbusds.jwt.SignedJWT; 

import org.apache.commons.lang.StringUtils; 
import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory; 
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; 
import org.wso2.carbon.base.MultitenantConstants; 
import org.wso2.carbon.context.CarbonContext; 
import org.wso2.carbon.core.util.KeyStoreManager; 
import org.wso2.carbon.identity.core.util.IdentityTenantUtil; 
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration; 
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; 
import org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext; 
import org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO; 
import org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext; 
import org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl; 
import org.wso2.carbon.identity.oauth2.util.OAuth2Util; 
import org.wso2.carbon.user.api.UserStoreException; 

import java.security.Key; 
import java.security.interfaces.RSAPrivateKey; 
import java.util.Arrays; 
import java.util.Calendar; 
import java.util.Date; 
import java.util.Map; 
import java.util.concurrent.ConcurrentHashMap;