Skip to content

Commit

Permalink
Cleaned some checkstyle violations, build still failing
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Jul 1, 2013
1 parent f43fba0 commit 8b8b33f
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 111 deletions.
33 changes: 20 additions & 13 deletions pom.xml
Expand Up @@ -18,6 +18,11 @@
<artifactId>fcrepo-http-api</artifactId>
<groupId>org.fcrepo</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.authzserver</artifactId>
<version>${oltu.version}</version>
<exclusions>
<!-- Dependency convergence: fcrepo-http-api (via jersey-json:1.17.1) depends
on jettison:1.1, but org.apache.oltu.oauth2.authzserver depends on jettison:1.2 -->
Expand All @@ -33,15 +38,25 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.authzserver</artifactId>
<version>${oltu.version}</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>oltu-oauth2-resourceserver-filter</artifactId>
<version>${oltu.version}</version>
<exclusions>
<!-- Dependency convergence: fcrepo-http-api (via jersey-json:1.17.1)
depends on jettison:1.1, but org.apache.oltu.oauth2.authzserver depends on
jettison:1.2 -->
<exclusion>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
</exclusion>
<!-- Dependency convergence: fcrepo-http-api (via fcrepo-jcr) depends
on commons-codec:1.6, but org.apache.oltu.oauth2.authzserver depends on commons-codec:1.8 -->
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- test gear -->
<dependency>
Expand All @@ -50,14 +65,6 @@
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
<exclusions>
<!-- Dependency convergence: fcrepo-kernel depends on commons-codec:1.6,
but org.apache.oltu.oauth2.authzserver depends on commons-codec:1.8 -->
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/org/fcrepo/auth/oauth/Decision.java
@@ -1,17 +1,12 @@
/**
* Copyright 2013 DuraSpace, Inc.
*
* Licensed 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.
* Copyright 2013 DuraSpace, Inc. Licensed 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.fcrepo.auth.oauth;
Expand All @@ -21,6 +16,10 @@
import org.apache.oltu.oauth2.rsfilter.OAuthClient;
import org.apache.oltu.oauth2.rsfilter.OAuthDecision;

/**
* @author ajs6f
* @date Jul 1, 2013
*/
public class Decision implements OAuthDecision {

private OAuthClient oAuthClient;
Expand Down
@@ -1,22 +1,20 @@
/**
* Copyright 2013 DuraSpace, Inc.
*
* Licensed 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.
* Copyright 2013 DuraSpace, Inc. Licensed 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.fcrepo.auth.oauth;

import static com.google.common.base.Throwables.propagate;
import static org.fcrepo.auth.oauth.Constants.CLIENT_PROPERTY;
import static org.fcrepo.auth.oauth.Constants.OAUTH_WORKSPACE;
import static org.fcrepo.auth.oauth.Constants.PRINCIPAL_PROPERTY;
import static org.slf4j.LoggerFactory.getLogger;

import javax.jcr.Node;
Expand All @@ -33,8 +31,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static org.fcrepo.auth.oauth.Constants.*;

/**
* @author ajs6f
* @date Jul 1, 2013
*/
@Component
public class DefaultOAuthResourceProvider implements OAuthRSProvider {

Expand All @@ -44,6 +44,12 @@ public class DefaultOAuthResourceProvider implements OAuthRSProvider {
private static final Logger LOGGER =
getLogger(DefaultOAuthResourceProvider.class);

/*
* (non-Javadoc)
* @see
* org.apache.oltu.oauth2.rsfilter.OAuthRSProvider#validateRequest(java.
* lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
*/
@Override
public OAuthDecision validateRequest(final String rsId, final String token,
final HttpServletRequest req) throws OAuthProblemException {
Expand Down
49 changes: 35 additions & 14 deletions src/main/java/org/fcrepo/auth/oauth/api/AuthzEndpoint.java
@@ -1,17 +1,12 @@
/**
* Copyright 2013 DuraSpace, Inc.
*
* Licensed 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.
* Copyright 2013 DuraSpace, Inc. Licensed 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.fcrepo.auth.oauth.api;
Expand Down Expand Up @@ -58,12 +53,24 @@
import static org.fcrepo.auth.oauth.api.Util.createOauthWorkspace;
import static org.slf4j.LoggerFactory.getLogger;

/**
* @author ajs6f
* @date Jul 1, 2013
*/
@Component
@Path("/authorization")
public class AuthzEndpoint extends AbstractResource {

private static final Logger LOGGER = getLogger(AuthzEndpoint.class);

/**
* @param request An HTTP request
* @return An authorization code for later use with the
* {@link TokenEndpoint}
* @throws URISyntaxException
* @throws OAuthSystemException
* @throws RepositoryException
*/
@GET
public Response getAuthorization(@Context
final HttpServletRequest request) throws URISyntaxException,
Expand Down Expand Up @@ -114,7 +121,7 @@ public Response getAuthorization(@Context

if (isEmpty(redirectUri)) {
throw new WebApplicationException(responseBuilder.entity(
"OAuth callback url needs to be provided by client!!!")
"OAuth callback url needs to be provided by client!")
.build());
}
final OAuthResponse response =
Expand All @@ -125,6 +132,14 @@ public Response getAuthorization(@Context
}
}

/**
* Saves an authorization code for later retrieval at the token endpoint.
*
* @param authCode
* @param scopes
* @param client
* @throws RepositoryException
*/
private void saveAuthCode(final String authCode, final Set<String> scopes,
final String client) throws RepositoryException {
final Session session = sessions.getSession(OAUTH_WORKSPACE);
Expand All @@ -142,6 +157,12 @@ private void saveAuthCode(final String authCode, final Set<String> scopes,

}

/**
* Ensures the existence of the workspace into which authorization codes are
* stored.
*
* @throws RepositoryException
*/
@PostConstruct
public void init() throws RepositoryException {
createOauthWorkspace(sessions);
Expand Down
48 changes: 34 additions & 14 deletions src/main/java/org/fcrepo/auth/oauth/api/TokenEndpoint.java
@@ -1,17 +1,12 @@
/**
* Copyright 2013 DuraSpace, Inc.
*
* Licensed 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.
* Copyright 2013 DuraSpace, Inc. Licensed 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.fcrepo.auth.oauth.api;
Expand All @@ -35,6 +30,7 @@
import static org.fcrepo.auth.oauth.api.Util.createOauthWorkspace;
import static org.slf4j.LoggerFactory.getLogger;

import java.security.AccessControlException;
import java.util.Set;

import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -64,6 +60,10 @@
import org.slf4j.Logger;
import org.springframework.stereotype.Component;

/**
* @author ajs6f
* @date Jul 1, 2013
*/
@Component
@Path("/token")
public class TokenEndpoint extends AbstractResource {
Expand All @@ -73,6 +73,12 @@ public class TokenEndpoint extends AbstractResource {

private static final Logger LOGGER = getLogger(TokenEndpoint.class);

/**
* @param request An HTTP request
* @return A token-bearing HTTP response
* @throws OAuthSystemException
* @throws RepositoryException
*/
@POST
@Consumes(APPLICATION_FORM_URLENCODED)
@Produces(APPLICATION_JSON)
Expand Down Expand Up @@ -165,6 +171,12 @@ public Response getToken(@Context
}
}

/**
* @param oauthRequest
* @return An answer to whether or not this request matches up with an
* authorization code issued at the {@link AuthzEndpoint}
* @throws RepositoryException
*/
private boolean isValidAuthCode(final OAuthTokenRequest oauthRequest)
throws RepositoryException {
final String client = oauthRequest.getClientId();
Expand Down Expand Up @@ -195,11 +207,19 @@ private boolean isValidAuthCode(final OAuthTokenRequest oauthRequest)
} finally {
session.logout();
}
throw new RuntimeException(
throw new AccessControlException(
"Could not establish validity or invalidity of authorization code! Code:" +
code);
}

/**
* Stores a token for later use by the configured {@link OAuthRSProvider}
*
* @param token
* @param client
* @param username
* @throws RepositoryException
*/
private void saveToken(final String token, final String client,
final String username) throws RepositoryException {
final Session session = sessions.getSession(OAUTH_WORKSPACE);
Expand Down
31 changes: 18 additions & 13 deletions src/main/java/org/fcrepo/auth/oauth/api/Util.java
@@ -1,17 +1,12 @@
/**
* Copyright 2013 DuraSpace, Inc.
*
* Licensed 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.
* Copyright 2013 DuraSpace, Inc. Licensed 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.fcrepo.auth.oauth.api;
Expand All @@ -24,8 +19,18 @@

import org.fcrepo.session.SessionFactory;

/**
* @author ajs6f
* @date Jul 1, 2013
*/
public class Util {

/**
* Ensures that the workspace in which we store OAuth info exists.
*
* @param sessionFactory
* @throws RepositoryException
*/
public static void
createOauthWorkspace(final SessionFactory sessionFactory)
throws RepositoryException {
Expand Down

0 comments on commit 8b8b33f

Please sign in to comment.