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

be.personify.iam.frontend.security.CustomAuthentication Maven / Gradle / Ivy

There is a newer version: 1.5.2.RELEASE
Show newest version
package be.personify.iam.frontend.security;

import java.util.Collection;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class CustomAuthentication implements Authentication{

	private static final long serialVersionUID = -2465661964089021764L;
	
	private String principal;
	private String credentials;
	private boolean authenticated;
	private UserDetails details;
	private long validityInMillisecons;
	private long creationTimeInMilliseconds;
	
	/**
	 * Constructor
	 * @param principal the username ( email )
	 * @param credentials the token
	 * @param validityInMilliseconds the validity
	 */
	public CustomAuthentication( String principal, String credentials, long validityInMilliseconds) {
		this.principal = principal;
		this.credentials = credentials;
		this.creationTimeInMilliseconds = System.currentTimeMillis();
		this.validityInMillisecons = validityInMilliseconds;
	}
	
		
	@Override
	public String getName() {
		return principal;
	}

	@Override
	public Collection getAuthorities() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getCredentials() {
		return credentials;
	}
	
	public void setDetails( UserDetails customDetails ) {
		this.details = customDetails;
	}
	

	@Override
	public Object getDetails() {
		return details;
	}

	@Override
	public Object getPrincipal() {
		return principal;
	}

	@Override
	public boolean isAuthenticated() {
		if( authenticated ) {
			if ( System.currentTimeMillis() < (creationTimeInMilliseconds + validityInMillisecons)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
		this.authenticated = isAuthenticated;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy