Repository: cxf Updated Branches: refs/heads/master 92c234306 -> b24261500
Prototyping DynamicClientReg service support in OAuth2/OIDC Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/b2426150 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b2426150 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b2426150 Branch: refs/heads/master Commit: b24261500fef7be8e68ac5afebd97c620bb2cc31 Parents: 92c2343 Author: Sergey Beryozkin <[email protected]> Authored: Tue Aug 23 17:45:26 2016 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Tue Aug 23 17:45:26 2016 +0100 ---------------------------------------------------------------------- .../cxf/jaxrs/json/basic/JsonMapObject.java | 11 ++ .../services/ClientRegistrationRequest.java | 124 +++++++++++++++++++ .../services/ClientRegistrationResponse.java | 82 ++++++++++++ .../services/DynamicRegistrationService.java | 97 +++++++++++++++ .../oidc/idp/OidcClientRegistrationRequest.java | 27 ++++ .../idp/OidcDynamicRegistrationService.java | 26 ++++ 6 files changed, 367 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/b2426150/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObject.java ---------------------------------------------------------------------- diff --git a/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObject.java b/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObject.java index f9c1025..8c4fc85 100644 --- a/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObject.java +++ b/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObject.java @@ -22,8 +22,11 @@ package org.apache.cxf.jaxrs.json.basic; import java.io.Serializable; import java.util.Collections; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import org.apache.cxf.helpers.CastUtils; + public class JsonMapObject implements Serializable { private static final long serialVersionUID = 2620765136328623790L; Map<String, Integer> updateCount; @@ -91,6 +94,14 @@ public class JsonMapObject implements Serializable { return null; } } + public List<String> getListStringProperty(String name) { + Object value = getProperty(name); + if (value != null) { + return CastUtils.cast((List<?>)value); + } else { + return null; + } + } public int hashCode() { return values.hashCode(); } http://git-wip-us.apache.org/repos/asf/cxf/blob/b2426150/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ClientRegistrationRequest.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ClientRegistrationRequest.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ClientRegistrationRequest.java new file mode 100644 index 0000000..d899343 --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ClientRegistrationRequest.java @@ -0,0 +1,124 @@ +/** + * 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.services; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.cxf.jaxrs.json.basic.JsonMapObject; +import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants; + +public class ClientRegistrationRequest extends JsonMapObject { + public static final String REDIRECT_URIS = "redirect_uris"; + public static final String RESPONSE_TYPES = "response_types"; + public static final String GRANT_TYPES = "grant_types"; + public static final String APPLICATION_TYPE = "application_type"; + public static final String CONTACTS = "contacts"; + public static final String CLIENT_NAME = "client_name"; + public static final String LOGO_URI = "logo_uri"; + public static final String CLIENT_URI = "client_uri"; + public static final String POLICY_URI = "policy_uri"; + public static final String TOS_URI = "tos_uri"; + public static final String TOKEN_ENDPOINT_AUTH_METHOD = "token_endpoint_auth_method"; + public static final String SCOPE = OAuthConstants.SCOPE; + + private static final long serialVersionUID = 7903976943604132150L; + + public ClientRegistrationRequest() { + } + + public ClientRegistrationRequest(Map<String, Object> props) { + super(new LinkedHashMap<String, Object>(props)); + } + + public void setRedirectUris(List<String> redirectUris) { + super.setProperty(REDIRECT_URIS, redirectUris); + } + public List<String> getRedirectUris() { + return getListStringProperty(REDIRECT_URIS); + } + public void setResponseTypes(List<String> responseTypes) { + super.setProperty(RESPONSE_TYPES, responseTypes); + } + public List<String> getResponseTypes() { + return getListStringProperty(RESPONSE_TYPES); + } + public void setGrantTypes(List<String> grantTypes) { + super.setProperty(GRANT_TYPES, grantTypes); + } + public List<String> getGrantTypes() { + return getListStringProperty(GRANT_TYPES); + } + public void setApplicationType(String applicationType) { + super.setProperty(APPLICATION_TYPE, applicationType); + } + public String getApplicationType() { + return getStringProperty(APPLICATION_TYPE); + } + public void setContacts(List<String> contacts) { + super.setProperty(CONTACTS, contacts); + } + public List<String> getContacts() { + return getListStringProperty(CONTACTS); + } + public void setClientName(String clientName) { + super.setProperty(CLIENT_NAME, clientName); + } + public String getClientName() { + return getStringProperty(CLIENT_NAME); + } + public void setLogoUri(String logoUri) { + super.setProperty(LOGO_URI, logoUri); + } + public String getLogoUri() { + return getStringProperty(LOGO_URI); + } + public void setClientUri(String clientUri) { + super.setProperty(CLIENT_URI, clientUri); + } + public String getClientUri() { + return getStringProperty(CLIENT_URI); + } + public void setPolicyUri(String policyUri) { + super.setProperty(POLICY_URI, policyUri); + } + public String getPolicyUri() { + return getStringProperty(POLICY_URI); + } + public void setTosUri(String tosUri) { + super.setProperty(TOS_URI, tosUri); + } + public String getTosUri() { + return getStringProperty(TOS_URI); + } + public void setTokenEndpointAuthMethod(String method) { + super.setProperty(TOKEN_ENDPOINT_AUTH_METHOD, method); + } + public String getTokenEndpointAuthMethod() { + return getStringProperty(TOKEN_ENDPOINT_AUTH_METHOD); + } + public void setScope(String scope) { + super.setProperty(SCOPE, scope); + } + public String getScope() { + return getStringProperty(SCOPE); + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/b2426150/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ClientRegistrationResponse.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ClientRegistrationResponse.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ClientRegistrationResponse.java new file mode 100644 index 0000000..dfe43e1 --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ClientRegistrationResponse.java @@ -0,0 +1,82 @@ +/** + * 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.services; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.cxf.jaxrs.json.basic.JsonMapObject; +import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants; + +public class ClientRegistrationResponse extends JsonMapObject { + + public static final String CLIENT_ID = OAuthConstants.CLIENT_ID; + public static final String CLIENT_SECRET = OAuthConstants.CLIENT_SECRET; + public static final String REG_ACCESS_TOKEN = "registration_access_token"; + public static final String REG_CLIENT_URI = "registration_client_uri"; + public static final String CLIENT_ID_ISSUED_AT = "client_id_issued_at"; + public static final String CLIENT_SECRET_EXPIRES_AT = "client_secret_expires_at"; + + private static final long serialVersionUID = 7114757825909879652L; + + public ClientRegistrationResponse() { + } + + public ClientRegistrationResponse(Map<String, Object> props) { + super(new LinkedHashMap<String, Object>(props)); + } + + public void setClientId(String clientId) { + super.setProperty(CLIENT_ID, clientId); + } + public String getClientId() { + return getStringProperty(CLIENT_ID); + } + public void setClientSecret(String clientSecret) { + super.setProperty(CLIENT_SECRET, clientSecret); + } + public String getClientSecret() { + return getStringProperty(CLIENT_SECRET); + } + public void setRegistrationAccessToken(String at) { + super.setProperty(REG_ACCESS_TOKEN, at); + } + public String getRegistrationAccessToken() { + return getStringProperty(REG_ACCESS_TOKEN); + } + public void setRegistrationClientUri(String at) { + super.setProperty(REG_ACCESS_TOKEN, at); + } + public String getRegistrationClientUri() { + return getStringProperty(REG_CLIENT_URI); + } + public void setClientIdIssuedAt(Long issuedAt) { + super.setProperty(CLIENT_ID_ISSUED_AT, issuedAt); + } + public Long getClientIdIssuedAt() { + return getLongProperty(CLIENT_ID_ISSUED_AT); + } + public void setClientSecretExpiresAt(Long expiresAt) { + super.setProperty(CLIENT_ID_ISSUED_AT, expiresAt); + } + public Long getClientSecretExpiresAt() { + return getLongProperty(CLIENT_SECRET_EXPIRES_AT); + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/b2426150/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/DynamicRegistrationService.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/DynamicRegistrationService.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/DynamicRegistrationService.java new file mode 100644 index 0000000..130fb64 --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/DynamicRegistrationService.java @@ -0,0 +1,97 @@ +/** + * 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.services; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +import org.apache.cxf.rs.security.oauth2.provider.OAuthDataProvider; + +@Path("register") +public class DynamicRegistrationService extends AbstractOAuthService { + + private OAuthDataProvider dataProvider; + private String initialAccessToken; + + @POST + @Consumes("application/json") + @Produces("application/json") + public ClientRegistrationResponse register(ClientRegistrationRequest request) { + + return new ClientRegistrationResponse(); + } + + @GET + @Produces("application/json") + public ClientRegistrationResponse readClientRegistrationWithQuery(@QueryParam("client_id") String clientId) { + + return doReadClientRegistration(clientId); + } + + @GET + @Path("{clientId}") + @Produces("application/json") + public ClientRegistrationResponse readClientRegistrationWithPath(@PathParam("clientId") String clientId) { + + return doReadClientRegistration(clientId); + } + + @PUT + @Path("{clientId}") + @Consumes("application/json") + public Response updateClientRegistration(@PathParam("clientId") String clientId) { + return Response.ok().build(); + } + + @DELETE + @Path("{clientId}") + public Response deleteClientRegistration(@PathParam("clientId") String clientId) { + return Response.ok().build(); + } + + protected ClientRegistrationResponse doReadClientRegistration(String clientId) { + return new ClientRegistrationResponse(); + } + + public OAuthDataProvider getDataProvider() { + return dataProvider; + } + + public void setDataProvider(OAuthDataProvider dataProvider) { + this.dataProvider = dataProvider; + } + + public String getInitialAccessToken() { + return initialAccessToken; + } + + public void setRegistrationAccessToken(String registrationAccessToken) { + this.initialAccessToken = registrationAccessToken; + } + + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/b2426150/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcClientRegistrationRequest.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcClientRegistrationRequest.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcClientRegistrationRequest.java new file mode 100644 index 0000000..7a9dbe3 --- /dev/null +++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcClientRegistrationRequest.java @@ -0,0 +1,27 @@ +/** + * 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.idp; + +import org.apache.cxf.rs.security.oauth2.services.ClientRegistrationRequest; + +public class OidcClientRegistrationRequest extends ClientRegistrationRequest { + + private static final long serialVersionUID = -7941815270850562749L; + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/b2426150/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcDynamicRegistrationService.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcDynamicRegistrationService.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcDynamicRegistrationService.java new file mode 100644 index 0000000..bb9d080 --- /dev/null +++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcDynamicRegistrationService.java @@ -0,0 +1,26 @@ +/** + * 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.idp; + +import org.apache.cxf.rs.security.oauth2.services.DynamicRegistrationService; + +public class OidcDynamicRegistrationService extends DynamicRegistrationService { + + +}
