001/******************************************************************************* 002 * Copyright 2018 The MIT Internet Trust Consortium 003 * 004 * Portions copyright 2011-2013 The MITRE Corporation 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 *******************************************************************************/ 018package org.mitre.openid.connect.service.impl; 019 020import java.util.Collection; 021 022import org.mitre.openid.connect.model.WhitelistedSite; 023import org.mitre.openid.connect.repository.WhitelistedSiteRepository; 024import org.mitre.openid.connect.service.WhitelistedSiteService; 025import org.springframework.beans.factory.annotation.Autowired; 026import org.springframework.stereotype.Service; 027import org.springframework.transaction.annotation.Transactional; 028 029/** 030 * Implementation of the WhitelistedSiteService 031 * 032 * @author Michael Joseph Walsh, aanganes 033 * 034 */ 035@Service 036@Transactional(value="defaultTransactionManager") 037public class DefaultWhitelistedSiteService implements WhitelistedSiteService { 038 039 @Autowired 040 private WhitelistedSiteRepository repository; 041 042 @Override 043 public WhitelistedSite getById(Long id) { 044 return repository.getById(id); 045 } 046 047 @Override 048 public void remove(WhitelistedSite whitelistedSite) { 049 repository.remove(whitelistedSite); 050 } 051 052 @Override 053 public WhitelistedSite saveNew(WhitelistedSite whitelistedSite) { 054 if (whitelistedSite.getId() != null) { 055 throw new IllegalArgumentException("A new whitelisted site cannot be created with an id value already set: " + whitelistedSite.getId()); 056 } 057 return repository.save(whitelistedSite); 058 } 059 060 @Override 061 public Collection<WhitelistedSite> getAll() { 062 return repository.getAll(); 063 } 064 065 @Override 066 public WhitelistedSite getByClientId(String clientId) { 067 return repository.getByClientId(clientId); 068 } 069 070 @Override 071 public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite) { 072 if (oldWhitelistedSite == null || whitelistedSite == null) { 073 throw new IllegalArgumentException("Neither the old or new sites may be null"); 074 } 075 return repository.update(oldWhitelistedSite, whitelistedSite); 076 } 077 078}