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

com.jslsolucoes.auth.ee.strategy.impl.DefaultAuthStrategy Maven / Gradle / Ivy

There is a newer version: 1.0.32
Show newest version
package com.jslsolucoes.auth.ee.strategy.impl;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Default;
import javax.inject.Inject;
import javax.interceptor.InvocationContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

@RequestScoped
@Default
public class DefaultAuthStrategy extends AbstractAuthStrategy {

	private Auth auth;
	private HttpServletRequest httpServletRequest;

	@Deprecated
	public DefaultAuthStrategy() {

	}

	@Inject
	public DefaultAuthStrategy(Auth auth, HttpServletRequest httpServletRequest) {
		this.auth = auth;
		this.httpServletRequest = httpServletRequest;
	}

	@Override
	public Object handleAuth(InvocationContext invocationContext) throws Exception {
		String authorizationHeader = httpServletRequest.getHeader("Authorization");
		if (!StringUtils.isEmpty(authorizationHeader) && authorizationHeader.equals(auth.getAuthorizationKey())) {
			return invocationContext.proceed();
		} else {
			return forbidden(invocationContext, "Authorization key not found or not match");
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy