Author: sergeyb
Date: Wed Dec 5 11:16:00 2012
New Revision: 1417360
URL: http://svn.apache.org/viewvc?rev=1417360&view=rev
Log:
[CXF-4675] Introducing SubjectCreator interface for users be able to customize
the user subject creation 'closer' to the data
Added:
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/SubjectCreator.java
(with props)
Modified:
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/RedirectionBasedGrantService.java
Added:
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/SubjectCreator.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/SubjectCreator.java?rev=1417360&view=auto
==============================================================================
---
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/SubjectCreator.java
(added)
+++
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/SubjectCreator.java
Wed Dec 5 11:16:00 2012
@@ -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.oauth2.provider;
+
+import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.rs.security.oauth2.common.UserSubject;
+
+/**
+ * Optional provider responsible for creating
+ * resource owner subject representations
+ */
+public interface SubjectCreator {
+
+
+ /**
+ * Create a {@link UserSubject}
+ * @param mc the {@link MessageContext} of this request
+ * @return {@link UserSubject}
+ * @throws OAuthServiceException
+ */
+ UserSubject createUserSubject(MessageContext mc) throws
OAuthServiceException;
+}
Propchange:
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/SubjectCreator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/SubjectCreator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/RedirectionBasedGrantService.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/RedirectionBasedGrantService.java?rev=1417360&r1=1417359&r2=1417360&view=diff
==============================================================================
---
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/RedirectionBasedGrantService.java
(original)
+++
cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/RedirectionBasedGrantService.java
Wed Dec 5 11:16:00 2012
@@ -43,6 +43,7 @@ import org.apache.cxf.rs.security.oauth2
import org.apache.cxf.rs.security.oauth2.common.UserSubject;
import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException;
import
org.apache.cxf.rs.security.oauth2.provider.SessionAuthenticityTokenProvider;
+import org.apache.cxf.rs.security.oauth2.provider.SubjectCreator;
import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants;
import org.apache.cxf.rs.security.oauth2.utils.OAuthUtils;
import org.apache.cxf.security.SecurityContext;
@@ -56,6 +57,7 @@ public abstract class RedirectionBasedGr
private String supportedGrantType;
private boolean isClientConfidential;
private SessionAuthenticityTokenProvider sessionAuthenticityTokenProvider;
+ private SubjectCreator subjectCreator;
protected RedirectionBasedGrantService(String supportedResponseType,
String supportedGrantType,
@@ -242,8 +244,20 @@ public abstract class RedirectionBasedGr
this.sessionAuthenticityTokenProvider =
sessionAuthenticityTokenProvider;
}
+ public void setSubjectCreator(SubjectCreator creator) {
+ this.subjectCreator = creator;
+ }
+
protected UserSubject createUserSubject(SecurityContext securityContext) {
- UserSubject subject =
getMessageContext().getContent(UserSubject.class);
+ UserSubject subject = null;
+ if (subjectCreator != null) {
+ subject = subjectCreator.createUserSubject(getMessageContext());
+ if (subject != null) {
+ return subject;
+ }
+ }
+
+ subject = getMessageContext().getContent(UserSubject.class);
if (subject != null) {
return subject;
} else {