forked from eclipse-ditto/ditto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-ditto#926] add HTTP API for activateTokenIntegration and dea…
…ctivateTokenIntegration. Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
- Loading branch information
Showing
22 changed files
with
681 additions
and
45 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
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
52 changes: 52 additions & 0 deletions
52
...tto/services/gateway/endpoints/routes/policies/OAuthTokenIntegrationSubjectIdFactory.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,52 @@ | ||
/* | ||
* Copyright (c) 2020 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.services.gateway.endpoints.routes.policies; | ||
|
||
import org.eclipse.ditto.model.base.headers.DittoHeaders; | ||
import org.eclipse.ditto.model.jwt.JsonWebToken; | ||
import org.eclipse.ditto.model.placeholders.ExpressionResolver; | ||
import org.eclipse.ditto.model.placeholders.PlaceholderFactory; | ||
import org.eclipse.ditto.model.policies.SubjectId; | ||
import org.eclipse.ditto.services.gateway.security.authentication.jwt.JwtPlaceholder; | ||
import org.eclipse.ditto.services.gateway.util.config.security.OAuthConfig; | ||
|
||
/** | ||
* Creator of token integration subjects for the configured OAuth subject pattern. | ||
*/ | ||
public final class OAuthTokenIntegrationSubjectIdFactory implements TokenIntegrationSubjectIdFactory { | ||
|
||
private final String subjectTemplate; | ||
|
||
private OAuthTokenIntegrationSubjectIdFactory(final String subjectTemplate) { | ||
this.subjectTemplate = subjectTemplate; | ||
} | ||
|
||
/** | ||
* Create an OAuth token integration subject ID factory from OAuth config. | ||
* | ||
* @param oAuthConfig the config. | ||
* @return the factory. | ||
*/ | ||
public static OAuthTokenIntegrationSubjectIdFactory of(final OAuthConfig oAuthConfig) { | ||
return new OAuthTokenIntegrationSubjectIdFactory(oAuthConfig.getTokenIntegrationSubject()); | ||
} | ||
|
||
@Override | ||
public SubjectId getSubjectId(final DittoHeaders dittoHeaders, final JsonWebToken jwt) { | ||
final ExpressionResolver expressionResolver = PlaceholderFactory.newExpressionResolver( | ||
PlaceholderFactory.newPlaceholderResolver(PlaceholderFactory.newHeadersPlaceholder(), dittoHeaders), | ||
PlaceholderFactory.newPlaceholderResolver(JwtPlaceholder.getInstance(), jwt) | ||
); | ||
return SubjectId.newInstance(expressionResolver.resolvePartially(subjectTemplate)); | ||
} | ||
} |
Oops, something went wrong.