/*
 * oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxtrust.action;

import java.io.Serializable;

import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.gluu.oxtrust.model.AuthenticationChartDto;
import org.gluu.oxtrust.security.Identity;
import org.gluu.oxtrust.service.MetricService;
import org.slf4j.Logger;
import org.xdi.service.JsonService;

/**
 * Action class for home page
 * 
 * @author Yuriy Movchan Date: 08/28/2015
 */
@Named("homeAction")
@ConversationScoped
//TODO CDI @Restrict("#{identity.loggedIn}")
public class HomeAction implements Serializable {

	private static final long serialVersionUID = 5130372165991117114L;

	@Inject
	private Logger log;

	@Inject
	private MetricService metricService;

	@Inject
	private JsonService jsonService;

	@Inject
	private Identity identity;

	private AuthenticationChartDto authenticationChartDto;

	private String authenticationChartJson;

	public void init() {
		boolean hasConfigurationAccess = identity.hasPermission("configuration", "access");
		if (hasConfigurationAccess) {
			generateAuthenticationChart();
		}
	}

	private boolean generateAuthenticationChart() {
		try {
			this.authenticationChartDto = metricService.genereateAuthenticationChartDto(7);
			this.authenticationChartJson = jsonService.objectToJson(authenticationChartDto);
		} catch (Exception ex) {
			log.error("Failed to prepare authentication chart", ex);
			return false;
		}

		return true;
	}

	public String getAuthenticationChartJson() {
		return authenticationChartJson;
	}

	public AuthenticationChartDto getAuthenticationChartDto() {
		return authenticationChartDto;
	}

}

@@ -396,23 +396,27 @@
 t.se
-curity.Identity
+rvice.MetricService
 ;%0Aim
@@ -437,38 +437,42 @@
 oxtrust.service.
-Metric
+Permission
 Service;%0Aimport 
@@ -961,25 +961,43 @@
 ate 
-Identity identity
+PermissionService permissionService
 ;%0A%0A%09
@@ -1151,24 +1151,33 @@
 ccess = 
-identity
+permissionService
 .hasPerm

Use permissionService to check access