我尝试更新自定义声明java文件中的导入。到目前为止,我发现的并没有什么改变,但真的是一个进口。 org.wso2.carbon.apimgt。 impl .token.URLSafeJWTGenerator已更改为org.wso2.carbon.apimgt。 keymgt .token.URLSafeJWTGenerator。当我将此更改添加到文件时,它表示populateCustomClaims方法不再有效。
import edu.wso2.is.helper.DomainEntity;
import edu.wso2.is.helper.DomainEntityHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO;
import org.wso2.carbon.apimgt.impl.token.URLSafeJWTGenerator;
import org.wso2.carbon.apimgt.api.*;
import org.wso2.carbon.user.core.util.UserCoreUtil;
import org.apache.commons.codec.binary.Base64;
import java.util.HashMap;
import java.util.Map;
public class CustomTokenGenerator extends URLSafeJWTGenerator {
private static final Log log = LogFactory.getLog(CustomTokenGenerator.class);
static String DOMAIN_DIALECT = "http://domain.edu/claims";
private final DOMAINEntityHelper DOMAINEntityHelper = new DOMAINEntityHelper();
public CustomTokenGenerator() {
}
//there is no access to the api call headers, etc. only what was passed in the DTO
public Map<String, String> populateCustomClaims(APIKeyValidationInfoDTO keyValidationInfoDTO, String apiContext, String version, String accessToken)
throws APIManagementException {
if (log.isDebugEnabled())
log.debug("populateCustomClaims starting");
Map<String, String> map = new HashMap<>();//map for custom claims
Map<String, String> claims = super.populateCustomClaims(keyValidationInfoDTO,apiContext,version,accessToken);
boolean isApplicationToken =
keyValidationInfoDTO.getUserType().equalsIgnoreCase(APIConstants.ACCESS_TOKEN_USER_TYPE_APPLICATION) ? true : false;
if (isApplicationToken) {
if (log.isDebugEnabled())
log.debug("Application Token detected - no resource owner claims will be added");
}
else {
String netid = extractNetId(keyValidationInfoDTO.getEndUserName());
if (log.isDebugEnabled())
log.debug("adding resource owner claims to map - netid " + netid);
map = addResourceOwnerClaims(netid, map);
}
String consumerKey = keyValidationInfoDTO.getConsumerKey();
String dialect = getDialectURI();
String subscriberNetId = extractNetId(keyValidationInfoDTO.getSubscriber());
if (log.isDebugEnabled())
log.debug("adding client claims to map - subscriberNetId " + subscriberNetId + " client_id " + consumerKey);
map.put(dialect + "/client_id",consumerKey);
map = addClientClaims(consumerKey, subscriberNetId, map);
if (log.isDebugEnabled())
log.debug("populateCustomClaims ending");
return map;
}
private Map<String, String> addClientClaims(String consumerKey, String subscriberNetId, Map<String, String> map) {
if (log.isDebugEnabled())
log.debug("addClientClaims starting");
if (consumerKey == null) {
return map;
}
boolean isConsumerClaims = true;
DOMAINEntity identifiers = DOMAINEntityHelper.getDOMAINEntityFromConsumerKey(consumerKey);
if (identifiers == null) {
if (log.isDebugEnabled())
log.debug("No claims found for consumerKey, using subscriberNetId");
isConsumerClaims = false;
identifiers = DOMAINEntityHelper.getDOMAINEntityFromNetId(subscriberNetId);
if (identifiers == null)
return map;
}
if (isConsumerClaims)
map.put(DOMAIN_DIALECT + "/client_claim_source", "CLIENT_ID");
else
map.put(DOMAIN_DIALECT + "/client_claim_source", "CLIENT_SUBSCRIBER");
map.put(DOMAIN_DIALECT + "/client_subscriber_net_id", subscriberNetId);
map.put(DOMAIN_DIALECT + "/client_person_id", identifiers.getPersonId());
map.put(DOMAIN_DIALECT + "/client_net_id", identifiers.getNetId());
map.put(DOMAIN_DIALECT + "/client_surname", identifiers.getSurname());
if (log.isDebugEnabled())
log.debug("addClientClaims ending");
return map;
}
/* adds resource owner credentials to the map */
private Map<String, String> addResourceOwnerClaims(String netid, Map<String, String> map) {
if (log.isDebugEnabled())
log.debug("addResourceOwnerClaims starting");
if (netid == null) {
return map;
}
DOMAINEntity identifiers = DOMAINEntityHelper.getDOMAINEntityFromNetId(netid);
if (identifiers == null) {
return map;
}
map.put(DOMAIN_DIALECT + "/resourceowner_person_id", identifiers.getPersonId());
map.put(DOMAIN_DIALECT + "/resourceowner_domain_id", identifiers.getDomainId());
map.put(DOMAIN_DIALECT + "/resourceowner_surname", identifiers.getSurname());
map.put(DOMAIN_DIALECT + "/resourceowner_rest_of_name", identifiers.getRestOfName());
map.put(DOMAIN_DIALECT + "/resourceowner_surname_position", identifiers.getSurnamePosition());
if (log.isDebugEnabled())
log.debug("addResourceOwnerClaims ending");
return map;
}
private String extractNetId(String carbonIdentifier) {
if (log.isDebugEnabled()) {
log.debug("extractNetId starting");
log.debug("step 1: carbonIdentifier is " + carbonIdentifier);
}
String netid = UserCoreUtil.removeDomainFromName(carbonIdentifier);
if (log.isDebugEnabled())
log.debug("step 2: after remove domain netid is " + netid);
if (netid != null) {
if (netid.endsWith("@carbon.super")) {
netid = netid.replace("@carbon.super", "");
}
}
if (log.isDebugEnabled())
log.debug("extractNetId ending with result " + netid);
return netid;
}
}
我还更新了pom.xml依赖
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.wso2.is</groupId>
<artifactId>edu.wso2.is.CustomClaimsGenerator</artifactId>
<version>1.3.0</version>
<packaging>jar</packaging>
<name>Custom Claims Generator</name>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.application.common</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4.0.wso2v1</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.keymgt</artifactId>
<version>6.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
非常感谢任何方向的帮助或观点。 谢谢!
答案 0 :(得分:1)
populateCustomClaims()
签名已更改。现在需要TokenValidationContext
object。
public Map<String, String> populateCustomClaims(TokenValidationContext validationContext)
throws APIManagementException {
代码为here。