Repository: cxf Updated Branches: refs/heads/master 8498cbbcb -> 474369eb0
Adding UserInfo and IdToken context providers Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/474369eb Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/474369eb Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/474369eb Branch: refs/heads/master Commit: 474369eb04efb9ccfcdf5a30da9edb0e644200b8 Parents: 8498cbb Author: Sergey Beryozkin <[email protected]> Authored: Mon Dec 14 15:52:56 2015 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Mon Dec 14 15:52:56 2015 +0000 ---------------------------------------------------------------------- .../oauth2/client/AccessTokenClientFilter.java | 53 ++++++++++++++++++++ .../cxf/rs/security/oidc/common/UserInfo.java | 7 +++ .../oidc/rp/IdTokenContextProvider.java | 35 +++++++++++++ .../oidc/rp/UserInfoContextProvider.java | 39 ++++++++++++++ 4 files changed, 134 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/474369eb/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AccessTokenClientFilter.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AccessTokenClientFilter.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AccessTokenClientFilter.java new file mode 100644 index 0000000..668a73b --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AccessTokenClientFilter.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.cxf.rs.security.oauth2.client; + +import java.io.IOException; + +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientRequestFilter; +import javax.ws.rs.core.HttpHeaders; + +import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken; +import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants; + +public class AccessTokenClientFilter extends AbstractAuthSupplier implements ClientRequestFilter { + + public AccessTokenClientFilter() { + super(OAuthConstants.BEARER_AUTHORIZATION_SCHEME); + } + + @Override + public void filter(ClientRequestContext requestContext) throws IOException { + requestContext.getHeaders().putSingle(HttpHeaders.AUTHORIZATION, + createAuthorizationHeader()); + + } + protected ClientAccessToken getClientAccessToken() { + ClientAccessToken at = super.getClientAccessToken(); + if (at.getTokenKey() == null) { + ClientTokenContext ctx = StaticClientTokenContext.getClientTokenContext(); + if (ctx != null) { + at = ctx.getToken(); + } + } + return at; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/474369eb/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/UserInfo.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/UserInfo.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/UserInfo.java index 1ac2986..06b4e96 100644 --- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/UserInfo.java +++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/UserInfo.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.cxf.rs.security.jose.jwt.JwtClaims; public class UserInfo extends AbstractUserInfo { + private IdToken idToken; public UserInfo() { } public UserInfo(JwtClaims claims) { @@ -32,4 +33,10 @@ public class UserInfo extends AbstractUserInfo { public UserInfo(Map<String, Object> claims) { super(new LinkedHashMap<String, Object>(claims)); } + public IdToken getIdToken() { + return idToken; + } + public void setIdToken(IdToken idToken) { + this.idToken = idToken; + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/474369eb/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/IdTokenContextProvider.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/IdTokenContextProvider.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/IdTokenContextProvider.java new file mode 100644 index 0000000..0955b8e --- /dev/null +++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/IdTokenContextProvider.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.cxf.rs.security.oidc.rp; + +import org.apache.cxf.jaxrs.ext.ContextProvider; +import org.apache.cxf.message.Message; +import org.apache.cxf.rs.security.oauth2.client.ClientTokenContext; +import org.apache.cxf.rs.security.oidc.common.IdToken; + +public class IdTokenContextProvider implements ContextProvider<IdToken> { + + @Override + public IdToken createContext(Message m) { + OidcClientTokenContext ctx = (OidcClientTokenContext) + m.getContent(ClientTokenContext.class); + return ctx != null ? ctx.getIdToken() : null; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/474369eb/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/UserInfoContextProvider.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/UserInfoContextProvider.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/UserInfoContextProvider.java new file mode 100644 index 0000000..ad4793e --- /dev/null +++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/UserInfoContextProvider.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.cxf.rs.security.oidc.rp; + +import org.apache.cxf.jaxrs.ext.ContextProvider; +import org.apache.cxf.message.Message; +import org.apache.cxf.rs.security.oauth2.client.ClientTokenContext; +import org.apache.cxf.rs.security.oidc.common.UserInfo; + +public class UserInfoContextProvider implements ContextProvider<UserInfo> { + + @Override + public UserInfo createContext(Message m) { + OidcClientTokenContext ctx = (OidcClientTokenContext) + m.getContent(ClientTokenContext.class); + UserInfo userInfo = ctx != null ? ctx.getUserInfo() : null; + if (userInfo != null) { + userInfo.setIdToken(ctx.getIdToken()); + } + return userInfo; + } + +}
