// Path: core/src/main/java/org/meruvian/yama/core/user/User.java
// @Entity
// @Table(name = "yama_backend_user")
// public class User extends DefaultPersistence {
// 	private String username;
// 	private String password;
// 	private String email;
// 	private Name name = new Name();
// 	private Address address = new Address();
// 	private FileInfo fileInfo;
// 	private List<UserRole> roles = new ArrayList<UserRole>();
// 	
// 	@NotNull
// 	@Size(min = 6)
// 	@Column(name = "username", unique = true, nullable = false)
// 	public String getUsername() {
// 		return username;
// 	}
// 
// 	public void setUsername(String username) {
// 		this.username = username;
// 	}
// 
// 	@Column(name = "password", nullable = false)
// 	public String getPassword() {
// 		return password;
// 	}
// 
// 	public void setPassword(String password) {
// 		this.password = password;
// 	}
// 
// 	@NotNull
// 	@Column(name = "email", unique = true, nullable = false)
// 	public String getEmail() {
// 		return email;
// 	}
// 
// 	public void setEmail(String email) {
// 		this.email = email;
// 	}
// 
// 	@Embedded
// 	public Name getName() {
// 		return name;
// 	}
// 
// 	public void setName(Name name) {
// 		this.name = name;
// 	}
// 	
// 	@Embedded
// 	public Address getAddress() {
// 		return address;
// 	}
// 
// 	public void setAddress(Address address) {
// 		this.address = address;
// 	}
// 
// 	@ManyToOne
// 	@JoinColumn(name = "file_info_id")
// 	public FileInfo getFileInfo() {
// 		return fileInfo;
// 	}
// 	
// 	public void setFileInfo(FileInfo fileInfo) {
// 		this.fileInfo = fileInfo;
// 	}
// 
// 	@JsonIgnore
// 	@OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
// 	public List<UserRole> getRoles() {
// 		return roles;
// 	}
// 
// 	public void setRoles(List<UserRole> roles) {
// 		this.roles = roles;
// 	}
// }
// 
// Path: core/src/main/java/org/meruvian/yama/web/security/DefaultUserDetails.java
// public class DefaultUserDetails extends org.springframework.security.core.userdetails.User {
// 	private String id;
// 	private User user;
// 	
// 	public DefaultUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities) {
// 		super(username, password, authorities);
// 	}
// 
// 	public DefaultUserDetails(String username, String password, boolean enabled, boolean accountNonExpired,
// 			boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
// 		super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
// 	}
// 	
// 	public String getId() {
// 		return id;
// 	}
// 	
// 	public void setId(String id) {
// 		this.id = id;
// 	}
// 	
// 	public User getUser() {
// 		return user;
// 	}
// 	
// 	public void setUser(User user) {
// 		this.user = user;
// 	}
// }


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.meruvian.yama.core.user.User;
import org.meruvian.yama.web.security.DefaultUserDetails;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
/**
 * Copyright 2014 Meruvian
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.meruvian.yama.web;



/**
 * @author Dian Aditya
 *
 */
public class SessionCredentials {
	public static User getCurrentUser() {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null || !authentication.isAuthenticated()) {
			return null;
		}
		
		if (authentication.getPrincipal() instanceof DefaultUserDetails) {
// Path: core/src/main/java/org/meruvian/yama/core/user/User.java
// @Entity
// @Table(name = "yama_backend_user")
// public class User extends DefaultPersistence {
// 	private String username;
// 	private String password;
// 	private String email;
// 	private Name name = new Name();
// 	private Address address = new Address();
// 	private FileInfo fileInfo;
// 	private List<UserRole> roles = new ArrayList<UserRole>();
// 	
// 	@NotNull
// 	@Size(min = 6)
// 	@Column(name = "username", unique = true, nullable = false)
// 	public String getUsername() {
// 		return username;
// 	}
// 
// 	public void setUsername(String username) {
// 		this.username = username;
// 	}
// 
// 	@Column(name = "password", nullable = false)
// 	public String getPassword() {
// 		return password;
// 	}
// 
// 	public void setPassword(String password) {
// 		this.password = password;
// 	}
// 
// 	@NotNull
// 	@Column(name = "email", unique = true, nullable = false)
// 	public String getEmail() {
// 		return email;
// 	}
// 
// 	public void setEmail(String email) {
// 		this.email = email;
// 	}
// 
// 	@Embedded
// 	public Name getName() {
// 		return name;
// 	}
// 
// 	public void setName(Name name) {
// 		this.name = name;
// 	}
// 	
// 	@Embedded
// 	public Address getAddress() {
// 		return address;
// 	}
// 
// 	public void setAddress(Address address) {
// 		this.address = address;
// 	}
// 
// 	@ManyToOne
// 	@JoinColumn(name = "file_info_id")
// 	public FileInfo getFileInfo() {
// 		return fileInfo;
// 	}
// 	
// 	public void setFileInfo(FileInfo fileInfo) {
// 		this.fileInfo = fileInfo;
// 	}
// 
// 	@JsonIgnore
// 	@OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
// 	public List<UserRole> getRoles() {
// 		return roles;
// 	}
// 
// 	public void setRoles(List<UserRole> roles) {
// 		this.roles = roles;
// 	}
// }
// 
// Path: core/src/main/java/org/meruvian/yama/web/security/DefaultUserDetails.java
// public class DefaultUserDetails extends org.springframework.security.core.userdetails.User {
// 	private String id;
// 	private User user;
// 	
// 	public DefaultUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities) {
// 		super(username, password, authorities);
// 	}
// 
// 	public DefaultUserDetails(String username, String password, boolean enabled, boolean accountNonExpired,
// 			boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
// 		super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
// 	}
// 	
// 	public String getId() {
// 		return id;
// 	}
// 	
// 	public void setId(String id) {
// 		this.id = id;
// 	}
// 	
// 	public User getUser() {
// 		return user;
// 	}
// 	
// 	public void setUser(User user) {
// 		this.user = user;
// 	}
// }


// Path: core/src/main/java/org/meruvian/yama/web/SessionCredentials.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.meruvian.yama.core.user.User;
import org.meruvian.yama.web.security.DefaultUserDetails;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Copyright 2014 Meruvian
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.meruvian.yama.web;



/**
 * @author Dian Aditya
 *
 */
public class SessionCredentials {
	public static User getCurrentUser() {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null || !authentication.isAuthenticated()) {
			return null;
		}
		
		if (authentication.getPrincipal() instanceof DefaultUserDetails) {
			DefaultUserDetails user = (DefaultUserDetails) authentication.getPrincipal();