Commit 1caf996e authored by michael.simon's avatar michael.simon
Browse files

Add functions to ssh key controller

parent 4160a796
package edu.kit.scc.webreg.dto.entity;
public class SshKeyEntityDto extends AbstractBaseEntityDto {
private static final long serialVersionUID = 1L;
}
package edu.kit.scc.webreg.dto.entity;
import edu.kit.scc.webreg.entity.SshPubKeyUsageType;
public class SshPubKeyEntityDto extends AbstractBaseEntityDto {
private static final long serialVersionUID = 1L;
private String name;
private String command;
private String from;
private String keyType;
private String encodedKey;
private String comment;
private SshPubKeyUsageType usageType;
public String getCommand() {
return command;
}
public void setCommand(String command) {
this.command = command;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getKeyType() {
return keyType;
}
public void setKeyType(String keyType) {
this.keyType = keyType;
}
public String getEncodedKey() {
return encodedKey;
}
public void setEncodedKey(String encodedKey) {
this.encodedKey = encodedKey;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public SshPubKeyUsageType getUsageType() {
return usageType;
}
public void setUsageType(SshPubKeyUsageType usageType) {
this.usageType = usageType;
}
}
package edu.kit.scc.webreg.dto.mapper;
import javax.enterprise.context.ApplicationScoped;
import edu.kit.scc.webreg.dto.entity.SshPubKeyEntityDto;
import edu.kit.scc.webreg.entity.SshPubKeyEntity;
@ApplicationScoped
public class SshPubKeyEntityMapper extends AbstractBaseEntityMapper<SshPubKeyEntity, SshPubKeyEntityDto, Long> {
private static final long serialVersionUID = 1L;
@Override
protected void copyAllProperties(SshPubKeyEntity fromBaseEntity,
SshPubKeyEntityDto toDtoEntity) {
}
@Override
public Class<SshPubKeyEntityDto> getEntityDtoClass() {
return SshPubKeyEntityDto.class;
}
@Override
protected String[] getPropertiesToCopy() {
return new String[] { "name", "command",
"from", "comment", "encodedKey", "keyType"};
}
}
package edu.kit.scc.webreg.dto.service;
import java.util.List;
import edu.kit.scc.webreg.dto.entity.SshPubKeyEntityDto;
import edu.kit.scc.webreg.entity.SshPubKeyEntity;
import edu.kit.scc.webreg.exc.RestInterfaceException;
public interface SshPubKeyDtoService extends BaseDtoService<SshPubKeyEntity, SshPubKeyEntityDto, Long> {
List<SshPubKeyEntityDto> findByUidNumber(Long uidNumber) throws RestInterfaceException;
}
package edu.kit.scc.webreg.dto.service;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.SshPubKeyDao;
import edu.kit.scc.webreg.dao.UserDao;
import edu.kit.scc.webreg.dto.entity.SshPubKeyEntityDto;
import edu.kit.scc.webreg.dto.mapper.BaseEntityMapper;
import edu.kit.scc.webreg.dto.mapper.SshPubKeyEntityMapper;
import edu.kit.scc.webreg.entity.SshPubKeyEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.exc.RestInterfaceException;
@Stateless
public class SshPubKeyDtoServiceImpl extends BaseDtoServiceImpl<SshPubKeyEntity, SshPubKeyEntityDto, Long> implements SshPubKeyDtoService {
private static final long serialVersionUID = 1L;
@Inject
private Logger logger;
@Inject
private UserDao userDao;
@Inject
private SshPubKeyDao dao;
@Inject
private SshPubKeyEntityMapper mapper;
@Override
public List<SshPubKeyEntityDto> findByUidNumber(Long uidNumber) throws RestInterfaceException {
UserEntity user = userDao.findByUidNumber(uidNumber);
List<SshPubKeyEntity> list = dao.findByUser(user.getId());
List<SshPubKeyEntityDto> dtoList = new ArrayList<SshPubKeyEntityDto>(list.size());
for (SshPubKeyEntity key : list) {
SshPubKeyEntityDto dto = createNewDto();
mapper.copyProperties(key, dto);
dtoList.add(dto);
}
return dtoList;
}
@Override
protected BaseEntityMapper<SshPubKeyEntity, SshPubKeyEntityDto, Long> getMapper() {
return mapper;
}
@Override
protected BaseDao<SshPubKeyEntity, Long> getDao() {
return dao;
}
}
......@@ -52,6 +52,7 @@ public class JaxRsApplicationActivator extends Application {
resources.add(ImageController.class);
resources.add(ServiceAdminController.class);
resources.add(UserController.class);
resources.add(SshKeyController.class);
// Exceptions
resources.add(AssertionExceptionMapper.class);
......
......@@ -14,7 +14,8 @@ import javax.ws.rs.core.MediaType;
import org.slf4j.Logger;
import edu.kit.scc.webreg.dto.entity.RegistryEntityDto;
import edu.kit.scc.webreg.dto.entity.SshPubKeyEntityDto;
import edu.kit.scc.webreg.dto.service.SshPubKeyDtoService;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.RegistryStatus;
import edu.kit.scc.webreg.entity.ServiceEntity;
......@@ -48,6 +49,17 @@ public class SshKeyController {
@Inject
private UserService userService;
@Inject
private SshPubKeyDtoService dtoService;
@Path(value = "/list/uidnumber/{uidNumber}")
@Produces({MediaType.APPLICATION_JSON})
@GET
public List<SshPubKeyEntityDto> listKeysForUser(@PathParam("uidNumber") Long uidNumber, @Context HttpServletRequest request)
throws IOException, RestInterfaceException {
return dtoService.findByUidNumber(uidNumber);
}
@Path(value = "/auth/{ssn}/uidnumber/{uidNumber}")
@Produces({MediaType.TEXT_PLAIN})
@GET
......@@ -72,8 +84,6 @@ public class SshKeyController {
if (registry == null)
throw new NoRegistryFoundException("No active registry for user");
return "";
}
......
......@@ -32,6 +32,10 @@
<p:column>
<f:facet name="header"><h:outputText value="#{messages.ssh_key_name}:"/></f:facet>
<h:outputText value="#{key.pubKeyEntity.name}"/>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="#{messages.ssh_key_type}:"/></f:facet>
<h:outputText value="#{key.pubKeyEntity.keyType}"/>
</p:column>
<p:column>
<h:outputText value="#{key.publicKey}" rendered="#{not empty key.publicKey}" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment