1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.amber.oauth2.ext.dynamicreg.server.validator;
23
24 import org.apache.amber.oauth2.common.OAuth;
25 import org.apache.amber.oauth2.common.exception.OAuthProblemException;
26 import org.apache.amber.oauth2.common.utils.OAuthUtils;
27 import org.apache.amber.oauth2.common.validators.AbstractValidator;
28 import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
29 import org.apache.amber.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38 public class PushPullValidator extends AbstractValidator<JSONHttpServletRequestWrapper> {
39
40 private Logger log = LoggerFactory.getLogger(PushPullValidator.class);
41
42 public PushPullValidator() {
43
44 }
45
46 public void validateContentType(JSONHttpServletRequestWrapper request) throws OAuthProblemException {
47
48 String contentType = request.getContentType();
49 final String expectedContentType = OAuth.ContentType.JSON;
50 if (!OAuthUtils.hasContentType(contentType, expectedContentType)) {
51 throw OAuthUtils.handleBadContentTypeException(expectedContentType);
52 }
53
54
55 initializeValidationParameter(request);
56
57 }
58
59 private void initializeValidationParameter(JSONHttpServletRequestWrapper request)
60 throws OAuthProblemException {
61 final String requestType = request.getParameter(OAuthRegistration.Request.TYPE);
62
63 if (OAuthUtils.isEmpty(requestType)) {
64 throw OAuthUtils.handleOAuthProblemException("Missing [type] parameter value");
65 }
66
67 if (OAuthRegistration.Type.PULL.equals(requestType)) {
68 requiredParams.add(OAuthRegistration.Request.TYPE);
69 requiredParams.add(OAuthRegistration.Request.CLIENT_URL);
70 } else if (OAuthRegistration.Type.PUSH.equals(requestType)) {
71 requiredParams.add(OAuthRegistration.Request.TYPE);
72 requiredParams.add(OAuthRegistration.Request.CLIENT_NAME);
73 requiredParams.add(OAuthRegistration.Request.CLIENT_URL);
74 requiredParams.add(OAuthRegistration.Request.CLIENT_DESCRIPTION);
75 requiredParams.add(OAuthRegistration.Request.REDIRECT_URL);
76 } else {
77 throw OAuthUtils.handleOAuthProblemException("Invalid [type] parameter value");
78 }
79
80 if (log.isDebugEnabled()) {
81 log.debug("OAuth dynamic client registration type is: {}", new String[] {requestType});
82 }
83 }
84 }