-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6dbb65
commit 5d916f0
Showing
5 changed files
with
149 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...n/java/org/wso2/carbon/identity/oauth2/token/bindings/impl/ClientInstanceTokenBinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com). | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.identity.oauth2.token.bindings.impl; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration; | ||
import org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenReqDTO; | ||
import org.wso2.carbon.identity.oauth2.model.RequestParameter; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.GrantTypes.AUTHORIZATION_CODE; | ||
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.GrantTypes.PASSWORD; | ||
import static org.wso2.carbon.identity.oauth2.OAuth2Constants.TokenBinderType.CLIENT_INSTANCE; | ||
|
||
|
||
/** | ||
* Client Instance Reference binding to the token. | ||
*/ | ||
public class ClientInstanceTokenBinder extends AbstractTokenBinder { | ||
|
||
private static final String CLIENT_INSTANCE_REF = "clientInstanceRef"; | ||
|
||
@Override | ||
public Optional<String> getTokenBindingValue(OAuth2AccessTokenReqDTO oAuth2AccessTokenReqDTO) { | ||
|
||
RequestParameter[] parameters = oAuth2AccessTokenReqDTO.getRequestParameters(); | ||
for (RequestParameter parameter : parameters) { | ||
if (CLIENT_INSTANCE_REF.equals(parameter.getKey()) | ||
&& StringUtils.isNotBlank(parameter.getValue()[0])) { | ||
return Optional.ofNullable(parameter.getValue()[0]); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
|
||
return "Client Instance"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
|
||
return "Client Instance Token Binding"; | ||
} | ||
|
||
@Override | ||
public String getBindingType() { | ||
|
||
return CLIENT_INSTANCE; | ||
} | ||
|
||
@Override | ||
public List<String> getSupportedGrantTypes() { | ||
Set<String> supportedGrantTypes = OAuthServerConfiguration.getInstance().getSupportedGrantTypes().keySet(); | ||
return supportedGrantTypes.stream().collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public String getOrGenerateTokenBindingValue(HttpServletRequest request) { | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void setTokenBindingValueForResponse(HttpServletResponse response, String bindingValue) { | ||
|
||
} | ||
|
||
@Override | ||
public void clearTokenBindingElements(HttpServletRequest request, HttpServletResponse response) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isValidTokenBinding(Object request, String bindingReference) { | ||
|
||
/* | ||
* As the token binding reference is same as the device code, the token call implementation | ||
* will validate the device code. So no need to revalidate here. | ||
*/ | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isValidTokenBinding(OAuth2AccessTokenReqDTO oAuth2AccessTokenReqDTO, String bindingReference) { | ||
|
||
/* | ||
* As the token binding reference is same as the device code, the token call implementation | ||
* will validate the device code. So no need to revalidate here. | ||
*/ | ||
return true; | ||
} | ||
} |