All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.protea.foundation.utility.services.ProteaService Maven / Gradle / Ivy

package cc.protea.foundation.utility.services;

import java.security.Principal;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;

import org.apache.commons.lang3.math.NumberUtils;

import cc.protea.foundation.model.Pojo;
import cc.protea.foundation.utility.ProteaUser;
import cc.protea.foundation.utility.UserUtil;

public abstract class ProteaService extends Pojo {

	@Context
	SecurityContext securityContext;

	ProteaUser user = null;

	public ProteaUser getUser() {
		if (user == null) {
			user = UserUtil.getProteaUser(getUserId());
			UserUtil.updateLastSeen(getUserId(), getIpAddress());
		}
		return user;
	}

	public Integer getUserId() {
		if (securityContext == null) {
			return null;
		}
		Principal principal = securityContext.getUserPrincipal();
		if (principal == null) {
			return null;
		}
        return NumberUtils.createInteger(principal.getName());
    }

	@Context
	ContainerRequestContext requestContext;

	@Context
	HttpServletRequest request;

	public String getIpAddress() {
		return request.getRemoteAddr();
	}

	public String getSessionToken() {
		Object o = requestContext.getProperty("sessionToken");
		return o == null ? null : o.toString();
	}

	public String getReferrer() {
		return requestContext.getHeaders().getFirst("Referer");
	}

	public String getUrl() {
		return requestContext.getUriInfo().toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy