Commit 19bb3b86 authored by ls1947's avatar ls1947
Browse files

list 2fas

parent 2167c000
package edu.kit.scc.webreg.service.twofa;
import java.util.List;
public interface TwoFaService {
void findByUserId(Long userId) throws TwoFaException;
List<?> findByUserId(Long userId) throws TwoFaException;
}
......@@ -51,7 +51,7 @@ public class TwoFaServiceImpl implements TwoFaService {
private UserDao userDao;
@Override
public void findByUserId(Long userId) throws TwoFaException {
public List<?> findByUserId(Long userId) throws TwoFaException {
UserEntity user = userDao.findById(userId);
Map<String, String> configMap = configResolver.resolveConfig(user);
......@@ -119,24 +119,27 @@ public class TwoFaServiceImpl implements TwoFaService {
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity);
logger.debug(responseString);
ObjectMapper om = new ObjectMapper();
@SuppressWarnings("unchecked")
Map<String, Object> map = om.readValue(responseString, Map.class);
if (map.get("result") instanceof Map<?, ?>) {
Map<?, ?> resultMap = (Map<?, ?>) map.get("result");
logger.debug("value: " + resultMap.get("value").getClass().toString());
if (resultMap.get("value") instanceof Map<?, ?>) {
Map<?, ?> valueMap = (Map<?, ?>) resultMap.get("value");
logger.debug("data: " + valueMap.get("data").getClass().toString());
if (valueMap.get("data") instanceof List<?>) {
List<?> dataList = (List<?>) valueMap.get("data");
for (Object data : dataList) {
if (data instanceof Map<?, ?>) {
Map<?, ?> dataMap = (Map<?, ?>) data;
logger.debug("ID: " + dataMap.get("LinOtp.TokenId"));
}
}
}
List<?> dataList = getDataList(valueMap);
for (Object data : dataList) {
if (data instanceof Map<?, ?>) {
Map<?, ?> dataMap = (Map<?, ?>) data;
logger.debug("ID: " + dataMap.get("LinOtp.TokenId"));
}
}
return dataList;
}
}
} finally {
......@@ -145,9 +148,22 @@ public class TwoFaServiceImpl implements TwoFaService {
} finally {
httpClient.close();
}
return null;
} catch (IOException | URISyntaxException e) {
throw new TwoFaException(e);
}
}
protected List<?> getDataList(Map<?, ?> valueMap) {
logger.debug("data: " + valueMap.get("data").getClass().toString());
if (valueMap.get("data") instanceof List<?>) {
List<?> dataList = (List<?>) valueMap.get("data");
return dataList;
}
else {
return null;
}
}
}
......@@ -11,6 +11,7 @@
package edu.kit.scc.webreg.bean;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
......@@ -32,7 +33,6 @@ public class TwoFaUserBean implements Serializable {
private static final long serialVersionUID = 1L;
private UserEntity user;
@Inject
private Logger logger;
......@@ -49,11 +49,14 @@ public class TwoFaUserBean implements Serializable {
@Inject
private FacesMessageGenerator messageGenerator;
private UserEntity user;
private List<?> tokenList;
public void preRenderView(ComponentSystemEvent ev) {
if (user == null) {
user = userService.findById(sessionManager.getUserId());
try {
twoFaService.findByUserId(sessionManager.getUserId());
tokenList = twoFaService.findByUserId(sessionManager.getUserId());
} catch (TwoFaException e) {
messageGenerator.addErrorMessage("Error", e.toString());
logger.debug("Exception happened", e);
......@@ -61,6 +64,10 @@ public class TwoFaUserBean implements Serializable {
}
}
public List<?> getTokenList() {
return tokenList;
}
public UserEntity getUser() {
return user;
}
......
......@@ -28,6 +28,11 @@
<p:messages id="messageBox" for="key_error" showDetail="true" />
<p:repeat var="token" value="#{twoFaUserBean.tokenList}">
<div>
<h:outputText value="#{token.get('LinOtp.TokenSerialnumber')}" />
</div>
</p:repeat>
</p:panel>
</h:form>
</ui:define>
......
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