functioning resource set repository layer
parent
efeead52b6
commit
3076da1ed8
|
@ -97,7 +97,7 @@ public class ResourceSet {
|
|||
* @return the type
|
||||
*/
|
||||
@Basic
|
||||
@Column(name = "type")
|
||||
@Column(name = "rs_type")
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*******************************************************************************/
|
||||
package org.mitre.openid.connect.service;
|
||||
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* Manage registered resource sets at this authorization server.
|
||||
|
@ -25,4 +27,6 @@ package org.mitre.openid.connect.service;
|
|||
*/
|
||||
public interface ResourceSetService {
|
||||
|
||||
public ResourceSet saveNew(ResourceSet rs);
|
||||
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ CREATE TABLE IF NOT EXISTS resource_set (
|
|||
name VARCHAR(1024),
|
||||
uri VARCHAR(1024),
|
||||
icon_uri VARCHAR(1024),
|
||||
policy_uri VARCHAR(1024),
|
||||
rs_type VARCHAR(256),
|
||||
owner VARCHAR(256)
|
||||
);
|
||||
|
||||
|
|
|
@ -117,11 +117,10 @@
|
|||
<security:intercept-url pattern="/resource/**" access="permitAll"/>
|
||||
</security:http>
|
||||
|
||||
<security:http pattern="#{T(org.mitre.openid.connect.web.ResourceSetRegistrationEndpoint).URL}/**" use-expressions="true" entry-point-ref="oauthAuthenticationEntryPoint" create-session="stateless">
|
||||
<security:http pattern="#{T(org.mitre.openid.connect.web.ResourceSetRegistrationEndpoint).URL}/**" use-expressions="true" entry-point-ref="oauthAuthenticationEntryPoint" create-session="never">
|
||||
<security:custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
|
||||
<security:custom-filter ref="corsFilter" after="SECURITY_CONTEXT_FILTER" />
|
||||
<security:expression-handler ref="oauthWebExpressionHandler" />
|
||||
<security:intercept-url pattern="/resource/**" access="permitAll"/>
|
||||
</security:http>
|
||||
|
||||
<security:http pattern="/userinfo**" use-expressions="true" entry-point-ref="oauthAuthenticationEntryPoint" create-session="stateless">
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2015 The MITRE Corporation
|
||||
* and the MIT Kerberos and Internet Trust Consortium
|
||||
*
|
||||
* 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.mitre.openid.connect.repository;
|
||||
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
|
||||
/**
|
||||
* @author jricher
|
||||
*
|
||||
*/
|
||||
public interface ResourceSetRepository {
|
||||
|
||||
public ResourceSet save(ResourceSet rs);
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2015 The MITRE Corporation
|
||||
* and the MIT Kerberos and Internet Trust Consortium
|
||||
*
|
||||
* 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.mitre.openid.connect.repository.impl;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
import org.mitre.openid.connect.repository.ResourceSetRepository;
|
||||
import org.mitre.util.jpa.JpaUtil;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author jricher
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class JpaResourceSetRepository implements ResourceSetRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResourceSet save(ResourceSet rs) {
|
||||
return JpaUtil.saveOrUpdate(rs.getId(), em, rs);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,10 @@
|
|||
|
||||
package org.mitre.openid.connect.service.impl;
|
||||
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
import org.mitre.openid.connect.repository.ResourceSetRepository;
|
||||
import org.mitre.openid.connect.service.ResourceSetService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
@ -27,4 +30,22 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class DefaultResourceSetService implements ResourceSetService {
|
||||
|
||||
@Autowired
|
||||
private ResourceSetRepository repository;
|
||||
|
||||
@Override
|
||||
public ResourceSet saveNew(ResourceSet rs) {
|
||||
|
||||
if (rs.getId() != null) {
|
||||
throw new IllegalArgumentException("Can't save a new resource set with an ID already set to it.");
|
||||
}
|
||||
|
||||
ResourceSet saved = repository.save(rs);
|
||||
|
||||
return saved;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,10 +40,10 @@ import com.google.gson.JsonElement;
|
|||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(ResourceSetRegistrationEndpoint.URL)
|
||||
@PreAuthorize("hasRole('ROLE_USER')")
|
||||
public class ResourceSetRegistrationEndpoint {
|
||||
|
||||
public static final String URL = "/resource_set/resource_set";
|
||||
|
@ -54,7 +54,6 @@ public class ResourceSetRegistrationEndpoint {
|
|||
private JsonParser parser = new JsonParser();
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, produces = MimeTypeUtils.APPLICATION_JSON_VALUE, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE)
|
||||
@PreAuthorize("hasRole('ROLE_USER')")
|
||||
public String createResourceSet(@RequestBody String jsonString, Model m, Authentication auth) {
|
||||
|
||||
// if auth is OAuth, make sure we've got the right scope
|
||||
|
@ -80,8 +79,10 @@ public class ResourceSetRegistrationEndpoint {
|
|||
|
||||
rs.setOwner(auth.getName());
|
||||
|
||||
ResourceSet saved = resourceSetService.saveNew(rs);
|
||||
|
||||
m.addAttribute("code", HttpStatus.CREATED);
|
||||
m.addAttribute("entity", rs);
|
||||
m.addAttribute("entity", saved);
|
||||
return ResourceSetEntityView.VIEWNAME;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue