// Path: commons/src/main/java/com/dataagg/commons/domain/EAuthority.java
// @Table("sys_authority")
// @Comment("权限标识")
// public class EAuthority implements GrantedAuthority {
// 	private static final long serialVersionUID = 7423414401567180611L;
// 	@Id
// 	private Long id;
// 
// 	@Column(hump = true)
// 	@ColDefine(type = ColType.VARCHAR, width = 64, notNull = true)
// 	@Comment("权限标识")
// 	private String name;
// 
// 	@Column(hump = true)
// 	@ColDefine(type = ColType.VARCHAR, width = 200, notNull = true)
// 	@Comment("描述")
// 	private String description;
// 
// 	public Long getId() {
// 		return id;
// 	}
// 
// 	public void setId(Long id) {
// 		this.id = id;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	@Override
// 	public String getAuthority() {
// 		return name;
// 	}
// 
// 	public String getDescription() {
// 		return description;
// 	}
// 
// 	public void setDescription(String description) {
// 		this.description = description;
// 	}
// }


import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import com.dataagg.commons.domain.EAuthority;
package com.dataagg.util;




public class SecurityHelper {
	public static Authentication getAuthentication() {
		SecurityContext sc = SecurityContextHolder.getContext();
		return sc.getAuthentication();
	}

	public static Authentication auth(AuthenticationManager authenticationManager, String userName, String password) {
		SecurityContext sc = SecurityContextHolder.getContext();
		UsernamePasswordAuthenticationToken upToken = new UsernamePasswordAuthenticationToken(userName, password);
		Authentication authentication = authenticationManager.authenticate(upToken);
		sc.setAuthentication(authentication);
		return sc.getAuthentication();
	}

	public static boolean hasAuthority(Set<String> authorities, String authority) {
		if (authorities != null) {
			String authorityText = "," + authority + ",";
			for (String a : authorities) {
				if (authorityText.contains("," + a + ",")) { return true; }
			}
		}
		return false;
	}

// Path: commons/src/main/java/com/dataagg/commons/domain/EAuthority.java
// @Table("sys_authority")
// @Comment("权限标识")
// public class EAuthority implements GrantedAuthority {
// 	private static final long serialVersionUID = 7423414401567180611L;
// 	@Id
// 	private Long id;
// 
// 	@Column(hump = true)
// 	@ColDefine(type = ColType.VARCHAR, width = 64, notNull = true)
// 	@Comment("权限标识")
// 	private String name;
// 
// 	@Column(hump = true)
// 	@ColDefine(type = ColType.VARCHAR, width = 200, notNull = true)
// 	@Comment("描述")
// 	private String description;
// 
// 	public Long getId() {
// 		return id;
// 	}
// 
// 	public void setId(Long id) {
// 		this.id = id;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	@Override
// 	public String getAuthority() {
// 		return name;
// 	}
// 
// 	public String getDescription() {
// 		return description;
// 	}
// 
// 	public void setDescription(String description) {
// 		this.description = description;
// 	}
// }


// Path: commons/src/main/java/com/dataagg/util/SecurityHelper.java
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import com.dataagg.commons.domain.EAuthority;

package com.dataagg.util;




public class SecurityHelper {
	public static Authentication getAuthentication() {
		SecurityContext sc = SecurityContextHolder.getContext();
		return sc.getAuthentication();
	}

	public static Authentication auth(AuthenticationManager authenticationManager, String userName, String password) {
		SecurityContext sc = SecurityContextHolder.getContext();
		UsernamePasswordAuthenticationToken upToken = new UsernamePasswordAuthenticationToken(userName, password);
		Authentication authentication = authenticationManager.authenticate(upToken);
		sc.setAuthentication(authentication);
		return sc.getAuthentication();
	}

	public static boolean hasAuthority(Set<String> authorities, String authority) {
		if (authorities != null) {
			String authorityText = "," + authority + ",";
			for (String a : authorities) {
				if (authorityText.contains("," + a + ",")) { return true; }
			}
		}
		return false;
	}

	public static List<EAuthority> buildAuthority(String... allAuthorities) {