ilgrosso commented on a change in pull request #196: URL: https://github.com/apache/syncope/pull/196#discussion_r439267576
########## File path: core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCJWKSDataBinderImpl.java ########## @@ -0,0 +1,68 @@ +/* + * 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.syncope.core.provisioning.java.data; + +import com.nimbusds.jose.jwk.JWKSet; +import com.nimbusds.jose.jwk.KeyUse; +import com.nimbusds.jose.jwk.RSAKey; +import com.nimbusds.jose.jwk.gen.RSAKeyGenerator; +import org.apache.syncope.common.lib.to.OIDCJWKSTO; +import org.apache.syncope.core.persistence.api.entity.EntityFactory; +import org.apache.syncope.core.persistence.api.entity.auth.OIDCJWKS; +import org.apache.syncope.core.provisioning.api.data.OIDCJWKSDataBinder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +public class OIDCJWKSDataBinderImpl implements OIDCJWKSDataBinder { + @Autowired + private EntityFactory entityFactory; + + @Override + public OIDCJWKSTO get(final OIDCJWKS jwks) { + return new OIDCJWKSTO.Builder(). + json(jwks.getJson()). + key(jwks.getKey()). + build(); + } + + @Override + public OIDCJWKS create() { + try { + OIDCJWKS jwks = entityFactory.newEntity(OIDCJWKS.class); + RSAKey jwk = new RSAKeyGenerator(2048) + .keyUse(KeyUse.SIGNATURE) + .keyID(UUID.randomUUID().toString()) Review comment: Do not use `UUID.randomUUID().toString()` but `SecureRandomUtils.generateRandomUUID()` ########## File path: core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/auth/JPAOIDCJWKSDAO.java ########## @@ -0,0 +1,60 @@ +/* + * 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.syncope.core.persistence.jpa.dao.auth; + +import org.apache.syncope.core.persistence.api.dao.auth.OIDCJWKSDAO; +import org.apache.syncope.core.persistence.api.entity.auth.OIDCJWKS; +import org.apache.syncope.core.persistence.jpa.dao.AbstractDAO; +import org.apache.syncope.core.persistence.jpa.entity.auth.JPAOIDCJWKS; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.NoResultException; +import javax.persistence.TypedQuery; + +import java.util.Optional; + +@Repository +public class JPAOIDCJWKSDAO extends AbstractDAO<OIDCJWKS> implements OIDCJWKSDAO { + + @Transactional(readOnly = true) + @Override + public Optional<OIDCJWKS> get() { + try { + TypedQuery<OIDCJWKS> query = entityManager(). + createQuery("SELECT e FROM " + JPAOIDCJWKS.class.getSimpleName() + " e", OIDCJWKS.class); + return Optional.of(query.getSingleResult()); Review comment: The equivalent methods from other DAOs are not returning `Optional` but something that can be `null`. I recognize the advantages of such approach, but I think we should also keep consistency. We could consider a future PR involving all DAOs. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
