Repository: cxf Updated Branches: refs/heads/master 26f430253 -> 0c5557917
Minor update to OAuth2 Dynamic Reg service Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0c555791 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0c555791 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0c555791 Branch: refs/heads/master Commit: 0c5557917a84346840a2259f16440db47db70292 Parents: 26f4302 Author: Sergey Beryozkin <[email protected]> Authored: Wed Sep 28 11:16:13 2016 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Wed Sep 28 11:16:13 2016 +0100 ---------------------------------------------------------------------- .../services/DynamicRegistrationService.java | 15 ++- .../security/oidc/MemoryClientDataProvider.java | 55 ++++++++++ .../security/oidc/MemoryOAuthDataProvider.java | 107 ------------------- .../jaxrs/security/oidc/oidc-server-dynreg.xml | 7 +- 4 files changed, 72 insertions(+), 112 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/0c555791/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 index 090c84d..47ea3f0 100644 --- 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 @@ -30,11 +30,13 @@ 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.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import org.apache.cxf.common.util.Base64UrlUtility; import org.apache.cxf.common.util.StringUtils; +import org.apache.cxf.jaxrs.ext.MessageContext; import org.apache.cxf.jaxrs.utils.ExceptionUtils; import org.apache.cxf.rs.security.oauth2.common.Client; import org.apache.cxf.rs.security.oauth2.provider.ClientRegistrationProvider; @@ -44,12 +46,14 @@ import org.apache.cxf.rs.security.oauth2.utils.OAuthUtils; import org.apache.cxf.rt.security.crypto.CryptoUtils; @Path("register") -public class DynamicRegistrationService extends AbstractOAuthService { +public class DynamicRegistrationService { private static final String DEFAULT_APPLICATION_TYPE = "web"; private static final Integer DEFAULT_CLIENT_ID_SIZE = 10; private ClientRegistrationProvider clientProvider; private String initialAccessToken; private int clientIdSizeInBytes = DEFAULT_CLIENT_ID_SIZE; + private MessageContext mc; + @POST @Consumes("application/json") @Produces("application/json") @@ -281,4 +285,13 @@ public class DynamicRegistrationService extends AbstractOAuthService { protected int getClientSecretSizeInBytes(ClientRegistration request) { return 16; } + + @Context + public void setMessageContext(MessageContext context) { + this.mc = context; + } + + public MessageContext getMessageContext() { + return mc; + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/0c555791/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/MemoryClientDataProvider.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/MemoryClientDataProvider.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/MemoryClientDataProvider.java new file mode 100644 index 0000000..ba0b56b --- /dev/null +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/MemoryClientDataProvider.java @@ -0,0 +1,55 @@ +/** + * 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.systest.jaxrs.security.oidc; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.cxf.rs.security.oauth2.common.Client; +import org.apache.cxf.rs.security.oauth2.common.UserSubject; +import org.apache.cxf.rs.security.oauth2.provider.ClientRegistrationProvider; +import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException; + +public class MemoryClientDataProvider implements ClientRegistrationProvider { + + private Map<String, Client> clients = new HashMap<String, Client>(); + @Override + public Client getClient(String clientId) throws OAuthServiceException { + return clients.get(clientId); + } + + @Override + public void setClient(Client client) { + clients.put(client.getClientId(), client); + } + + @Override + public List<Client> getClients(UserSubject resourceOwner) { + return new ArrayList<Client>(clients.values()); + } + + + @Override + public Client removeClient(String clientId) { + return clients.remove(clientId); + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/0c555791/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/MemoryOAuthDataProvider.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/MemoryOAuthDataProvider.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/MemoryOAuthDataProvider.java deleted file mode 100644 index 01eef5f..0000000 --- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/MemoryOAuthDataProvider.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * 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.systest.jaxrs.security.oidc; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.cxf.rs.security.oauth2.common.Client; -import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken; -import org.apache.cxf.rs.security.oauth2.common.UserSubject; -import org.apache.cxf.rs.security.oauth2.provider.AbstractOAuthDataProvider; -import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException; -import org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken; - -public class MemoryOAuthDataProvider extends AbstractOAuthDataProvider { - - private Map<String, Client> clients = new HashMap<String, Client>(); - @Override - public Client getClient(String clientId) throws OAuthServiceException { - return clients.get(clientId); - } - - @Override - public ServerAccessToken getAccessToken(String accessToken) throws OAuthServiceException { - // TODO Auto-generated method stub - return null; - } - - @Override - public List<ServerAccessToken> getAccessTokens(Client client, UserSubject subject) - throws OAuthServiceException { - // TODO Auto-generated method stub - return null; - } - - @Override - public List<RefreshToken> getRefreshTokens(Client client, UserSubject subject) - throws OAuthServiceException { - // TODO Auto-generated method stub - return null; - } - - @Override - public void setClient(Client client) { - clients.put(client.getClientId(), client); - } - - @Override - public List<Client> getClients(UserSubject resourceOwner) { - return new ArrayList<Client>(clients.values()); - } - - @Override - protected void saveAccessToken(ServerAccessToken serverToken) { - // TODO Auto-generated method stub - - } - - @Override - protected void saveRefreshToken(RefreshToken refreshToken) { - // TODO Auto-generated method stub - - } - - @Override - protected void doRevokeAccessToken(ServerAccessToken accessToken) { - // TODO Auto-generated method stub - - } - - @Override - protected void doRevokeRefreshToken(RefreshToken refreshToken) { - // TODO Auto-generated method stub - - } - - @Override - protected RefreshToken getRefreshToken(String refreshTokenKey) { - // TODO Auto-generated method stub - return null; - } - - @Override - protected void doRemoveClient(Client c) { - clients.remove(c.getClientId()); - - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/0c555791/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oidc/oidc-server-dynreg.xml ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oidc/oidc-server-dynreg.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oidc/oidc-server-dynreg.xml index 55a6cb4..ed248ce 100644 --- a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oidc/oidc-server-dynreg.xml +++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oidc/oidc-server-dynreg.xml @@ -62,14 +62,13 @@ under the License. </httpj:engine> </httpj:engine-factory> - <bean id="oauthProvider" class="org.apache.cxf.systest.jaxrs.security.oidc.MemoryOAuthDataProvider"> - </bean> + <bean id="clientProvider" class="org.apache.cxf.systest.jaxrs.security.oidc.MemoryClientDataProvider"/> <bean id="dynRegService" class="org.apache.cxf.rs.security.oidc.idp.OidcDynamicRegistrationService"> - <property name="clientProvider" ref="oauthProvider"/> + <property name="clientProvider" ref="clientProvider"/> </bean> <bean id="dynRegServiceWithAt" class="org.apache.cxf.rs.security.oidc.idp.OidcDynamicRegistrationService"> - <property name="clientProvider" ref="oauthProvider"/> + <property name="clientProvider" ref="clientProvider"/> <property name="initialAccessToken" value="123456789"/> </bean>
