Repository: cxf Updated Branches: refs/heads/master e9ac42b6d -> 71a43b949
[CXF-5311] Copying some SAML grant handlers to JWT Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/71a43b94 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/71a43b94 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/71a43b94 Branch: refs/heads/master Commit: 71a43b949fdb0cfea826f43a5ab7ed2b2bda4f89 Parents: e9ac42b Author: Sergey Beryozkin <[email protected]> Authored: Thu May 22 17:46:09 2014 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Thu May 22 17:46:09 2014 +0100 ---------------------------------------------------------------------- .../jwt/grant/AbstractJwtBearerGrant.java | 69 ++++++++++++++++++++ .../grant/JwtBearerClientCredentialsGrant.java | 41 ++++++++++++ .../oauth2/jwt/grant/JwtBearerGrant.java | 48 ++++++++++++++ .../oauth2/jwt/grant/JwtUserSubject.java | 34 ++++++++++ 4 files changed, 192 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/71a43b94/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/AbstractJwtBearerGrant.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/AbstractJwtBearerGrant.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/AbstractJwtBearerGrant.java new file mode 100644 index 0000000..b1ec482 --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/AbstractJwtBearerGrant.java @@ -0,0 +1,69 @@ +/** + * 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.jwt.grant; + +import javax.ws.rs.core.MultivaluedMap; + +import org.apache.cxf.jaxrs.impl.MetadataMap; +import org.apache.cxf.rs.security.oauth2.common.AccessTokenGrant; +import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException; +import org.apache.cxf.rs.security.oauth2.utils.Base64UrlUtility; +import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants; + +public abstract class AbstractJwtBearerGrant implements AccessTokenGrant { + private static final long serialVersionUID = 5754722119855372511L; + private String assertion; + private String scope; + private boolean encoded; + private String grantType; + protected AbstractJwtBearerGrant(String grantType, String assertion, boolean encoded, String scope) { + this.grantType = grantType; + this.assertion = assertion; + this.encoded = encoded; + this.scope = scope; + } + + public String getType() { + return grantType; + } + + protected MultivaluedMap<String, String> initMap() { + MultivaluedMap<String, String> map = new MetadataMap<String, String>(); + map.putSingle(OAuthConstants.GRANT_TYPE, grantType); + return map; + } + + protected void addScope(MultivaluedMap<String, String> map) { + if (scope != null) { + map.putSingle(OAuthConstants.SCOPE, scope); + } + } + + protected String encodeAssertion() { + if (encoded) { + return assertion; + } + + try { + return Base64UrlUtility.encode(assertion); + } catch (Exception ex) { + throw new OAuthServiceException(ex.getMessage(), ex); + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/71a43b94/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtBearerClientCredentialsGrant.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtBearerClientCredentialsGrant.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtBearerClientCredentialsGrant.java new file mode 100644 index 0000000..de6b0a4 --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtBearerClientCredentialsGrant.java @@ -0,0 +1,41 @@ +/** + * 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.jwt.grant; + +import javax.ws.rs.core.MultivaluedMap; + +import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants; + +public class JwtBearerClientCredentialsGrant extends AbstractJwtBearerGrant { + + private static final long serialVersionUID = 4801583498206813025L; + + public JwtBearerClientCredentialsGrant(String assertion, boolean encoded, String scope) { + super(OAuthConstants.CLIENT_CREDENTIALS_GRANT, assertion, encoded, scope); + } + + public MultivaluedMap<String, String> toMap() { + MultivaluedMap<String, String> map = initMap(); + map.putSingle(Constants.CLIENT_AUTH_ASSERTION_TYPE, Constants.CLIENT_AUTH_JWT_BEARER); + map.putSingle(Constants.CLIENT_AUTH_ASSERTION_PARAM, encodeAssertion()); + addScope(map); + return map; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/71a43b94/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtBearerGrant.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtBearerGrant.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtBearerGrant.java new file mode 100644 index 0000000..798e247 --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtBearerGrant.java @@ -0,0 +1,48 @@ +/** + * 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.jwt.grant; + +import javax.ws.rs.core.MultivaluedMap; + +public class JwtBearerGrant extends AbstractJwtBearerGrant { + private static final long serialVersionUID = -7296527609343431294L; + + public JwtBearerGrant(String assertion) { + this(assertion, false); + } + + public JwtBearerGrant(String assertion, boolean encoded) { + this(assertion, false, null); + } + + public JwtBearerGrant(String assertion, String scope) { + this(assertion, false, scope); + } + + public JwtBearerGrant(String assertion, boolean encoded, String scope) { + super(Constants.JWT_BEARER_GRANT, assertion, encoded, scope); + } + + public MultivaluedMap<String, String> toMap() { + MultivaluedMap<String, String> map = initMap(); + map.putSingle(Constants.CLIENT_GRANT_ASSERTION_PARAM, encodeAssertion()); + addScope(map); + return map; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/71a43b94/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtUserSubject.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtUserSubject.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtUserSubject.java new file mode 100644 index 0000000..fae1140 --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/grant/JwtUserSubject.java @@ -0,0 +1,34 @@ +/** + * 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.jwt.grant; + +import org.apache.cxf.rs.security.oauth2.common.UserSubject; +import org.apache.cxf.rs.security.oauth2.jwt.JwtToken; + +public class JwtUserSubject extends UserSubject { + private static final long serialVersionUID = -1135272749329239037L; + private JwtToken token; + public JwtUserSubject(String user, JwtToken token) { + super(user); + this.token = token; + } + public JwtToken getToken() { + return token; + } +}
