mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 08:59:10 +08:00
v1.2.2 RC
This commit is contained in:
parent
c70aa8df95
commit
6ce1481df5
7
.checkstyle
Normal file
7
.checkstyle
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
|
||||
<fileset name="all" enabled="true" check-config-name="checkstyle-rules" local="false">
|
||||
<file-match-pattern match-pattern=".*" include-pattern="true"/>
|
||||
</fileset>
|
||||
</fileset-config>
|
||||
6
.project
6
.project
@ -15,9 +15,15 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
||||
@ -1,18 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<classpathentry kind="src" output="bin/main"
|
||||
path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
<attribute name="gradle_scope" value="main" />
|
||||
<attribute name="gradle_used_by_scope" value="main,test" />
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/java">
|
||||
<classpathentry kind="src" output="bin/test"
|
||||
path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
<attribute name="gradle_used_by_scope" value="test"/>
|
||||
<attribute name="gradle_scope" value="test" />
|
||||
<attribute name="gradle_used_by_scope" value="test" />
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
<classpathentry kind="con"
|
||||
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/" />
|
||||
<classpathentry kind="con"
|
||||
path="org.eclipse.buildship.core.gradleclasspathcontainer" />
|
||||
<classpathentry kind="output" path="bin/default" />
|
||||
</classpath>
|
||||
|
||||
@ -25,11 +25,17 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="maxkey-core">
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/test/java"/>
|
||||
</wb-module>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-modules id="moduleCoreId"
|
||||
project-version="1.5.0">
|
||||
<wb-module deploy-name="maxkey-core">
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java" />
|
||||
<wb-resource deploy-path="/" source-path="/src/test/java" />
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="java"/>
|
||||
<fixed facet="jst.utility"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
<installed facet="java" version="1.8"/>
|
||||
<fixed facet="java" />
|
||||
<fixed facet="jst.utility" />
|
||||
<installed facet="jst.utility" version="1.0" />
|
||||
<installed facet="java" version="1.8" />
|
||||
</faceted-project>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -19,58 +19,59 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
|
||||
|
||||
/**
|
||||
* login Authentication abstract class
|
||||
*
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractAuthenticationProvider{
|
||||
|
||||
public abstract class AbstractAuthenticationProvider {
|
||||
|
||||
private static final Logger _logger = LoggerFactory.getLogger(AbstractAuthenticationProvider.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("authenticationRealm")
|
||||
protected AbstractAuthenticationRealm authenticationRealm;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("tfaOTPAuthn")
|
||||
protected AbstractOTPAuthn tfaOTPAuthn;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("remeberMeService")
|
||||
protected AbstractRemeberMeService remeberMeService;
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("authenticationRealm")
|
||||
protected AbstractAuthenticationRealm authenticationRealm;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("tfaOTPAuthn")
|
||||
protected AbstractOTPAuthn tfaOTPAuthn;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("remeberMeService")
|
||||
protected AbstractRemeberMeService remeberMeService;
|
||||
|
||||
protected abstract String getProviderName();
|
||||
|
||||
protected abstract String getProviderName();
|
||||
|
||||
protected abstract Authentication doInternalAuthenticate(Authentication authentication);
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public boolean supports(Class authentication) {
|
||||
public boolean supports(Class authentication) {
|
||||
return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
|
||||
}
|
||||
|
||||
/*
|
||||
* authenticate
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.security.authentication.AuthenticationProvider#authenticate(org.springframework.security.core.Authentication)
|
||||
/*
|
||||
* authenticate (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.security.authentication.AuthenticationProvider#
|
||||
* authenticate(org.springframework.security.core.Authentication)
|
||||
*/
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
_logger.debug("Trying to authenticate user '{}' via {}", authentication.getPrincipal(), getProviderName());
|
||||
|
||||
|
||||
try {
|
||||
authentication = doInternalAuthenticate(authentication);
|
||||
} catch (AuthenticationException e) {
|
||||
e.printStackTrace();
|
||||
_logger.error("Failed to authenticate user {} via {}: {}", new Object[]{authentication.getPrincipal(), getProviderName(), e.getMessage()});
|
||||
e.printStackTrace();
|
||||
_logger.error("Failed to authenticate user {} via {}: {}",
|
||||
new Object[] { authentication.getPrincipal(), getProviderName(), e.getMessage() });
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
String message = "Unexpected exception in " + getProviderName() + " authentication:";
|
||||
_logger.error(message, e);
|
||||
throw new AuthenticationServiceException(message, e);
|
||||
@ -78,188 +79,195 @@ public abstract class AbstractAuthenticationProvider{
|
||||
if (!authentication.isAuthenticated()) {
|
||||
return authentication;
|
||||
}
|
||||
|
||||
|
||||
// user authenticated
|
||||
_logger.debug("'{}' authenticated successfully by {}.", authentication.getPrincipal(), getProviderName());
|
||||
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
Object password_set_type=WebContext.getSession().getAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE);
|
||||
//登录完成后切换SESSION
|
||||
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
Object password_set_type = WebContext.getSession()
|
||||
.getAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE);
|
||||
// 登录完成后切换SESSION
|
||||
_logger.debug("Login Session {}.", WebContext.getSession().getId());
|
||||
WebContext.getSession().invalidate();
|
||||
WebContext.getSession().invalidate();
|
||||
WebContext.setAttribute(WebConstants.CURRENT_USER_SESSION_ID, WebContext.getSession().getId());
|
||||
_logger.debug("Login Success Session {}.", WebContext.getSession().getId());
|
||||
|
||||
authenticationRealm.insertLoginHistory(userInfo,LOGINTYPE.LOCAL,"","xe00000004","success");
|
||||
|
||||
//认证设置
|
||||
WebContext.setAuthentication(authentication);
|
||||
WebContext.setUserInfo(userInfo);
|
||||
WebContext.getSession().setAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE,password_set_type);
|
||||
|
||||
|
||||
authenticationRealm.insertLoginHistory(userInfo, LOGINTYPE.LOCAL, "", "xe00000004", "success");
|
||||
|
||||
// 认证设置
|
||||
WebContext.setAuthentication(authentication);
|
||||
WebContext.setUserInfo(userInfo);
|
||||
WebContext.getSession().setAttribute(WebConstants.CURRENT_LOGIN_USER_PASSWORD_SET_TYPE, password_set_type);
|
||||
|
||||
// create new authentication response containing the user and it's authorities
|
||||
UsernamePasswordAuthenticationToken simpleUserAuthentication = new UsernamePasswordAuthenticationToken(userInfo.getUsername(), authentication.getCredentials(), authentication.getAuthorities());
|
||||
UsernamePasswordAuthenticationToken simpleUserAuthentication = new UsernamePasswordAuthenticationToken(
|
||||
userInfo.getUsername(), authentication.getCredentials(), authentication.getAuthorities());
|
||||
return simpleUserAuthentication;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* session validate
|
||||
*
|
||||
* @param j_username
|
||||
* @param j_cname
|
||||
* @param sessionId
|
||||
*/
|
||||
protected void sessionValid(String j_sessionId){
|
||||
if(j_sessionId==null || ! j_sessionId.equals(WebContext.getSession().getId())){
|
||||
String message=WebContext.getI18nValue("login.error.session");
|
||||
_logger.debug("login session valid error.");
|
||||
throw new BadCredentialsException(message);
|
||||
protected void sessionValid(String j_sessionId) {
|
||||
if (j_sessionId == null || !j_sessionId.equals(WebContext.getSession().getId())) {
|
||||
String message = WebContext.getI18nValue("login.error.session");
|
||||
_logger.debug("login session valid error.");
|
||||
throw new BadCredentialsException(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* session validate
|
||||
*
|
||||
* @param j_username
|
||||
* @param j_cname
|
||||
* @param sessionId
|
||||
*/
|
||||
protected void jwtTokenValid(String j_jwtToken){
|
||||
/*if(j_jwtToken!=null && ! j_jwtToken.equals("")){
|
||||
if(jwtLoginService.jwtTokenValidation(j_jwtToken)){
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
String message=WebContext.getI18nValue("login.error.session");
|
||||
_logger.debug("login session valid error.");
|
||||
throw new BadCredentialsException(message);
|
||||
protected void jwtTokenValid(String j_jwtToken) {
|
||||
/*
|
||||
* if(j_jwtToken!=null && ! j_jwtToken.equals("")){
|
||||
* if(jwtLoginService.jwtTokenValidation(j_jwtToken)){ return; } }
|
||||
*/
|
||||
String message = WebContext.getI18nValue("login.error.session");
|
||||
_logger.debug("login session valid error.");
|
||||
throw new BadCredentialsException(message);
|
||||
}
|
||||
|
||||
protected void authTypeValid(String j_auth_type){
|
||||
if(j_auth_type==null){
|
||||
String message=WebContext.getI18nValue("login.error.authtype");
|
||||
_logger.debug("login AuthN type can not been null .");
|
||||
throw new BadCredentialsException(message);
|
||||
protected void authTypeValid(String j_auth_type) {
|
||||
if (j_auth_type == null) {
|
||||
String message = WebContext.getI18nValue("login.error.authtype");
|
||||
_logger.debug("login AuthN type can not been null .");
|
||||
throw new BadCredentialsException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* captcha validate
|
||||
*
|
||||
* @param j_username
|
||||
* @param j_cname
|
||||
* @param captcha
|
||||
*/
|
||||
protected void captchaValid(String j_captcha,String j_auth_type){
|
||||
if(applicationConfig.getLoginConfig().isCaptcha()){//for basic
|
||||
if(j_auth_type.equalsIgnoreCase("common")){
|
||||
_logger.info("captcha : "+WebContext.getSession().getAttribute(WebConstants.KAPTCHA_SESSION_KEY).toString());
|
||||
if(j_captcha==null
|
||||
|| !j_captcha.equals(WebContext.getSession().getAttribute(WebConstants.KAPTCHA_SESSION_KEY).toString())){
|
||||
String message=WebContext.getI18nValue("login.error.captcha");
|
||||
_logger.debug("login captcha valid error.");
|
||||
throw new BadCredentialsException(message);
|
||||
}
|
||||
}
|
||||
protected void captchaValid(String j_captcha, String j_auth_type) {
|
||||
if (applicationConfig.getLoginConfig().isCaptcha()) {// for basic
|
||||
if (j_auth_type.equalsIgnoreCase("common")) {
|
||||
_logger.info("captcha : "
|
||||
+ WebContext.getSession().getAttribute(WebConstants.KAPTCHA_SESSION_KEY).toString());
|
||||
if (j_captcha == null || !j_captcha
|
||||
.equals(WebContext.getSession().getAttribute(WebConstants.KAPTCHA_SESSION_KEY).toString())) {
|
||||
String message = WebContext.getI18nValue("login.error.captcha");
|
||||
_logger.debug("login captcha valid error.");
|
||||
throw new BadCredentialsException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* captcha validate
|
||||
*
|
||||
* @param j_username
|
||||
* @param j_cname
|
||||
* @param j_otp_captcha
|
||||
*/
|
||||
protected void tftcaptchaValid(String j_otp_captcha,String j_auth_type,UserInfo userInfo){
|
||||
if(applicationConfig.getLoginConfig().isOneTimePwd()){//for one time password 2 factor
|
||||
if(j_auth_type.equalsIgnoreCase("tfa")){
|
||||
UserInfo validUserInfo=new UserInfo();
|
||||
validUserInfo.setUsername(userInfo.getUsername());
|
||||
String sharedSecret=PasswordReciprocal.getInstance().decoder(userInfo.getSharedSecret());
|
||||
validUserInfo.setSharedSecret(sharedSecret);
|
||||
validUserInfo.setSharedCounter(userInfo.getSharedCounter());
|
||||
validUserInfo.setId(userInfo.getId());
|
||||
if(j_otp_captcha==null||!tfaOTPAuthn.validate(validUserInfo, j_otp_captcha)){
|
||||
String message=WebContext.getI18nValue("login.error.captcha");
|
||||
_logger.debug("login captcha valid error.");
|
||||
throw new BadCredentialsException(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
protected void tftcaptchaValid(String j_otp_captcha, String j_auth_type, UserInfo userInfo) {
|
||||
if (applicationConfig.getLoginConfig().isOneTimePwd()) {// for one time password 2 factor
|
||||
if (j_auth_type.equalsIgnoreCase("tfa")) {
|
||||
UserInfo validUserInfo = new UserInfo();
|
||||
validUserInfo.setUsername(userInfo.getUsername());
|
||||
String sharedSecret = PasswordReciprocal.getInstance().decoder(userInfo.getSharedSecret());
|
||||
validUserInfo.setSharedSecret(sharedSecret);
|
||||
validUserInfo.setSharedCounter(userInfo.getSharedCounter());
|
||||
validUserInfo.setId(userInfo.getId());
|
||||
if (j_otp_captcha == null || !tfaOTPAuthn.validate(validUserInfo, j_otp_captcha)) {
|
||||
String message = WebContext.getI18nValue("login.error.captcha");
|
||||
_logger.debug("login captcha valid error.");
|
||||
throw new BadCredentialsException(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* login user by j_username and j_cname
|
||||
* first query user by j_cname
|
||||
* if first step userinfo is null,query user from system
|
||||
* login user by j_username and j_cname first query user by j_cname if first
|
||||
* step userinfo is null,query user from system
|
||||
*
|
||||
* @param j_username
|
||||
* @param j_cname
|
||||
* @return
|
||||
*/
|
||||
protected UserInfo loadUserInfo(String j_username,String j_password){
|
||||
UserInfo userInfo = authenticationRealm.loadUserInfo(j_username,j_password);
|
||||
|
||||
if(userInfo != null){
|
||||
if(userInfo.getUserType()=="SYSTEM"){
|
||||
_logger.debug("SYSTEM User Login. ");
|
||||
}else{
|
||||
_logger.debug("User Login. ");
|
||||
}
|
||||
}
|
||||
protected UserInfo loadUserInfo(String j_username, String j_password) {
|
||||
UserInfo userInfo = authenticationRealm.loadUserInfo(j_username, j_password);
|
||||
|
||||
return userInfo;
|
||||
if (userInfo != null) {
|
||||
if (userInfo.getUserType() == "SYSTEM") {
|
||||
_logger.debug("SYSTEM User Login. ");
|
||||
} else {
|
||||
_logger.debug("User Login. ");
|
||||
}
|
||||
}
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* check input password empty
|
||||
* check input password empty
|
||||
*
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
protected boolean emptyPasswordValid(String j_password){
|
||||
if(null==j_password||"".equals(j_password)){
|
||||
throw new BadCredentialsException(WebContext.getI18nValue("login.error.password.null"));
|
||||
}
|
||||
return true;
|
||||
protected boolean emptyPasswordValid(String j_password) {
|
||||
if (null == j_password || "".equals(j_password)) {
|
||||
throw new BadCredentialsException(WebContext.getI18nValue("login.error.password.null"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check input username or password empty
|
||||
* check input username or password empty
|
||||
*
|
||||
* @param j_username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
protected boolean emptyEmailValid(String j_email){
|
||||
if(null==j_email||"".equals(j_email)){
|
||||
throw new BadCredentialsException("login.error.email.null");
|
||||
}
|
||||
return true;
|
||||
protected boolean emptyEmailValid(String j_email) {
|
||||
if (null == j_email || "".equals(j_email)) {
|
||||
throw new BadCredentialsException("login.error.email.null");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check input username empty
|
||||
* check input username empty
|
||||
*
|
||||
* @param j_username
|
||||
* @return
|
||||
*/
|
||||
protected boolean emptyUsernameValid(String j_username){
|
||||
if(null==j_username||"".equals(j_username)){
|
||||
throw new BadCredentialsException(WebContext.getI18nValue("login.error.username.null"));
|
||||
}
|
||||
return true;
|
||||
protected boolean emptyUsernameValid(String j_username) {
|
||||
if (null == j_username || "".equals(j_username)) {
|
||||
throw new BadCredentialsException(WebContext.getI18nValue("login.error.username.null"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean userinfoValid(UserInfo userInfo,String j_username){
|
||||
if(null==userInfo){
|
||||
String message=WebContext.getI18nValue("login.error.username");
|
||||
_logger.debug("login user "+j_username+" not in this System ."+message);
|
||||
UserInfo loginUser=new UserInfo(j_username);
|
||||
loginUser.setId(loginUser.generateId());
|
||||
loginUser.setDisplayName("not exist");
|
||||
loginUser.setLoginCount(0);
|
||||
authenticationRealm.insertLoginHistory(loginUser,LOGINTYPE.LOCAL,"",WebContext.getI18nValue("login.error.username"),"user not exist");
|
||||
throw new BadCredentialsException(WebContext.getI18nValue("login.error.username"));
|
||||
}
|
||||
return true;
|
||||
|
||||
protected boolean userinfoValid(UserInfo userInfo, String j_username) {
|
||||
if (null == userInfo) {
|
||||
String message = WebContext.getI18nValue("login.error.username");
|
||||
_logger.debug("login user " + j_username + " not in this System ." + message);
|
||||
UserInfo loginUser = new UserInfo(j_username);
|
||||
loginUser.setId(loginUser.generateId());
|
||||
loginUser.setDisplayName("not exist");
|
||||
loginUser.setLoginCount(0);
|
||||
authenticationRealm.insertLoginHistory(loginUser, LOGINTYPE.LOCAL, "",
|
||||
WebContext.getI18nValue("login.error.username"), "user not exist");
|
||||
throw new BadCredentialsException(WebContext.getI18nValue("login.error.username"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -6,13 +6,13 @@ import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
||||
public class BasicAuthentication implements Authentication{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -110742975439268030L;
|
||||
String j_username ;
|
||||
String j_password ;
|
||||
public class BasicAuthentication implements Authentication {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -110742975439268030L;
|
||||
String j_username;
|
||||
String j_password;
|
||||
String j_sessionid;
|
||||
String j_captcha;
|
||||
String j_otp_captcha;
|
||||
@ -21,135 +21,134 @@ public class BasicAuthentication implements Authentication{
|
||||
String j_jwt_token;
|
||||
ArrayList<GrantedAuthority> grantedAuthority;
|
||||
boolean authenticated;
|
||||
|
||||
public BasicAuthentication() {
|
||||
grantedAuthority = new ArrayList<GrantedAuthority>();
|
||||
grantedAuthority.add(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
grantedAuthority.add(new SimpleGrantedAuthority("ORDINARY_USER"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Basic Authentication";
|
||||
}
|
||||
public BasicAuthentication() {
|
||||
grantedAuthority = new ArrayList<GrantedAuthority>();
|
||||
grantedAuthority.add(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
grantedAuthority.add(new SimpleGrantedAuthority("ORDINARY_USER"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return grantedAuthority;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Basic Authentication";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCredentials() {
|
||||
return this.getJ_password();
|
||||
}
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return grantedAuthority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDetails() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Object getCredentials() {
|
||||
return this.getJ_password();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPrincipal() {
|
||||
return this.getJ_username();
|
||||
}
|
||||
@Override
|
||||
public Object getDetails() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthenticated() {
|
||||
return authenticated;
|
||||
}
|
||||
@Override
|
||||
public Object getPrincipal() {
|
||||
return this.getJ_username();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAuthenticated(boolean authenticated) throws IllegalArgumentException {
|
||||
this.authenticated=authenticated;
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean isAuthenticated() {
|
||||
return authenticated;
|
||||
}
|
||||
|
||||
public String getJ_username() {
|
||||
return j_username;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return j_username;
|
||||
}
|
||||
@Override
|
||||
public void setAuthenticated(boolean authenticated) throws IllegalArgumentException {
|
||||
this.authenticated = authenticated;
|
||||
|
||||
public void setJ_username(String j_username) {
|
||||
this.j_username = j_username;
|
||||
}
|
||||
}
|
||||
|
||||
public String getJ_password() {
|
||||
return j_password;
|
||||
}
|
||||
public String getJ_username() {
|
||||
return j_username;
|
||||
}
|
||||
|
||||
public void setJ_password(String j_password) {
|
||||
this.j_password = j_password;
|
||||
}
|
||||
public String getUsername() {
|
||||
return j_username;
|
||||
}
|
||||
|
||||
public String getJ_sessionid() {
|
||||
return j_sessionid;
|
||||
}
|
||||
public String getSessionid() {
|
||||
return j_sessionid;
|
||||
}
|
||||
public void setJ_username(String j_username) {
|
||||
this.j_username = j_username;
|
||||
}
|
||||
|
||||
public void setJ_sessionid(String j_sessionid) {
|
||||
this.j_sessionid = j_sessionid;
|
||||
}
|
||||
public String getJ_password() {
|
||||
return j_password;
|
||||
}
|
||||
|
||||
public String getJ_captcha() {
|
||||
return j_captcha;
|
||||
}
|
||||
public void setJ_password(String j_password) {
|
||||
this.j_password = j_password;
|
||||
}
|
||||
|
||||
public void setJ_captcha(String j_captcha) {
|
||||
this.j_captcha = j_captcha;
|
||||
}
|
||||
public String getJ_sessionid() {
|
||||
return j_sessionid;
|
||||
}
|
||||
|
||||
public String getJ_otp_captcha() {
|
||||
return j_otp_captcha;
|
||||
}
|
||||
public String getSessionid() {
|
||||
return j_sessionid;
|
||||
}
|
||||
|
||||
public void setJ_otp_captcha(String j_otp_captcha) {
|
||||
this.j_otp_captcha = j_otp_captcha;
|
||||
}
|
||||
public void setJ_sessionid(String j_sessionid) {
|
||||
this.j_sessionid = j_sessionid;
|
||||
}
|
||||
|
||||
public String getJ_remeberme() {
|
||||
return j_remeberme;
|
||||
}
|
||||
public String getJ_captcha() {
|
||||
return j_captcha;
|
||||
}
|
||||
|
||||
public void setJ_remeberme(String j_remeberme) {
|
||||
this.j_remeberme = j_remeberme;
|
||||
}
|
||||
public void setJ_captcha(String j_captcha) {
|
||||
this.j_captcha = j_captcha;
|
||||
}
|
||||
|
||||
public String getJ_auth_type() {
|
||||
return j_auth_type;
|
||||
}
|
||||
public String getJ_otp_captcha() {
|
||||
return j_otp_captcha;
|
||||
}
|
||||
|
||||
public void setJ_auth_type(String j_auth_type) {
|
||||
this.j_auth_type = j_auth_type;
|
||||
}
|
||||
public void setJ_otp_captcha(String j_otp_captcha) {
|
||||
this.j_otp_captcha = j_otp_captcha;
|
||||
}
|
||||
|
||||
public String getJ_jwt_token() {
|
||||
return j_jwt_token;
|
||||
}
|
||||
public String getJ_remeberme() {
|
||||
return j_remeberme;
|
||||
}
|
||||
|
||||
public void setJ_jwt_token(String j_jwt_token) {
|
||||
this.j_jwt_token = j_jwt_token;
|
||||
}
|
||||
|
||||
public ArrayList<GrantedAuthority> getGrantedAuthority() {
|
||||
return grantedAuthority;
|
||||
}
|
||||
public void setJ_remeberme(String j_remeberme) {
|
||||
this.j_remeberme = j_remeberme;
|
||||
}
|
||||
|
||||
public void setGrantedAuthority(ArrayList<GrantedAuthority> grantedAuthority) {
|
||||
this.grantedAuthority = grantedAuthority;
|
||||
}
|
||||
public String getJ_auth_type() {
|
||||
return j_auth_type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BasicAuthentication [j_username=" + j_username + ", j_sessionId=" + j_sessionid + ", j_captcha="
|
||||
+ j_captcha + ", j_otp_captcha=" + j_otp_captcha + ", j_remeberMe=" + j_remeberme + ", j_auth_type="
|
||||
+ j_auth_type + ", j_jwtToken=" + j_jwt_token + ", authenticated=" + authenticated + "]";
|
||||
}
|
||||
|
||||
|
||||
public void setJ_auth_type(String j_auth_type) {
|
||||
this.j_auth_type = j_auth_type;
|
||||
}
|
||||
|
||||
public String getJ_jwt_token() {
|
||||
return j_jwt_token;
|
||||
}
|
||||
|
||||
public void setJ_jwt_token(String j_jwt_token) {
|
||||
this.j_jwt_token = j_jwt_token;
|
||||
}
|
||||
|
||||
public ArrayList<GrantedAuthority> getGrantedAuthority() {
|
||||
return grantedAuthority;
|
||||
}
|
||||
|
||||
public void setGrantedAuthority(ArrayList<GrantedAuthority> grantedAuthority) {
|
||||
this.grantedAuthority = grantedAuthority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BasicAuthentication [j_username=" + j_username + ", j_sessionId=" + j_sessionid + ", j_captcha="
|
||||
+ j_captcha + ", j_otp_captcha=" + j_otp_captcha + ", j_remeberMe=" + j_remeberme + ", j_auth_type="
|
||||
+ j_auth_type + ", j_jwtToken=" + j_jwt_token + ", authenticated=" + authenticated + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,67 +18,67 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
*
|
||||
*/
|
||||
public class RealmAuthenticationProvider extends AbstractAuthenticationProvider {
|
||||
|
||||
|
||||
private static final Logger _logger = LoggerFactory.getLogger(RealmAuthenticationProvider.class);
|
||||
|
||||
protected String getProviderName() {
|
||||
return "RealmAuthenticationProvider";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Authentication doInternalAuthenticate(Authentication authentication) {
|
||||
BasicAuthentication auth =(BasicAuthentication)authentication;
|
||||
BasicAuthentication auth = (BasicAuthentication)authentication;
|
||||
|
||||
_logger.debug("authentication "+auth);
|
||||
|
||||
sessionValid(auth.getJ_sessionid());
|
||||
|
||||
//jwtTokenValid(j_jwtToken);
|
||||
|
||||
authTypeValid(auth.getJ_auth_type());
|
||||
|
||||
captchaValid(auth.getJ_captcha(),auth.getJ_auth_type());
|
||||
|
||||
emptyPasswordValid(auth.getJ_password());
|
||||
|
||||
UserInfo userInfo = null;
|
||||
|
||||
emptyUsernameValid(auth.getJ_username());
|
||||
|
||||
userInfo= loadUserInfo(auth.getJ_username(),auth.getJ_password());
|
||||
|
||||
userinfoValid(userInfo, auth.getJ_password());
|
||||
|
||||
tftcaptchaValid(auth.getJ_otp_captcha(),auth.getJ_auth_type(),userInfo);
|
||||
|
||||
authenticationRealm.passwordPolicyValid(userInfo);
|
||||
|
||||
authenticationRealm.passwordMatches(userInfo, auth.getJ_password());
|
||||
authenticationRealm.grantAuthority(userInfo);
|
||||
/**
|
||||
* put userInfo to current session context
|
||||
*/
|
||||
WebContext.setUserInfo(userInfo);
|
||||
|
||||
auth.setAuthenticated(true);
|
||||
|
||||
if(auth.isAuthenticated()&&applicationConfig.getLoginConfig().isRemeberMe()){
|
||||
if(auth.getJ_remeberme()!=null&&auth.getJ_remeberme().equals("remeberMe")){
|
||||
WebContext.getSession().setAttribute(WebConstants.REMEBER_ME_SESSION,auth.getJ_username());
|
||||
_logger.debug("do Remeber Me");
|
||||
remeberMeService.createRemeberMe(
|
||||
userInfo.getUsername(),
|
||||
WebContext.getRequest(),
|
||||
((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse());
|
||||
}
|
||||
}
|
||||
_logger.debug("authentication " + auth);
|
||||
|
||||
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken =new UsernamePasswordAuthenticationToken(
|
||||
auth,
|
||||
"PASSWORD",
|
||||
authenticationRealm.grantAuthority(userInfo));
|
||||
usernamePasswordAuthenticationToken.setDetails(new WebAuthenticationDetails(WebContext.getRequest()));
|
||||
|
||||
return usernamePasswordAuthenticationToken;
|
||||
sessionValid(auth.getJ_sessionid());
|
||||
|
||||
//jwtTokenValid(j_jwtToken);
|
||||
|
||||
authTypeValid(auth.getJ_auth_type());
|
||||
|
||||
captchaValid(auth.getJ_captcha(),auth.getJ_auth_type());
|
||||
|
||||
emptyPasswordValid(auth.getJ_password());
|
||||
|
||||
UserInfo userInfo = null;
|
||||
|
||||
emptyUsernameValid(auth.getJ_username());
|
||||
|
||||
userInfo= loadUserInfo(auth.getJ_username(),auth.getJ_password());
|
||||
|
||||
userinfoValid(userInfo, auth.getJ_password());
|
||||
|
||||
tftcaptchaValid(auth.getJ_otp_captcha(),auth.getJ_auth_type(),userInfo);
|
||||
|
||||
authenticationRealm.passwordPolicyValid(userInfo);
|
||||
|
||||
authenticationRealm.passwordMatches(userInfo, auth.getJ_password());
|
||||
authenticationRealm.grantAuthority(userInfo);
|
||||
/**
|
||||
* put userInfo to current session context
|
||||
*/
|
||||
WebContext.setUserInfo(userInfo);
|
||||
|
||||
auth.setAuthenticated(true);
|
||||
|
||||
if(auth.isAuthenticated()&&applicationConfig.getLoginConfig().isRemeberMe()){
|
||||
if(auth.getJ_remeberme()!=null&&auth.getJ_remeberme().equals("remeberMe")){
|
||||
WebContext.getSession().setAttribute(WebConstants.REMEBER_ME_SESSION,auth.getJ_username());
|
||||
_logger.debug("do Remeber Me");
|
||||
remeberMeService.createRemeberMe(
|
||||
userInfo.getUsername(),
|
||||
WebContext.getRequest(),
|
||||
((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse());
|
||||
}
|
||||
}
|
||||
|
||||
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken =new UsernamePasswordAuthenticationToken(
|
||||
auth,
|
||||
"PASSWORD",
|
||||
authenticationRealm.grantAuthority(userInfo));
|
||||
usernamePasswordAuthenticationToken.setDetails(new WebAuthenticationDetails(WebContext.getRequest()));
|
||||
|
||||
return usernamePasswordAuthenticationToken;
|
||||
}
|
||||
}
|
||||
@ -25,11 +25,17 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
||||
@ -17,23 +17,23 @@ package org.maxkey.authz.oauth2.common;
|
||||
*/
|
||||
public enum AuthenticationScheme {
|
||||
|
||||
/**
|
||||
* Send an Authorization header.
|
||||
*/
|
||||
header,
|
||||
/**
|
||||
* Send an Authorization header.
|
||||
*/
|
||||
header,
|
||||
|
||||
/**
|
||||
* Send a query parameter in the URI.
|
||||
*/
|
||||
query,
|
||||
/**
|
||||
* Send a query parameter in the URI.
|
||||
*/
|
||||
query,
|
||||
|
||||
/**
|
||||
* Send in the form body.
|
||||
*/
|
||||
form,
|
||||
/**
|
||||
* Send in the form body.
|
||||
*/
|
||||
form,
|
||||
|
||||
/**
|
||||
* Do not send at all.
|
||||
*/
|
||||
none
|
||||
/**
|
||||
* Do not send at all.
|
||||
*/
|
||||
none
|
||||
}
|
||||
@ -18,222 +18,227 @@ import java.util.TreeSet;
|
||||
*/
|
||||
public class DefaultOAuth2AccessToken implements Serializable, OAuth2AccessToken {
|
||||
|
||||
private static final long serialVersionUID = 914967629530462926L;
|
||||
private static final long serialVersionUID = 914967629530462926L;
|
||||
|
||||
private String value;
|
||||
private String value;
|
||||
|
||||
private Date expiration;
|
||||
private Date expiration;
|
||||
|
||||
private String tokenType = BEARER_TYPE.toLowerCase();
|
||||
private String tokenType = BEARER_TYPE.toLowerCase();
|
||||
|
||||
private OAuth2RefreshToken refreshToken;
|
||||
private OAuth2RefreshToken refreshToken;
|
||||
|
||||
private Set<String> scope;
|
||||
private Set<String> scope;
|
||||
|
||||
private Map<String, Object> additionalInformation = Collections.emptyMap();
|
||||
private Map<String, Object> additionalInformation = Collections.emptyMap();
|
||||
|
||||
/**
|
||||
* Create an access token from the value provided.
|
||||
*/
|
||||
public DefaultOAuth2AccessToken(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
/**
|
||||
* Create an access token from the value provided.
|
||||
*/
|
||||
public DefaultOAuth2AccessToken(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor for JPA and other serialization tools.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private DefaultOAuth2AccessToken() {
|
||||
this((String) null);
|
||||
}
|
||||
/**
|
||||
* Private constructor for JPA and other serialization tools.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private DefaultOAuth2AccessToken() {
|
||||
this((String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor for access token.
|
||||
*
|
||||
* @param accessToken
|
||||
*/
|
||||
public DefaultOAuth2AccessToken(OAuth2AccessToken accessToken) {
|
||||
this(accessToken.getValue());
|
||||
setAdditionalInformation(accessToken.getAdditionalInformation());
|
||||
setRefreshToken(accessToken.getRefreshToken());
|
||||
setExpiration(accessToken.getExpiration());
|
||||
setScope(accessToken.getScope());
|
||||
setTokenType(accessToken.getTokenType());
|
||||
}
|
||||
/**
|
||||
* Copy constructor for access token.
|
||||
*
|
||||
* @param accessToken
|
||||
*/
|
||||
public DefaultOAuth2AccessToken(OAuth2AccessToken accessToken) {
|
||||
this(accessToken.getValue());
|
||||
setAdditionalInformation(accessToken.getAdditionalInformation());
|
||||
setRefreshToken(accessToken.getRefreshToken());
|
||||
setExpiration(accessToken.getExpiration());
|
||||
setScope(accessToken.getScope());
|
||||
setTokenType(accessToken.getTokenType());
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The token value.
|
||||
*
|
||||
* @return The token value.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* The token value.
|
||||
*
|
||||
* @return The token value.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getExpiresIn() {
|
||||
return expiration != null ? Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L)
|
||||
.intValue() : 0;
|
||||
}
|
||||
public int getExpiresIn() {
|
||||
return expiration != null ? Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L).intValue()
|
||||
: 0;
|
||||
}
|
||||
|
||||
protected void setExpiresIn(int delta) {
|
||||
setExpiration(new Date(System.currentTimeMillis() + delta));
|
||||
}
|
||||
protected void setExpiresIn(int delta) {
|
||||
setExpiration(new Date(System.currentTimeMillis() + delta));
|
||||
}
|
||||
|
||||
/**
|
||||
* The instant the token expires.
|
||||
*
|
||||
* @return The instant the token expires.
|
||||
*/
|
||||
public Date getExpiration() {
|
||||
return expiration;
|
||||
}
|
||||
/**
|
||||
* The instant the token expires.
|
||||
*
|
||||
* @return The instant the token expires.
|
||||
*/
|
||||
public Date getExpiration() {
|
||||
return expiration;
|
||||
}
|
||||
|
||||
/**
|
||||
* The instant the token expires.
|
||||
*
|
||||
* @param expiration The instant the token expires.
|
||||
*/
|
||||
public void setExpiration(Date expiration) {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
/**
|
||||
* The instant the token expires.
|
||||
*
|
||||
* @param expiration The instant the token expires.
|
||||
*/
|
||||
public void setExpiration(Date expiration) {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for checking expiration
|
||||
*
|
||||
* @return true if the expiration is befor ethe current time
|
||||
*/
|
||||
public boolean isExpired() {
|
||||
return expiration != null && expiration.before(new Date());
|
||||
}
|
||||
/**
|
||||
* Convenience method for checking expiration
|
||||
*
|
||||
* @return true if the expiration is befor ethe current time
|
||||
*/
|
||||
public boolean isExpired() {
|
||||
return expiration != null && expiration.before(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* The token type, as introduced in draft 11 of the OAuth 2 spec. The spec doesn't define (yet) that the valid token
|
||||
* types are, but says it's required so the default will just be "undefined".
|
||||
*
|
||||
* @return The token type, as introduced in draft 11 of the OAuth 2 spec.
|
||||
*/
|
||||
public String getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
/**
|
||||
* The token type, as introduced in draft 11 of the OAuth 2 spec. The spec
|
||||
* doesn't define (yet) that the valid token types are, but says it's required
|
||||
* so the default will just be "undefined".
|
||||
*
|
||||
* @return The token type, as introduced in draft 11 of the OAuth 2 spec.
|
||||
*/
|
||||
public String getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The token type, as introduced in draft 11 of the OAuth 2 spec.
|
||||
*
|
||||
* @param tokenType The token type, as introduced in draft 11 of the OAuth 2 spec.
|
||||
*/
|
||||
public void setTokenType(String tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
}
|
||||
/**
|
||||
* The token type, as introduced in draft 11 of the OAuth 2 spec.
|
||||
*
|
||||
* @param tokenType The token type, as introduced in draft 11 of the OAuth 2
|
||||
* spec.
|
||||
*/
|
||||
public void setTokenType(String tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The refresh token associated with the access token, if any.
|
||||
*
|
||||
* @return The refresh token associated with the access token, if any.
|
||||
*/
|
||||
public OAuth2RefreshToken getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
/**
|
||||
* The refresh token associated with the access token, if any.
|
||||
*
|
||||
* @return The refresh token associated with the access token, if any.
|
||||
*/
|
||||
public OAuth2RefreshToken getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* The refresh token associated with the access token, if any.
|
||||
*
|
||||
* @param refreshToken The refresh token associated with the access token, if any.
|
||||
*/
|
||||
public void setRefreshToken(OAuth2RefreshToken refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
/**
|
||||
* The refresh token associated with the access token, if any.
|
||||
*
|
||||
* @param refreshToken The refresh token associated with the access token, if
|
||||
* any.
|
||||
*/
|
||||
public void setRefreshToken(OAuth2RefreshToken refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* The scope of the token.
|
||||
*
|
||||
* @return The scope of the token.
|
||||
*/
|
||||
public Set<String> getScope() {
|
||||
return scope;
|
||||
}
|
||||
/**
|
||||
* The scope of the token.
|
||||
*
|
||||
* @return The scope of the token.
|
||||
*/
|
||||
public Set<String> getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* The scope of the token.
|
||||
*
|
||||
* @param scope The scope of the token.
|
||||
*/
|
||||
public void setScope(Set<String> scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
/**
|
||||
* The scope of the token.
|
||||
*
|
||||
* @param scope The scope of the token.
|
||||
*/
|
||||
public void setScope(Set<String> scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null && toString().equals(obj.toString());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null && toString().equals(obj.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(getValue());
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(getValue());
|
||||
}
|
||||
|
||||
public static OAuth2AccessToken valueOf(Map<String, String> tokenParams) {
|
||||
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(tokenParams.get(ACCESS_TOKEN));
|
||||
public static OAuth2AccessToken valueOf(Map<String, String> tokenParams) {
|
||||
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(tokenParams.get(ACCESS_TOKEN));
|
||||
|
||||
if (tokenParams.containsKey(EXPIRES_IN)) {
|
||||
long expiration = 0;
|
||||
try {
|
||||
expiration = Long.parseLong(String.valueOf(tokenParams.get(EXPIRES_IN)));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// fall through...
|
||||
}
|
||||
token.setExpiration(new Date(System.currentTimeMillis() + (expiration * 1000L)));
|
||||
}
|
||||
if (tokenParams.containsKey(EXPIRES_IN)) {
|
||||
long expiration = 0;
|
||||
try {
|
||||
expiration = Long.parseLong(String.valueOf(tokenParams.get(EXPIRES_IN)));
|
||||
} catch (NumberFormatException e) {
|
||||
// fall through...
|
||||
}
|
||||
token.setExpiration(new Date(System.currentTimeMillis() + (expiration * 1000L)));
|
||||
}
|
||||
|
||||
if (tokenParams.containsKey(REFRESH_TOKEN)) {
|
||||
String refresh = tokenParams.get(REFRESH_TOKEN);
|
||||
DefaultOAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken(refresh);
|
||||
token.setRefreshToken(refreshToken);
|
||||
}
|
||||
if (tokenParams.containsKey(REFRESH_TOKEN)) {
|
||||
String refresh = tokenParams.get(REFRESH_TOKEN);
|
||||
DefaultOAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken(refresh);
|
||||
token.setRefreshToken(refreshToken);
|
||||
}
|
||||
|
||||
if (tokenParams.containsKey(SCOPE)) {
|
||||
Set<String> scope = new TreeSet<String>();
|
||||
for (StringTokenizer tokenizer = new StringTokenizer(tokenParams.get(SCOPE), " ,"); tokenizer
|
||||
.hasMoreTokens();) {
|
||||
scope.add(tokenizer.nextToken());
|
||||
}
|
||||
token.setScope(scope);
|
||||
}
|
||||
if (tokenParams.containsKey(SCOPE)) {
|
||||
Set<String> scope = new TreeSet<String>();
|
||||
for (StringTokenizer tokenizer = new StringTokenizer(tokenParams.get(SCOPE), " ,"); tokenizer
|
||||
.hasMoreTokens();) {
|
||||
scope.add(tokenizer.nextToken());
|
||||
}
|
||||
token.setScope(scope);
|
||||
}
|
||||
|
||||
if (tokenParams.containsKey(TOKEN_TYPE)) {
|
||||
token.setTokenType(tokenParams.get(TOKEN_TYPE));
|
||||
}
|
||||
if (tokenParams.containsKey(TOKEN_TYPE)) {
|
||||
token.setTokenType(tokenParams.get(TOKEN_TYPE));
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional information that token granters would like to add to the token, e.g. to support new token types.
|
||||
*
|
||||
* @return the additional information (default empty)
|
||||
*/
|
||||
public Map<String, Object> getAdditionalInformation() {
|
||||
return additionalInformation;
|
||||
}
|
||||
/**
|
||||
* Additional information that token granters would like to add to the token,
|
||||
* e.g. to support new token types.
|
||||
*
|
||||
* @return the additional information (default empty)
|
||||
*/
|
||||
public Map<String, Object> getAdditionalInformation() {
|
||||
return additionalInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional information that token granters would like to add to the token, e.g. to support new token types. If
|
||||
* the values in the map are primitive then remote communication is going to always work. It should also be safe to
|
||||
* use maps (nested if desired), or something that is explicitly serializable by Jackson.
|
||||
*
|
||||
* @param additionalInformation the additional information to set
|
||||
*/
|
||||
public void setAdditionalInformation(Map<String, Object> additionalInformation) {
|
||||
this.additionalInformation = new LinkedHashMap<String, Object>(additionalInformation);
|
||||
}
|
||||
/**
|
||||
* Additional information that token granters would like to add to the token,
|
||||
* e.g. to support new token types. If the values in the map are primitive then
|
||||
* remote communication is going to always work. It should also be safe to use
|
||||
* maps (nested if desired), or something that is explicitly serializable by
|
||||
* Jackson.
|
||||
*
|
||||
* @param additionalInformation the additional information to set
|
||||
*/
|
||||
public void setAdditionalInformation(Map<String, Object> additionalInformation) {
|
||||
this.additionalInformation = new LinkedHashMap<String, Object>(additionalInformation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
package org.maxkey.authz.oauth2.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* An OAuth 2 refresh token.
|
||||
@ -14,59 +12,59 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||
*/
|
||||
public class DefaultOAuth2RefreshToken implements Serializable, OAuth2RefreshToken {
|
||||
|
||||
private static final long serialVersionUID = 8349970621900575838L;
|
||||
private static final long serialVersionUID = 8349970621900575838L;
|
||||
|
||||
private String value;
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* Create a new refresh token.
|
||||
*/
|
||||
@JsonCreator
|
||||
public DefaultOAuth2RefreshToken(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for JPA and other serialization tools.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private DefaultOAuth2RefreshToken() {
|
||||
this(null);
|
||||
}
|
||||
/**
|
||||
* Create a new refresh token.
|
||||
*/
|
||||
@JsonCreator
|
||||
public DefaultOAuth2RefreshToken(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for JPA and other serialization tools.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private DefaultOAuth2RefreshToken() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.security.oauth2.common.IFOO#getValue()
|
||||
*/
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.security.oauth2.common.IFOO#getValue()
|
||||
*/
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getValue();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof DefaultOAuth2RefreshToken)) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof DefaultOAuth2RefreshToken)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DefaultOAuth2RefreshToken that = (DefaultOAuth2RefreshToken) o;
|
||||
DefaultOAuth2RefreshToken that = (DefaultOAuth2RefreshToken) o;
|
||||
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) {
|
||||
return false;
|
||||
}
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value != null ? value.hashCode() : 0;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value != null ? value.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
package org.maxkey;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.apache.ibatis.io.VFS;
|
||||
import org.apache.mybatis.jpa.SpringBootVFS;
|
||||
import org.maxkey.web.InitApplicationContext;
|
||||
@ -17,25 +15,30 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MaxKeyApplication extends SpringBootServletInitializer {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyApplication.class);
|
||||
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
VFS.addImplClass(SpringBootVFS.class);
|
||||
ConfigurableApplicationContext applicationContext =SpringApplication.run(MaxKeyApplication.class, args);
|
||||
InitApplicationContext initWebContext=new InitApplicationContext(applicationContext);
|
||||
try {
|
||||
initWebContext.init(null);
|
||||
} catch (ServletException e) {
|
||||
e.printStackTrace();
|
||||
_logger.error("",e);
|
||||
}
|
||||
_logger.info("MaxKey at "+new Date(applicationContext.getStartupDate()));
|
||||
_logger.info("MaxKey Server Port "+applicationContext.getBean(MaxKeyConfig.class).getPort());
|
||||
_logger.info("MaxKey started.");
|
||||
}
|
||||
/**
|
||||
* @param args args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
VFS.addImplClass(SpringBootVFS.class);
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
SpringApplication.run(MaxKeyApplication.class, args);
|
||||
InitApplicationContext initWebContext = new InitApplicationContext(applicationContext);
|
||||
try {
|
||||
initWebContext.init(null);
|
||||
} catch (ServletException e) {
|
||||
e.printStackTrace();
|
||||
_logger.error("", e);
|
||||
}
|
||||
_logger.info("MaxKey at " + new Date(applicationContext.getStartupDate()));
|
||||
_logger.info("MaxKey Server Port "
|
||||
+ applicationContext.getBean(MaxKeyConfig.class).getPort());
|
||||
_logger.info("MaxKey started.");
|
||||
}
|
||||
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(MaxKeyApplication.class);
|
||||
}
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(MaxKeyApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,21 +18,21 @@ import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@Configuration
|
||||
@ImportResource(locations={"classpath:spring/maxkey.xml"})
|
||||
@ImportResource(locations = { "classpath:spring/maxkey.xml" })
|
||||
@PropertySource("classpath:/application.properties")
|
||||
public class MaxKeyConfig {
|
||||
@Value("${server.port:8080}")
|
||||
@Value("${server.port:8080}")
|
||||
private int port;
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<TokenEndpointAuthenticationFilter> TokenEndpointAuthenticationFilter() {
|
||||
FilterRegistrationBean<TokenEndpointAuthenticationFilter> registration = new FilterRegistrationBean<TokenEndpointAuthenticationFilter>();
|
||||
registration.setFilter(new TokenEndpointAuthenticationFilter());
|
||||
@ -41,52 +41,50 @@ public class MaxKeyConfig {
|
||||
registration.setOrder(1);
|
||||
return registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置默认错误页面(仅用于内嵌tomcat启动时)
|
||||
* 使用这种方式,在打包为war后不起作用
|
||||
|
||||
/**
|
||||
* 配置默认错误页面(仅用于内嵌tomcat启动时) 使用这种方式,在打包为war后不起作用
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
|
||||
return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
|
||||
*/
|
||||
@Bean
|
||||
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
|
||||
return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
|
||||
@Override
|
||||
public void customize(ConfigurableWebServerFactory factory) {
|
||||
ErrorPage errorPage400 = new ErrorPage(HttpStatus.BAD_REQUEST,"/exception/error/400");
|
||||
ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND,"/exception/error/404");
|
||||
ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/exception/error/500");
|
||||
factory.addErrorPages(errorPage400, errorPage404,errorPage500);
|
||||
|
||||
ErrorPage errorPage400 = new ErrorPage(HttpStatus.BAD_REQUEST, "/exception/error/400");
|
||||
ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND, "/exception/error/404");
|
||||
ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/exception/error/500");
|
||||
factory.addErrorPages(errorPage400, errorPage404, errorPage500);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Connector connector() {
|
||||
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
|
||||
connector.setScheme("http");
|
||||
connector.setPort(80);
|
||||
connector.setSecure(false);
|
||||
connector.setRedirectPort(443);
|
||||
return connector;
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector) {
|
||||
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
|
||||
@Override
|
||||
protected void postProcessContext(Context context) {
|
||||
SecurityConstraint securityConstraint = new SecurityConstraint();
|
||||
securityConstraint.setUserConstraint("CONFIDENTIAL");
|
||||
SecurityCollection collection = new SecurityCollection();
|
||||
collection.addPattern("/*");
|
||||
securityConstraint.addCollection(collection);
|
||||
context.addConstraint(securityConstraint);
|
||||
}
|
||||
};
|
||||
tomcat.addAdditionalTomcatConnectors(connector);
|
||||
return tomcat;
|
||||
}
|
||||
@Bean
|
||||
public Connector connector() {
|
||||
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
|
||||
connector.setScheme("http");
|
||||
connector.setPort(80);
|
||||
connector.setSecure(false);
|
||||
connector.setRedirectPort(443);
|
||||
return connector;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector) {
|
||||
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
|
||||
@Override
|
||||
protected void postProcessContext(Context context) {
|
||||
SecurityConstraint securityConstraint = new SecurityConstraint();
|
||||
securityConstraint.setUserConstraint("CONFIDENTIAL");
|
||||
SecurityCollection collection = new SecurityCollection();
|
||||
collection.addPattern("/*");
|
||||
securityConstraint.addCollection(collection);
|
||||
context.addConstraint(securityConstraint);
|
||||
}
|
||||
};
|
||||
tomcat.addAdditionalTomcatConnectors(connector);
|
||||
return tomcat;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package org.maxkey.web.contorller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.maxkey.constants.OPERATEMESSAGE;
|
||||
import org.maxkey.constants.PROTOCOLS;
|
||||
import org.maxkey.crypto.ReciprocalUtils;
|
||||
@ -27,217 +26,233 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* AppListController.
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class AppListController{
|
||||
final static Logger _logger = LoggerFactory.getLogger(AppListController.class);
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
MyAppsListService myAppsListService;
|
||||
|
||||
@Autowired
|
||||
AccountsService appUsersService;
|
||||
|
||||
@Autowired
|
||||
AppsService appsService;
|
||||
|
||||
@RequestMapping(value={"/appList"})
|
||||
public ModelAndView appList(@RequestParam(value="gridList",required = false) String gridList) {
|
||||
ModelAndView modelAndView=new ModelAndView("main/appList");
|
||||
|
||||
if(gridList!=null&&!gridList.equals("")){
|
||||
int intGridList=Integer.parseInt(gridList);
|
||||
jdbcTemplate.update("UPDATE USERINFO SET GRIDLIST = ? WHERE ID = ?",
|
||||
intGridList,WebContext.getUserInfo().getId());
|
||||
WebContext.getUserInfo().setGridList(intGridList);
|
||||
}
|
||||
modelAndView.addObject("appList", queryAccessableApps());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value={"/appConfigList"})
|
||||
public ModelAndView appConfigList() {
|
||||
ModelAndView modelAndView=new ModelAndView("main/appConfigList");
|
||||
modelAndView.addObject("appList", queryAccessableApps());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
|
||||
private List<UserApps> queryAccessableApps(){
|
||||
UserApps userApplications=new UserApps();
|
||||
userApplications.setUsername(WebContext.getUserInfo().getUsername());
|
||||
|
||||
List<UserApps> appList=myAppsListService.queryMyApps(userApplications);
|
||||
for (UserApps app : appList){
|
||||
WebContext.setAttribute(app.getId(), app.getIcon());
|
||||
}
|
||||
|
||||
return appList;
|
||||
}
|
||||
public class AppListController {
|
||||
static final Logger _logger = LoggerFactory.getLogger(AppListController.class);
|
||||
|
||||
@RequestMapping(value={"/forward/appProtectedConfig/{protocol}/{credential}/{appId}"})
|
||||
public ModelAndView forwardAppLoginConfig(
|
||||
@PathVariable("protocol") String protocol,
|
||||
@PathVariable("credential") int credential,
|
||||
@PathVariable("appId") String appId){
|
||||
ModelAndView modelAndView=new ModelAndView("main/appProtectedConfig");
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
|
||||
if(userInfo.getProtectedAppsMap().get(appId)!=null){
|
||||
modelAndView.addObject("protectedappId",true);
|
||||
}else{
|
||||
modelAndView.addObject("protectedappId",false);
|
||||
}
|
||||
modelAndView.addObject("uid",userInfo.getId());
|
||||
modelAndView.addObject("appId",appId);
|
||||
modelAndView.addObject("protocol",protocol);
|
||||
modelAndView.addObject("credential",credential);
|
||||
return modelAndView;
|
||||
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value={"/appProtectedConfig"})
|
||||
public Message appLoginConfig(
|
||||
@RequestParam("protocol") String protocol,
|
||||
@RequestParam("credential") int credential,
|
||||
@RequestParam("appId") String appId,
|
||||
@RequestParam("protectedappId") String protectedappId,
|
||||
@RequestParam("password") String password
|
||||
){
|
||||
@Autowired
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
String userAppProtectedPassword=ReciprocalUtils.decoder(userInfo.getAppLoginPassword());
|
||||
if(userAppProtectedPassword.equals(password)){
|
||||
|
||||
if(protectedappId.equalsIgnoreCase("YES")){
|
||||
if(userInfo.getProtectedApps()!=null&&userInfo.getProtectedApps().indexOf(appId)<0){
|
||||
userInfo.setProtectedApps(userInfo.getProtectedApps()+","+appId);
|
||||
if(userInfo.getProtectedAppsMap()!=null){
|
||||
userInfo.getProtectedAppsMap().put(appId, appId);
|
||||
}
|
||||
}else{
|
||||
userInfo.setProtectedApps(","+appId);
|
||||
}
|
||||
}else{
|
||||
if(userInfo.getProtectedApps()!=null&&userInfo.getProtectedApps().indexOf(appId)>-1){
|
||||
//userInfo.setSecondProtectedApps(userInfo.getSecondProtectedApps()+","+appId);
|
||||
String []protectedApps=userInfo.getProtectedApps().split(",");
|
||||
String protectedAppIds="";
|
||||
if(userInfo.getProtectedAppsMap()!=null){
|
||||
userInfo.getProtectedAppsMap().remove(appId);
|
||||
}
|
||||
for(String protectedAppId:protectedApps){
|
||||
if(protectedAppId.equalsIgnoreCase(appId)||protectedAppId.trim().equals(""))continue;
|
||||
protectedAppIds=protectedAppIds+","+protectedAppId;
|
||||
}
|
||||
userInfo.setProtectedApps(protectedAppIds);
|
||||
}
|
||||
}
|
||||
|
||||
userInfoService.updateProtectedApps(userInfo);
|
||||
}else{
|
||||
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_ERROR),MessageType.error);
|
||||
}
|
||||
|
||||
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS),MessageType.success);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value={"/forward/appUserConfig/{protocol}/{credential}/{appId}"})
|
||||
public ModelAndView forwardAppUserConfig(
|
||||
@PathVariable("protocol") String protocol,
|
||||
@PathVariable("credential") int credential,
|
||||
@PathVariable("appId") String appId){
|
||||
ModelAndView modelAndView=new ModelAndView("main/appUserConfig");
|
||||
//modelAndView.addObject("appList",appList);
|
||||
|
||||
Accounts appUsers=new Accounts();
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
if(credential==Apps.CREDENTIALS.USER_DEFINED){
|
||||
appUsers=appUsersService.load(new Accounts(userInfo.getId(),appId));
|
||||
if(protocol.equalsIgnoreCase(PROTOCOLS.DESKTOP)||
|
||||
protocol.equalsIgnoreCase(PROTOCOLS.FORMBASED)||
|
||||
protocol.equalsIgnoreCase(PROTOCOLS.BASIC)||
|
||||
protocol.equalsIgnoreCase(PROTOCOLS.EXTEND_API)
|
||||
){
|
||||
|
||||
modelAndView.addObject("username",true);
|
||||
modelAndView.addObject("password",true);
|
||||
}else if(protocol.equalsIgnoreCase(PROTOCOLS.SAML20)
|
||||
){
|
||||
modelAndView.addObject("username",true);
|
||||
modelAndView.addObject("password",false);
|
||||
}else{
|
||||
modelAndView.addObject("username",false);
|
||||
modelAndView.addObject("password",false);
|
||||
}
|
||||
if(appUsers!=null){
|
||||
modelAndView.addObject("identity_username",appUsers.getRelatedUsername());
|
||||
modelAndView.addObject("identity_password",ReciprocalUtils.decoder(appUsers.getRelatedPassword()));
|
||||
}else{
|
||||
modelAndView.addObject("identity_username","");
|
||||
modelAndView.addObject("identity_password","");
|
||||
}
|
||||
}else{
|
||||
modelAndView.addObject("username",false);
|
||||
modelAndView.addObject("password",false);
|
||||
}
|
||||
|
||||
modelAndView.addObject("uid",userInfo.getId());
|
||||
modelAndView.addObject("appId",appId);
|
||||
modelAndView.addObject("protocol",protocol);
|
||||
modelAndView.addObject("credential",credential);
|
||||
return modelAndView;
|
||||
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value={"/appUserConfig"})
|
||||
public Message appUserConfig(
|
||||
@RequestParam("protocol") String protocol,
|
||||
@RequestParam("credential") int credential,
|
||||
@RequestParam("appId") String appId,
|
||||
@RequestParam("identity_username") String identity_username,
|
||||
@RequestParam("identity_password") String identity_password
|
||||
){
|
||||
|
||||
Apps app=appsService.get(appId);
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
|
||||
Accounts appUsers=new Accounts();
|
||||
appUsers.setAppId(appId);
|
||||
appUsers.setUid(userInfo.getId());
|
||||
|
||||
if(identity_password!=null&&!identity_password.equals("")&&credential==Apps.CREDENTIALS.USER_DEFINED){
|
||||
appUsers=appUsersService.load(new Accounts(userInfo.getId(),appId));
|
||||
if(appUsers==null){
|
||||
appUsers=new Accounts();
|
||||
appUsers.setId(appUsers.generateId());
|
||||
appUsers.setAppId(appId);
|
||||
appUsers.setAppName(app.getName());
|
||||
appUsers.setUid(userInfo.getId());
|
||||
appUsers.setUsername(userInfo.getUsername());
|
||||
appUsers.setDisplayName(userInfo.getDisplayName());
|
||||
|
||||
appUsers.setRelatedUsername(identity_username);
|
||||
appUsers.setRelatedPassword(ReciprocalUtils.encode(identity_password));
|
||||
appUsersService.insert(appUsers);
|
||||
}else{
|
||||
appUsers.setRelatedUsername(identity_username);
|
||||
appUsers.setRelatedPassword(ReciprocalUtils.encode(identity_password));
|
||||
appUsersService.update(appUsers);
|
||||
}
|
||||
}
|
||||
|
||||
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS),MessageType.success);
|
||||
}
|
||||
@Autowired
|
||||
MyAppsListService myAppsListService;
|
||||
|
||||
@Autowired
|
||||
AccountsService appUsersService;
|
||||
|
||||
@Autowired
|
||||
AppsService appsService;
|
||||
|
||||
/**
|
||||
* gridList.
|
||||
* @param gridList 类型
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = { "/appList" })
|
||||
public ModelAndView appList(
|
||||
@RequestParam(value = "gridList", required = false) String gridList) {
|
||||
ModelAndView modelAndView = new ModelAndView("main/appList");
|
||||
|
||||
if (gridList != null && !gridList.equals("")) {
|
||||
int intGridList = Integer.parseInt(gridList);
|
||||
jdbcTemplate.update("UPDATE USERINFO SET GRIDLIST = ? WHERE ID = ?", intGridList,
|
||||
WebContext.getUserInfo().getId());
|
||||
WebContext.getUserInfo().setGridList(intGridList);
|
||||
}
|
||||
modelAndView.addObject("appList", queryAccessableApps());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/appConfigList" })
|
||||
public ModelAndView appConfigList() {
|
||||
ModelAndView modelAndView = new ModelAndView("main/appConfigList");
|
||||
modelAndView.addObject("appList", queryAccessableApps());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
private List<UserApps> queryAccessableApps() {
|
||||
UserApps userApplications = new UserApps();
|
||||
userApplications.setUsername(WebContext.getUserInfo().getUsername());
|
||||
|
||||
List<UserApps> appList = myAppsListService.queryMyApps(userApplications);
|
||||
for (UserApps app : appList) {
|
||||
WebContext.setAttribute(app.getId(), app.getIcon());
|
||||
}
|
||||
|
||||
return appList;
|
||||
}
|
||||
|
||||
/**
|
||||
* forwardAppLoginConfig.
|
||||
* @param protocol protocol
|
||||
* @param credential credential
|
||||
* @param appId appId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = { "/forward/appProtectedConfig/{protocol}/{credential}/{appId}" })
|
||||
public ModelAndView forwardAppLoginConfig(@PathVariable("protocol") String protocol,
|
||||
@PathVariable("credential") int credential, @PathVariable("appId") String appId) {
|
||||
ModelAndView modelAndView = new ModelAndView("main/appProtectedConfig");
|
||||
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
|
||||
if (userInfo.getProtectedAppsMap().get(appId) != null) {
|
||||
modelAndView.addObject("protectedappId", true);
|
||||
} else {
|
||||
modelAndView.addObject("protectedappId", false);
|
||||
}
|
||||
modelAndView.addObject("uid", userInfo.getId());
|
||||
modelAndView.addObject("appId", appId);
|
||||
modelAndView.addObject("protocol", protocol);
|
||||
modelAndView.addObject("credential", credential);
|
||||
return modelAndView;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* appLoginConfig.
|
||||
* @param protocol protocol
|
||||
* @param credential credential
|
||||
* @param appId appId
|
||||
* @param protectedappId protectedappId
|
||||
* @param password password
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(value = { "/appProtectedConfig" })
|
||||
public Message appLoginConfig(
|
||||
@RequestParam("protocol") String protocol,
|
||||
@RequestParam("credential") int credential,
|
||||
@RequestParam("appId") String appId,
|
||||
@RequestParam("protectedappId") String protectedappId,
|
||||
@RequestParam("password") String password) {
|
||||
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
String userAppProtectedPassword = ReciprocalUtils.decoder(userInfo.getAppLoginPassword());
|
||||
if (userAppProtectedPassword.equals(password)) {
|
||||
|
||||
if (protectedappId.equalsIgnoreCase("YES")) {
|
||||
if (userInfo.getProtectedApps() != null
|
||||
&& userInfo.getProtectedApps().indexOf(appId) < 0) {
|
||||
userInfo.setProtectedApps(userInfo.getProtectedApps() + "," + appId);
|
||||
if (userInfo.getProtectedAppsMap() != null) {
|
||||
userInfo.getProtectedAppsMap().put(appId, appId);
|
||||
}
|
||||
} else {
|
||||
userInfo.setProtectedApps("," + appId);
|
||||
}
|
||||
} else {
|
||||
if (userInfo.getProtectedApps() != null
|
||||
&& userInfo.getProtectedApps().indexOf(appId) > -1) {
|
||||
// userInfo.setSecondProtectedApps(userInfo.getSecondProtectedApps()+","+appId);
|
||||
String[] protectedApps = userInfo.getProtectedApps().split(",");
|
||||
String protectedAppIds = "";
|
||||
if (userInfo.getProtectedAppsMap() != null) {
|
||||
userInfo.getProtectedAppsMap().remove(appId);
|
||||
}
|
||||
for (String protectedAppId : protectedApps) {
|
||||
if (protectedAppId.equalsIgnoreCase(appId)
|
||||
|| protectedAppId.trim().equals("")) {
|
||||
continue;
|
||||
}
|
||||
protectedAppIds = protectedAppIds + "," + protectedAppId;
|
||||
}
|
||||
userInfo.setProtectedApps(protectedAppIds);
|
||||
}
|
||||
}
|
||||
|
||||
userInfoService.updateProtectedApps(userInfo);
|
||||
} else {
|
||||
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_ERROR), MessageType.error);
|
||||
}
|
||||
|
||||
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS), MessageType.success);
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/forward/appUserConfig/{protocol}/{credential}/{appId}" })
|
||||
public ModelAndView forwardAppUserConfig(@PathVariable("protocol") String protocol,
|
||||
@PathVariable("credential") int credential, @PathVariable("appId") String appId) {
|
||||
ModelAndView modelAndView = new ModelAndView("main/appUserConfig");
|
||||
// modelAndView.addObject("appList",appList);
|
||||
|
||||
Accounts appUsers = new Accounts();
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
if (credential == Apps.CREDENTIALS.USER_DEFINED) {
|
||||
appUsers = appUsersService.load(new Accounts(userInfo.getId(), appId));
|
||||
if (protocol.equalsIgnoreCase(PROTOCOLS.DESKTOP) || protocol.equalsIgnoreCase(PROTOCOLS.FORMBASED)
|
||||
|| protocol.equalsIgnoreCase(PROTOCOLS.BASIC) || protocol.equalsIgnoreCase(PROTOCOLS.EXTEND_API)) {
|
||||
|
||||
modelAndView.addObject("username", true);
|
||||
modelAndView.addObject("password", true);
|
||||
} else if (protocol.equalsIgnoreCase(PROTOCOLS.SAML20)) {
|
||||
modelAndView.addObject("username", true);
|
||||
modelAndView.addObject("password", false);
|
||||
} else {
|
||||
modelAndView.addObject("username", false);
|
||||
modelAndView.addObject("password", false);
|
||||
}
|
||||
if (appUsers != null) {
|
||||
modelAndView.addObject("identity_username", appUsers.getRelatedUsername());
|
||||
modelAndView.addObject("identity_password", ReciprocalUtils.decoder(appUsers.getRelatedPassword()));
|
||||
} else {
|
||||
modelAndView.addObject("identity_username", "");
|
||||
modelAndView.addObject("identity_password", "");
|
||||
}
|
||||
} else {
|
||||
modelAndView.addObject("username", false);
|
||||
modelAndView.addObject("password", false);
|
||||
}
|
||||
|
||||
modelAndView.addObject("uid", userInfo.getId());
|
||||
modelAndView.addObject("appId", appId);
|
||||
modelAndView.addObject("protocol", protocol);
|
||||
modelAndView.addObject("credential", credential);
|
||||
return modelAndView;
|
||||
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = { "/appUserConfig" })
|
||||
public Message appUserConfig(@RequestParam("protocol") String protocol, @RequestParam("credential") int credential,
|
||||
@RequestParam("appId") String appId, @RequestParam("identity_username") String identity_username,
|
||||
@RequestParam("identity_password") String identity_password) {
|
||||
|
||||
Apps app = appsService.get(appId);
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
|
||||
Accounts appUsers = new Accounts();
|
||||
appUsers.setAppId(appId);
|
||||
appUsers.setUid(userInfo.getId());
|
||||
|
||||
if (identity_password != null && !identity_password.equals("") && credential == Apps.CREDENTIALS.USER_DEFINED) {
|
||||
appUsers = appUsersService.load(new Accounts(userInfo.getId(), appId));
|
||||
if (appUsers == null) {
|
||||
appUsers = new Accounts();
|
||||
appUsers.setId(appUsers.generateId());
|
||||
appUsers.setAppId(appId);
|
||||
appUsers.setAppName(app.getName());
|
||||
appUsers.setUid(userInfo.getId());
|
||||
appUsers.setUsername(userInfo.getUsername());
|
||||
appUsers.setDisplayName(userInfo.getDisplayName());
|
||||
|
||||
appUsers.setRelatedUsername(identity_username);
|
||||
appUsers.setRelatedPassword(ReciprocalUtils.encode(identity_password));
|
||||
appUsersService.insert(appUsers);
|
||||
} else {
|
||||
appUsers.setRelatedUsername(identity_username);
|
||||
appUsers.setRelatedPassword(ReciprocalUtils.encode(identity_password));
|
||||
appUsersService.update(appUsers);
|
||||
}
|
||||
}
|
||||
|
||||
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS), MessageType.success);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,120 +19,119 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value={"/forgotpassword"})
|
||||
@RequestMapping(value = { "/forgotpassword" })
|
||||
public class ForgotPasswordContorller {
|
||||
|
||||
private static Logger _logger = LoggerFactory.getLogger(ForgotPasswordContorller.class);
|
||||
|
||||
@Autowired
|
||||
ForgotPasswordService forgotPasswordService;
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
|
||||
@RequestMapping(value={"/forward"})
|
||||
public ModelAndView forwardreg() {
|
||||
_logger.debug("Registration /forgotpassword/forward.");
|
||||
return new ModelAndView("forgotpassword/forward");
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value={"/email"})
|
||||
public ModelAndView email(@RequestParam String email) {
|
||||
_logger.debug("Registration /forgotpassword/email.");
|
||||
_logger.debug("email : "+email);
|
||||
UserInfo userInfo=forgotPasswordService.queryUserInfoByEmail(email);
|
||||
ModelAndView modelAndView=new ModelAndView("forgotpassword/email");
|
||||
modelAndView.addObject("emailsend", 0);
|
||||
modelAndView.addObject("email", email);
|
||||
|
||||
if(userInfo!=null){
|
||||
ForgotPassword forgotPassword =new ForgotPassword();
|
||||
forgotPassword.setId(forgotPassword.generateId());
|
||||
forgotPassword.setEmail(email);
|
||||
forgotPassword.setUid(userInfo.getId());
|
||||
forgotPassword.setUsername(userInfo.getUsername());
|
||||
forgotPasswordService.insert(forgotPassword);
|
||||
|
||||
HtmlEmail hemail = new HtmlEmail();
|
||||
|
||||
try {
|
||||
hemail.setHostName(applicationConfig.getEmailConfig().getSmtpHost());
|
||||
hemail.setSmtpPort(applicationConfig.getEmailConfig().getPort());
|
||||
hemail.setAuthenticator(new DefaultAuthenticator(applicationConfig.getEmailConfig().getUsername(), applicationConfig.getEmailConfig().getPassword()));
|
||||
|
||||
hemail.addTo(userInfo.getEmail(), userInfo.getNickName());
|
||||
hemail.setFrom(applicationConfig.getEmailConfig().getSenderMail(), "ConnSec");
|
||||
hemail.setSubject("ConnSec Cloud Identity & Access ReSet Password .");
|
||||
|
||||
// set the html message
|
||||
String forgotPasswordUrl=WebContext.getHttpContextPath()+"/forgotpassword/resetpwd/"+forgotPassword.getId();
|
||||
|
||||
|
||||
// set the html message
|
||||
String emailText="<html>";
|
||||
emailText+="<a href='"+forgotPasswordUrl+"'>Reset Password</a><br>";
|
||||
emailText+=" or copy "+forgotPasswordUrl+" to brower.";
|
||||
emailText+="</html>";
|
||||
|
||||
hemail.setHtmlMsg(emailText);
|
||||
|
||||
// set the alternative message
|
||||
hemail.setTextMsg("Your email client does not support HTML messages");
|
||||
|
||||
// send the email
|
||||
hemail.send();
|
||||
modelAndView.addObject("emailsend", 1);
|
||||
} catch (EmailException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return modelAndView ;
|
||||
}
|
||||
|
||||
@RequestMapping(value={"/resetpwd/{id}"})
|
||||
public ModelAndView resetpwd(@PathVariable("id") String id) {
|
||||
_logger.debug("Registration /forgotpassword/resetpwd.");
|
||||
ForgotPassword forgotPassword=forgotPasswordService.get(id);
|
||||
ModelAndView mav=new ModelAndView("forgotpassword/resetpwd");
|
||||
if(forgotPassword!=null){
|
||||
mav.addObject("model", forgotPassword);
|
||||
}
|
||||
|
||||
return mav;
|
||||
}
|
||||
|
||||
@RequestMapping(value={"/setpassword/{id}"})
|
||||
public ModelAndView setPassWord(@PathVariable("id") String id,@RequestParam String password,@RequestParam String confirmpassword) {
|
||||
_logger.debug("forgotPassword /forgotPassword/pwdreseted.");
|
||||
ModelAndView modelAndView=new ModelAndView("forgotpassword/pwdreseted");
|
||||
if(password.equals(confirmpassword)){
|
||||
ForgotPassword forgotPassword=forgotPasswordService.get(id);
|
||||
if(forgotPassword!=null){
|
||||
UserInfo userInfo=new UserInfo();
|
||||
userInfo.setId(forgotPassword.getUid());
|
||||
userInfo.setPassword(password);
|
||||
userInfo.setDecipherable(password);
|
||||
userInfo.setUsername(forgotPassword.getUsername());
|
||||
userInfoService.changePassword(userInfo);
|
||||
forgotPasswordService.remove(id);
|
||||
modelAndView.addObject("pwdreseted", 1);
|
||||
}else{
|
||||
modelAndView.addObject("pwdreseted", 2);
|
||||
}
|
||||
}else{
|
||||
modelAndView.addObject("pwdreseted", 0);
|
||||
}
|
||||
return modelAndView;
|
||||
}
|
||||
private static Logger _logger = LoggerFactory.getLogger(ForgotPasswordContorller.class);
|
||||
|
||||
@Autowired
|
||||
ForgotPasswordService forgotPasswordService;
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@RequestMapping(value = { "/forward" })
|
||||
public ModelAndView forwardreg() {
|
||||
_logger.debug("Registration /forgotpassword/forward.");
|
||||
return new ModelAndView("forgotpassword/forward");
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/email" })
|
||||
public ModelAndView email(@RequestParam String email) {
|
||||
_logger.debug("Registration /forgotpassword/email.");
|
||||
_logger.debug("email : " + email);
|
||||
UserInfo userInfo = forgotPasswordService.queryUserInfoByEmail(email);
|
||||
ModelAndView modelAndView = new ModelAndView("forgotpassword/email");
|
||||
modelAndView.addObject("emailsend", 0);
|
||||
modelAndView.addObject("email", email);
|
||||
|
||||
if (userInfo != null) {
|
||||
ForgotPassword forgotPassword = new ForgotPassword();
|
||||
forgotPassword.setId(forgotPassword.generateId());
|
||||
forgotPassword.setEmail(email);
|
||||
forgotPassword.setUid(userInfo.getId());
|
||||
forgotPassword.setUsername(userInfo.getUsername());
|
||||
forgotPasswordService.insert(forgotPassword);
|
||||
|
||||
HtmlEmail hemail = new HtmlEmail();
|
||||
|
||||
try {
|
||||
hemail.setHostName(applicationConfig.getEmailConfig().getSmtpHost());
|
||||
hemail.setSmtpPort(applicationConfig.getEmailConfig().getPort());
|
||||
hemail.setAuthenticator(new DefaultAuthenticator(applicationConfig.getEmailConfig().getUsername(),
|
||||
applicationConfig.getEmailConfig().getPassword()));
|
||||
|
||||
hemail.addTo(userInfo.getEmail(), userInfo.getNickName());
|
||||
hemail.setFrom(applicationConfig.getEmailConfig().getSenderMail(), "ConnSec");
|
||||
hemail.setSubject("ConnSec Cloud Identity & Access ReSet Password .");
|
||||
|
||||
// set the html message
|
||||
String forgotPasswordUrl = WebContext.getHttpContextPath() + "/forgotpassword/resetpwd/"
|
||||
+ forgotPassword.getId();
|
||||
|
||||
// set the html message
|
||||
String emailText = "<html>";
|
||||
emailText += "<a href='" + forgotPasswordUrl + "'>Reset Password</a><br>";
|
||||
emailText += " or copy " + forgotPasswordUrl + " to brower.";
|
||||
emailText += "</html>";
|
||||
|
||||
hemail.setHtmlMsg(emailText);
|
||||
|
||||
// set the alternative message
|
||||
hemail.setTextMsg("Your email client does not support HTML messages");
|
||||
|
||||
// send the email
|
||||
hemail.send();
|
||||
modelAndView.addObject("emailsend", 1);
|
||||
} catch (EmailException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/resetpwd/{id}" })
|
||||
public ModelAndView resetpwd(@PathVariable("id") String id) {
|
||||
_logger.debug("Registration /forgotpassword/resetpwd.");
|
||||
ForgotPassword forgotPassword = forgotPasswordService.get(id);
|
||||
ModelAndView mav = new ModelAndView("forgotpassword/resetpwd");
|
||||
if (forgotPassword != null) {
|
||||
mav.addObject("model", forgotPassword);
|
||||
}
|
||||
|
||||
return mav;
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/setpassword/{id}" })
|
||||
public ModelAndView setPassWord(@PathVariable("id") String id, @RequestParam String password,
|
||||
@RequestParam String confirmpassword) {
|
||||
_logger.debug("forgotPassword /forgotPassword/pwdreseted.");
|
||||
ModelAndView modelAndView = new ModelAndView("forgotpassword/pwdreseted");
|
||||
if (password.equals(confirmpassword)) {
|
||||
ForgotPassword forgotPassword = forgotPasswordService.get(id);
|
||||
if (forgotPassword != null) {
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setId(forgotPassword.getUid());
|
||||
userInfo.setPassword(password);
|
||||
userInfo.setDecipherable(password);
|
||||
userInfo.setUsername(forgotPassword.getUsername());
|
||||
userInfoService.changePassword(userInfo);
|
||||
forgotPasswordService.remove(id);
|
||||
modelAndView.addObject("pwdreseted", 1);
|
||||
} else {
|
||||
modelAndView.addObject("pwdreseted", 2);
|
||||
}
|
||||
} else {
|
||||
modelAndView.addObject("pwdreseted", 0);
|
||||
}
|
||||
return modelAndView;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,13 +2,12 @@ package org.maxkey.web.contorller;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.mybatis.jpa.persistence.JpaPageResults;
|
||||
import org.maxkey.dao.service.HistoryLoginAppsService;
|
||||
import org.maxkey.dao.service.HistoryLoginService;
|
||||
import org.maxkey.dao.service.HistoryLogsService;
|
||||
import org.maxkey.domain.HistoryLoginApps;
|
||||
import org.maxkey.domain.HistoryLogin;
|
||||
import org.maxkey.domain.HistoryLoginApps;
|
||||
import org.maxkey.domain.HistoryLogs;
|
||||
import org.maxkey.util.DateUtils;
|
||||
import org.maxkey.web.WebContext;
|
||||
@ -24,89 +23,89 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* 登录日志和操作日志查询
|
||||
* 登录日志和操作日志查询.
|
||||
*
|
||||
* @author Crystal.sea
|
||||
*
|
||||
*/
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value={"/historys"})
|
||||
@RequestMapping(value = { "/historys" })
|
||||
public class HistorysController {
|
||||
final static Logger _logger = LoggerFactory.getLogger(HistorysController.class);
|
||||
|
||||
@Autowired
|
||||
HistoryLoginService historyLoginService;
|
||||
|
||||
@Autowired
|
||||
protected HistoryLoginAppsService historyLoginAppsService;
|
||||
|
||||
@Autowired
|
||||
HistoryLogsService historyLogsService;
|
||||
|
||||
@RequestMapping(value={"/logs"})
|
||||
public String List(){
|
||||
return "historys/logsList";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询操作日志
|
||||
* @param logs
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value={"/logs/grid"})
|
||||
@ResponseBody
|
||||
public JpaPageResults<HistoryLogs> logsDataGrid(@ModelAttribute("historyLogs") HistoryLogs historyLogs){
|
||||
_logger.debug("history/logs/grid/ logsGrid() "+historyLogs);
|
||||
return historyLogsService.queryPageResults(historyLogs);
|
||||
}
|
||||
static final Logger _logger = LoggerFactory.getLogger(HistorysController.class);
|
||||
|
||||
@RequestMapping(value={"/login"})
|
||||
public String authList(){
|
||||
return "historys/loginList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询登录日志
|
||||
* @param logsAuth
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value={"/login/grid"})
|
||||
@ResponseBody
|
||||
public JpaPageResults<HistoryLogin> logAuthsGrid(@ModelAttribute("historyLogin") HistoryLogin historyLogin){
|
||||
_logger.debug("history/login/grid/ logsGrid() "+historyLogin);
|
||||
historyLogin.setUid(WebContext.getUserInfo().getId());
|
||||
return historyLoginService.queryPageResults(historyLogin);
|
||||
}
|
||||
@Autowired
|
||||
HistoryLoginService historyLoginService;
|
||||
|
||||
@RequestMapping(value={"/loginApps"})
|
||||
public String loginAppHistoryList(){
|
||||
return "historys/loginAppsList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单点登录日志
|
||||
* @param logsSso
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value={"/loginApps/grid"})
|
||||
@ResponseBody
|
||||
public JpaPageResults<HistoryLoginApps> logsSsoGrid(@ModelAttribute("historyLoginApps") HistoryLoginApps historyLoginApps){
|
||||
_logger.debug("history/loginApps/grid/ logsGrid() "+historyLoginApps);
|
||||
historyLoginApps.setId(null);
|
||||
|
||||
return historyLoginAppsService.queryPageResults(historyLoginApps);
|
||||
@Autowired
|
||||
protected HistoryLoginAppsService historyLoginAppsService;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
HistoryLogsService historyLogsService;
|
||||
|
||||
@RequestMapping(value = { "/logs" })
|
||||
public String List() {
|
||||
return "historys/logsList";
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
/**
|
||||
* 查询操作日志.
|
||||
*
|
||||
* @param logs
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = { "/logs/grid" })
|
||||
@ResponseBody
|
||||
public JpaPageResults<HistoryLogs> logsDataGrid(@ModelAttribute("historyLogs") HistoryLogs historyLogs) {
|
||||
_logger.debug("history/logs/grid/ logsGrid() " + historyLogs);
|
||||
return historyLogsService.queryPageResults(historyLogs);
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/login" })
|
||||
public String authList() {
|
||||
return "historys/loginList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询登录日志.
|
||||
*
|
||||
* @param logsAuth
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = { "/login/grid" })
|
||||
@ResponseBody
|
||||
public JpaPageResults<HistoryLogin> logAuthsGrid(@ModelAttribute("historyLogin") HistoryLogin historyLogin) {
|
||||
_logger.debug("history/login/grid/ logsGrid() " + historyLogin);
|
||||
historyLogin.setUid(WebContext.getUserInfo().getId());
|
||||
return historyLoginService.queryPageResults(historyLogin);
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/loginApps" })
|
||||
public String loginAppHistoryList() {
|
||||
return "historys/loginAppsList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单点登录日志.
|
||||
*
|
||||
* @param logsSso
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = { "/loginApps/grid" })
|
||||
@ResponseBody
|
||||
public JpaPageResults<HistoryLoginApps> logsSsoGrid(
|
||||
@ModelAttribute("historyLoginApps") HistoryLoginApps historyLoginApps) {
|
||||
_logger.debug("history/loginApps/grid/ logsGrid() " + historyLoginApps);
|
||||
historyLoginApps.setId(null);
|
||||
|
||||
return historyLoginAppsService.queryPageResults(historyLoginApps);
|
||||
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void initBinder(WebDataBinder binder) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtils.FORMAT_DATE_HH_MM_SS);
|
||||
dateFormat.setLenient(false);
|
||||
dateFormat.setLenient(false);
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package org.maxkey.web.contorller;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.maxkey.crypto.Base32Utils;
|
||||
import org.maxkey.crypto.password.PasswordReciprocal;
|
||||
@ -11,8 +10,8 @@ import org.maxkey.crypto.password.opt.algorithm.OTPSecret;
|
||||
import org.maxkey.dao.service.UserInfoService;
|
||||
import org.maxkey.domain.UserInfo;
|
||||
import org.maxkey.util.RQCodeUtils;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.maxkey.web.ImageEndpoint;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -23,127 +22,128 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = { "/safe/otp" })
|
||||
@RequestMapping(value = { "/safe/otp" })
|
||||
public class OneTimePasswordController {
|
||||
final static Logger _logger = LoggerFactory.getLogger(OneTimePasswordController.class);
|
||||
static final Logger _logger = LoggerFactory.getLogger(OneTimePasswordController.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("userInfoService")
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("keyUriFormat")
|
||||
KeyUriFormat keyUriFormat;
|
||||
@Autowired
|
||||
@Qualifier("userInfoService")
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("passwordReciprocal")
|
||||
PasswordReciprocal passwordReciprocal;
|
||||
|
||||
@RequestMapping(value={"/timebased"})
|
||||
public ModelAndView timebased(){
|
||||
ModelAndView modelAndView=new ModelAndView("safe/timeBased");
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
String sharedSecret=passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||
keyUriFormat.setSecret(sharedSecret);
|
||||
String otpauth=keyUriFormat.format(userInfo.getUsername());
|
||||
byte[] byteSharedSecret=Base32Utils.decode(sharedSecret);
|
||||
String hexSharedSecret=Hex.encodeHexString(byteSharedSecret);
|
||||
modelAndView.addObject("id", genRQCode(otpauth));
|
||||
modelAndView.addObject("userInfo", userInfo);
|
||||
modelAndView.addObject("format", keyUriFormat);
|
||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
@RequestMapping(value={"gen/timebased"})
|
||||
public ModelAndView gentimebased(){
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
byte[] byteSharedSecret=OTPSecret.generate(keyUriFormat.getCrypto());
|
||||
String sharedSecret=Base32Utils.encode(byteSharedSecret);
|
||||
sharedSecret=passwordReciprocal.encode(sharedSecret);
|
||||
userInfo.setSharedSecret(sharedSecret);
|
||||
userInfoService.changeSharedSecret(userInfo);
|
||||
WebContext.setUserInfo(userInfo);
|
||||
return WebContext.redirect("/safe/otp/timebased");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Qualifier("keyUriFormat")
|
||||
KeyUriFormat keyUriFormat;
|
||||
|
||||
@RequestMapping(value={"/counterbased"})
|
||||
public ModelAndView counterbased(){
|
||||
ModelAndView modelAndView=new ModelAndView("safe/counterBased");
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
String sharedSecret=passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||
keyUriFormat.setSecret(sharedSecret);
|
||||
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
|
||||
String otpauth=keyUriFormat.format(userInfo.getUsername());
|
||||
|
||||
byte[] byteSharedSecret=Base32Utils.decode(sharedSecret);
|
||||
String hexSharedSecret=Hex.encodeHexString(byteSharedSecret);
|
||||
modelAndView.addObject("id", genRQCode(otpauth));
|
||||
modelAndView.addObject("userInfo", userInfo);
|
||||
modelAndView.addObject("format", keyUriFormat);
|
||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||
return modelAndView;
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value={"gen/counterbased"})
|
||||
public ModelAndView gencounterbased(){
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
byte[] byteSharedSecret=OTPSecret.generate(keyUriFormat.getCrypto());
|
||||
String sharedSecret=Base32Utils.encode(byteSharedSecret);
|
||||
sharedSecret=passwordReciprocal.encode(sharedSecret);
|
||||
userInfo.setSharedSecret(sharedSecret);
|
||||
userInfo.setSharedCounter("0");
|
||||
userInfoService.changeSharedSecret(userInfo);
|
||||
WebContext.setUserInfo(userInfo);
|
||||
return WebContext.redirect("/safe/otp/counterbased");
|
||||
}
|
||||
@Autowired
|
||||
@Qualifier("passwordReciprocal")
|
||||
PasswordReciprocal passwordReciprocal;
|
||||
|
||||
@RequestMapping(value={"/hotp"})
|
||||
public ModelAndView hotp(){
|
||||
ModelAndView modelAndView=new ModelAndView("safe/hotp");
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
String sharedSecret=passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||
keyUriFormat.setSecret(sharedSecret);
|
||||
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
|
||||
String otpauth=keyUriFormat.format(userInfo.getUsername());
|
||||
byte[] byteSharedSecret=Base32Utils.decode(sharedSecret);
|
||||
String hexSharedSecret=Hex.encodeHexString(byteSharedSecret);
|
||||
modelAndView.addObject("id", genRQCode(otpauth));
|
||||
modelAndView.addObject("userInfo", userInfo);
|
||||
modelAndView.addObject("format", keyUriFormat);
|
||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||
return modelAndView;
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value={"gen/hotp"})
|
||||
public ModelAndView genhotp(){
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
byte[] byteSharedSecret=OTPSecret.generate(keyUriFormat.getCrypto());
|
||||
String sharedSecret=Base32Utils.encode(byteSharedSecret);
|
||||
sharedSecret=passwordReciprocal.encode(sharedSecret);
|
||||
userInfo.setSharedSecret(sharedSecret);
|
||||
userInfo.setSharedCounter("0");
|
||||
userInfoService.changeSharedSecret(userInfo);
|
||||
WebContext.setUserInfo(userInfo);
|
||||
return WebContext.redirect("/safe/otp/hotp");
|
||||
}
|
||||
|
||||
|
||||
public String genRQCode(String otpauth){
|
||||
BufferedImage bufferedImage = RQCodeUtils.write2BufferedImage(otpauth, "gif", 300, 300);
|
||||
byte[] imageByte=ImageEndpoint.bufferedImage2Byte(bufferedImage);
|
||||
String uuid=UUID.randomUUID().toString().toLowerCase();
|
||||
WebContext.getSession().setAttribute(uuid, imageByte);
|
||||
return uuid;
|
||||
}
|
||||
@RequestMapping(value = {"/timebased"})
|
||||
public ModelAndView timebased() {
|
||||
ModelAndView modelAndView = new ModelAndView("safe/timeBased");
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||
keyUriFormat.setSecret(sharedSecret);
|
||||
String otpauth = keyUriFormat.format(userInfo.getUsername());
|
||||
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
||||
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
||||
modelAndView.addObject("id", genRqCode(otpauth));
|
||||
modelAndView.addObject("userInfo", userInfo);
|
||||
modelAndView.addObject("format", keyUriFormat);
|
||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"gen/timebased"})
|
||||
public ModelAndView gentimebased() {
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
byte[] byteSharedSecret = OTPSecret.generate(keyUriFormat.getCrypto());
|
||||
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
||||
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
||||
userInfo.setSharedSecret(sharedSecret);
|
||||
userInfoService.changeSharedSecret(userInfo);
|
||||
WebContext.setUserInfo(userInfo);
|
||||
return WebContext.redirect("/safe/otp/timebased");
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = {"/counterbased"})
|
||||
public ModelAndView counterbased() {
|
||||
ModelAndView modelAndView = new ModelAndView("safe/counterBased");
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||
keyUriFormat.setSecret(sharedSecret);
|
||||
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
|
||||
String otpauth = keyUriFormat.format(userInfo.getUsername());
|
||||
|
||||
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
||||
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
||||
modelAndView.addObject("id", genRqCode(otpauth));
|
||||
modelAndView.addObject("userInfo", userInfo);
|
||||
modelAndView.addObject("format", keyUriFormat);
|
||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||
return modelAndView;
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"gen/counterbased"})
|
||||
public ModelAndView gencounterbased() {
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
byte[] byteSharedSecret = OTPSecret.generate(keyUriFormat.getCrypto());
|
||||
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
||||
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
||||
userInfo.setSharedSecret(sharedSecret);
|
||||
userInfo.setSharedCounter("0");
|
||||
userInfoService.changeSharedSecret(userInfo);
|
||||
WebContext.setUserInfo(userInfo);
|
||||
return WebContext.redirect("/safe/otp/counterbased");
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"/hotp"})
|
||||
public ModelAndView hotp() {
|
||||
ModelAndView modelAndView = new ModelAndView("safe/hotp");
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||
keyUriFormat.setSecret(sharedSecret);
|
||||
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
|
||||
String otpauth = keyUriFormat.format(userInfo.getUsername());
|
||||
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
||||
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
||||
modelAndView.addObject("id", genRqCode(otpauth));
|
||||
modelAndView.addObject("userInfo", userInfo);
|
||||
modelAndView.addObject("format", keyUriFormat);
|
||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||
return modelAndView;
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"gen/hotp"})
|
||||
public ModelAndView genhotp() {
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
byte[] byteSharedSecret = OTPSecret.generate(keyUriFormat.getCrypto());
|
||||
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
||||
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
||||
userInfo.setSharedSecret(sharedSecret);
|
||||
userInfo.setSharedCounter("0");
|
||||
userInfoService.changeSharedSecret(userInfo);
|
||||
WebContext.setUserInfo(userInfo);
|
||||
return WebContext.redirect("/safe/otp/hotp");
|
||||
}
|
||||
|
||||
|
||||
public String genRqCode(String otpauth) {
|
||||
BufferedImage bufferedImage = RQCodeUtils.write2BufferedImage(otpauth, "gif", 300, 300);
|
||||
byte[] imageByte = ImageEndpoint.bufferedImage2Byte(bufferedImage);
|
||||
String uuid = UUID.randomUUID().toString().toLowerCase();
|
||||
WebContext.getSession().setAttribute(uuid, imageByte);
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package org.maxkey.web.contorller;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.maxkey.constants.OPERATEMESSAGE;
|
||||
import org.maxkey.dao.service.MyProfileService;
|
||||
import org.maxkey.dao.service.UserInfoService;
|
||||
@ -20,45 +19,45 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value={"/profile"})
|
||||
@RequestMapping(value = { "/profile" })
|
||||
public class ProfileController {
|
||||
final static Logger _logger = LoggerFactory.getLogger(ProfileController.class);
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
private MyProfileService myProfileService;
|
||||
|
||||
|
||||
@RequestMapping(value={"/myProfile"})
|
||||
public ModelAndView forwardBasic(){
|
||||
ModelAndView modelAndView=new ModelAndView("profile/myProfile");
|
||||
UserInfo userInfo=userInfoService.loadByUsername(WebContext.getUserInfo().getUsername());
|
||||
WebContext.getSession().setAttribute(userInfo.getId(), userInfo.getPicture());
|
||||
|
||||
// HashMap<String,Object>extraAttributeMap=new HashMap<String,Object>();
|
||||
// extraAttributeMap=(HashMap<String,Object>)JsonUtils.json2Object(userInfo.getExtraAttribute(),extraAttributeMap);
|
||||
// modelAndView.addObject("extraAttributeMap", extraAttributeMap);
|
||||
// _logger.info("extraAttributeMap : "+extraAttributeMap);
|
||||
|
||||
modelAndView.addObject("model", userInfo);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
* @param userInfo
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/update/myProfile")
|
||||
public ModelAndView updatebasic(@Valid @ModelAttribute("userInfo")UserInfo userInfo,BindingResult result) {
|
||||
_logger.debug(userInfo.toString());
|
||||
|
||||
static final Logger _logger = LoggerFactory.getLogger(ProfileController.class);
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
private MyProfileService myProfileService;
|
||||
|
||||
@RequestMapping(value = { "/myProfile" })
|
||||
public ModelAndView forwardBasic() {
|
||||
ModelAndView modelAndView = new ModelAndView("profile/myProfile");
|
||||
UserInfo userInfo = userInfoService.loadByUsername(WebContext.getUserInfo().getUsername());
|
||||
WebContext.getSession().setAttribute(userInfo.getId(), userInfo.getPicture());
|
||||
|
||||
// HashMap<String,Object>extraAttributeMap=new HashMap<String,Object>();
|
||||
// extraAttributeMap=(HashMap<String,Object>)JsonUtils.json2Object(userInfo.getExtraAttribute(),extraAttributeMap);
|
||||
// modelAndView.addObject("extraAttributeMap", extraAttributeMap);
|
||||
// _logger.info("extraAttributeMap : "+extraAttributeMap);
|
||||
//
|
||||
modelAndView.addObject("model", userInfo);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户.
|
||||
*
|
||||
* @param userInfo
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/update/myProfile")
|
||||
public ModelAndView updatebasic(
|
||||
@Valid @ModelAttribute("userInfo") UserInfo userInfo,
|
||||
BindingResult result) {
|
||||
_logger.debug(userInfo.toString());
|
||||
|
||||
// if(userInfo.getExtraAttributeValue()!=null){
|
||||
// String []extraAttributeLabel=userInfo.getExtraAttributeName().split(",");
|
||||
// String []extraAttributeValue=userInfo.getExtraAttributeValue().split(",");
|
||||
@ -69,16 +68,19 @@ public class ProfileController {
|
||||
// String extraAttribute=JsonUtils.object2Json(extraAttributeMap);
|
||||
// userInfo.setExtraAttribute(extraAttribute);
|
||||
// }
|
||||
|
||||
if(myProfileService.updateProfile(userInfo)>0) {
|
||||
new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS),userInfo,MessageType.success,OperateType.add,MessageScope.DB);
|
||||
|
||||
}else{
|
||||
new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_ERROR),MessageType.error);
|
||||
}
|
||||
|
||||
return WebContext.forward("forwardMyProfile");
|
||||
|
||||
}
|
||||
|
||||
if (myProfileService.updateProfile(userInfo) > 0) {
|
||||
new Message(
|
||||
WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS),
|
||||
userInfo, MessageType.success,
|
||||
OperateType.add, MessageScope.DB);
|
||||
|
||||
} else {
|
||||
new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_ERROR), MessageType.error);
|
||||
}
|
||||
|
||||
return WebContext.forward("forwardMyProfile");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package org.maxkey.web.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
@ -12,7 +11,6 @@ import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.maxkey.config.ApplicationConfig;
|
||||
import org.maxkey.domain.IpAddrFilter;
|
||||
import org.maxkey.web.WebContext;
|
||||
@ -24,58 +22,59 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
public class IpAddressFilter implements Filter {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(IpAddressFilter.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
private ApplicationConfig applicationConfig;
|
||||
|
||||
boolean whiteList=false;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
private static final Logger _logger = LoggerFactory.getLogger(IpAddressFilter.class);
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
if(applicationConfig==null){
|
||||
_logger.info("applicationConfig init .");
|
||||
applicationConfig=WebApplicationContextUtils.getWebApplicationContext(request.getServletContext()).getBean("applicationConfig", ApplicationConfig.class);
|
||||
}
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
String ipAddress=WebContext.getRequestIpAddress(httpServletRequest);
|
||||
_logger.trace("IpAddress "+ipAddress);
|
||||
//黑名单地址
|
||||
if(IpAddressCache.ipAddressBlackListMap.containsKey(ipAddress)){
|
||||
IpAddrFilter ipAddrFilter=IpAddressCache.ipAddressBlackListMap.get(ipAddress);
|
||||
|
||||
_logger.info("You IpAddress in Black List "+ipAddrFilter);
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
|
||||
dispatcher.forward(request, response);
|
||||
return ;
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
private ApplicationConfig applicationConfig;
|
||||
|
||||
}
|
||||
//白名单地址
|
||||
if(whiteList&&!IpAddressCache.ipAddressWhiteListMap.containsKey(ipAddress)){
|
||||
_logger.info("You IpAddress not in White List "+ipAddress);
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
|
||||
dispatcher.forward(request, response);
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
boolean whiteList = false;
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
if (applicationConfig == null) {
|
||||
_logger.info("applicationConfig init .");
|
||||
applicationConfig = WebApplicationContextUtils.getWebApplicationContext(
|
||||
request.getServletContext())
|
||||
.getBean("applicationConfig", ApplicationConfig.class);
|
||||
}
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
String ipAddress = WebContext.getRequestIpAddress(httpServletRequest);
|
||||
_logger.trace("IpAddress " + ipAddress);
|
||||
// 黑名单地址
|
||||
if (IpAddressCache.ipAddressBlackListMap.containsKey(ipAddress)) {
|
||||
IpAddrFilter ipAddrFilter = IpAddressCache.ipAddressBlackListMap.get(ipAddress);
|
||||
|
||||
_logger.info("You IpAddress in Black List " + ipAddrFilter);
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
|
||||
dispatcher.forward(request, response);
|
||||
return;
|
||||
|
||||
}
|
||||
// 白名单地址
|
||||
if (whiteList && !IpAddressCache.ipAddressWhiteListMap.containsKey(ipAddress)) {
|
||||
_logger.info("You IpAddress not in White List " + ipAddress);
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
|
||||
dispatcher.forward(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -10,40 +10,45 @@ import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.maxkey.util.StringUtils;
|
||||
import org.maxkey.web.WebConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* SingleSignOnFilter.
|
||||
* @author Crystal.Sea
|
||||
*/
|
||||
|
||||
public class SingleSignOnFilter implements Filter {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(SingleSignOnFilter.class);
|
||||
|
||||
public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(SingleSignOnFilter.class);
|
||||
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
//浠巗ession涓幏鍙栧瓨鏀剧殑appid
|
||||
String appId = (String) session.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
|
||||
//鑾峰彇鏈<EFBFBD>鍚庝竴涓<EFBFBD>"/"鐨勬暟鎹綔涓篴ppid锛屼繚瀛樺湪session涓<EFBFBD>
|
||||
if(StringUtils.isNullOrBlank(appId)) {
|
||||
String uir = httpServletRequest.getRequestURI();
|
||||
session.setAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID, uir.substring(uir.lastIndexOf("/")+1));
|
||||
session.setAttribute("protocol", "formbase");
|
||||
}
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
_logger.debug(" destroy.");
|
||||
}
|
||||
/**
|
||||
*doFilter.
|
||||
*/
|
||||
public void doFilter(ServletRequest request,
|
||||
ServletResponse response, FilterChain chain)throws IOException, ServletException {
|
||||
|
||||
public void init(FilterConfig config) throws ServletException {
|
||||
_logger.debug(" init.");
|
||||
}
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
// 浠巗ession涓幏鍙栧瓨鏀剧殑appid
|
||||
String appId = (String) session.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
|
||||
// 鑾峰彇鏈<EFBFBD>鍚庝竴涓<EFBFBD>"/"鐨勬暟鎹綔涓篴ppid锛屼繚瀛樺湪session涓<EFBFBD>
|
||||
if (StringUtils.isNullOrBlank(appId)) {
|
||||
String uir = httpServletRequest.getRequestURI();
|
||||
session.setAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID,
|
||||
uir.substring(uir.lastIndexOf("/") + 1));
|
||||
session.setAttribute("protocol", "formbase");
|
||||
}
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
_logger.debug(" destroy.");
|
||||
}
|
||||
|
||||
public void init(FilterConfig config) throws ServletException {
|
||||
_logger.debug(" init.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
package org.maxkey.web.interceptor;
|
||||
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
||||
import org.maxkey.dao.service.AppsService;
|
||||
import org.maxkey.dao.service.HistoryLoginAppsService;
|
||||
@ -20,42 +18,47 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
public class HistoryLoginAppAdapter extends HandlerInterceptorAdapter {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(HistoryLoginAppAdapter.class);
|
||||
private static final Logger _logger = LoggerFactory.getLogger(HistoryLoginAppAdapter.class);
|
||||
|
||||
@Autowired
|
||||
HistoryLoginAppsService historyLoginAppsService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("appsService")
|
||||
protected AppsService appsService;
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
|
||||
*/
|
||||
public void postHandle(HttpServletRequest request,HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {
|
||||
_logger.debug("postHandle");
|
||||
String appId=null;
|
||||
if(WebContext.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID)!=null){
|
||||
appId=WebContext.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID).toString();
|
||||
}
|
||||
if(appId==null){
|
||||
PreLoginAppAdapter.getAppIdFromRequestURI(request);
|
||||
}
|
||||
//Applications app=applicationsService.get(appId);
|
||||
Apps app=(Apps)WebContext.getAttribute(AuthorizeBaseEndpoint.class.getName());
|
||||
String sessionId=(String)WebContext.getAttribute(WebConstants.CURRENT_USER_SESSION_ID);
|
||||
UserInfo userInfo =WebContext.getUserInfo();
|
||||
_logger.debug("sessionId : "+sessionId+" ,appId : "+appId);
|
||||
HistoryLoginApps historyLoginApps=new HistoryLoginApps();
|
||||
historyLoginApps.setId(historyLoginApps.generateId());
|
||||
historyLoginApps.setAppId(appId);
|
||||
historyLoginApps.setSessionId(sessionId);
|
||||
historyLoginApps.setAppName(app.getName());
|
||||
historyLoginApps.setUid(userInfo.getId());
|
||||
historyLoginApps.setUsername(userInfo.getUsername());
|
||||
historyLoginApps.setDisplayName(userInfo.getDisplayName());
|
||||
historyLoginAppsService.insert(historyLoginApps);
|
||||
WebContext.removeAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
|
||||
WebContext.removeAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
|
||||
}
|
||||
@Autowired
|
||||
HistoryLoginAppsService historyLoginAppsService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("appsService")
|
||||
protected AppsService appsService;
|
||||
|
||||
/**
|
||||
* postHandle .
|
||||
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(
|
||||
* javax.servlet.http.HttpServletRequest,
|
||||
* javax.servlet.http.HttpServletResponse, java.lang.Object)
|
||||
*/
|
||||
public void postHandle(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
Object handler,ModelAndView modelAndView) throws Exception {
|
||||
_logger.debug("postHandle");
|
||||
String appId = null;
|
||||
if (WebContext.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID) != null) {
|
||||
appId = WebContext.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID).toString();
|
||||
}
|
||||
if (appId == null) {
|
||||
PreLoginAppAdapter.getAppIdFromRequestUrl(request);
|
||||
}
|
||||
//Applications app=applicationsService.get(appId);
|
||||
final Apps app = (Apps)WebContext.getAttribute(AuthorizeBaseEndpoint.class.getName());
|
||||
String sessionId = (String)WebContext.getAttribute(WebConstants.CURRENT_USER_SESSION_ID);
|
||||
final UserInfo userInfo = WebContext.getUserInfo();
|
||||
_logger.debug("sessionId : " + sessionId + " ,appId : " + appId);
|
||||
HistoryLoginApps historyLoginApps = new HistoryLoginApps();
|
||||
historyLoginApps.setId(historyLoginApps.generateId());
|
||||
historyLoginApps.setAppId(appId);
|
||||
historyLoginApps.setSessionId(sessionId);
|
||||
historyLoginApps.setAppName(app.getName());
|
||||
historyLoginApps.setUid(userInfo.getId());
|
||||
historyLoginApps.setUsername(userInfo.getUsername());
|
||||
historyLoginApps.setDisplayName(userInfo.getDisplayName());
|
||||
historyLoginAppsService.insert(historyLoginApps);
|
||||
WebContext.removeAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
|
||||
WebContext.removeAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package org.maxkey.web.interceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.maxkey.dao.service.HistoryLogsService;
|
||||
import org.maxkey.domain.HistoryLogs;
|
||||
import org.maxkey.domain.UserInfo;
|
||||
@ -19,47 +18,53 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
/**
|
||||
* Contorller调用完成后进行日志操作
|
||||
*
|
||||
* 日志处理需在parasec-servlet.xml中配置
|
||||
* mvc:interceptors log
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
public class HistoryLogsAdapter extends HandlerInterceptorAdapter {
|
||||
|
||||
private static final Logger _logger = LoggerFactory.getLogger(HistoryLogsAdapter.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("historyLogsService")
|
||||
private HistoryLogsService historyLogsService;
|
||||
|
||||
// after the handler is executed
|
||||
public void postHandle(HttpServletRequest request,HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {
|
||||
_logger.debug("postHandle");
|
||||
Message message = WebContext.getMessage();//读取session中message
|
||||
|
||||
if(message != null){
|
||||
if(message.getMessageScope() == MessageScope.DB || message.getMessageScope() == MessageScope.DB_CLIENT) {//判断message类型
|
||||
UserInfo userInfo =WebContext.getUserInfo();//取得当前用户信息
|
||||
|
||||
//创建日志记录
|
||||
HistoryLogs historyLogs = new HistoryLogs(
|
||||
message.getServiceName(),
|
||||
message.getCode(),
|
||||
message.getMessage(),
|
||||
JsonUtils.object2Json(message.getMessageObject()),
|
||||
message.getMessageType().toString(),
|
||||
message.getOperateType().toString(),
|
||||
userInfo==null?null:userInfo.getId(),
|
||||
userInfo==null?null:userInfo.getUsername(),
|
||||
""
|
||||
);
|
||||
_logger.debug("insert db historyLogs content : "+historyLogs);
|
||||
historyLogsService.insert(historyLogs);//日志插入数据库
|
||||
if(message.getMessageScope() == MessageScope.DB) {//message类型仅插入数据库
|
||||
WebContext.clearMessage();//清除message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger _logger = LoggerFactory.getLogger(HistoryLogsAdapter.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("historyLogsService")
|
||||
private HistoryLogsService historyLogsService;
|
||||
|
||||
/**
|
||||
* after the handler is executed.
|
||||
*/
|
||||
public void postHandle(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
Object handler,ModelAndView modelAndView) throws Exception {
|
||||
_logger.debug("postHandle");
|
||||
Message message = WebContext.getMessage();//读取session中message
|
||||
|
||||
if (message != null) {
|
||||
//判断message类型
|
||||
if (message.getMessageScope() == MessageScope.DB
|
||||
|| message.getMessageScope() == MessageScope.DB_CLIENT) {
|
||||
UserInfo userInfo = WebContext.getUserInfo();//取得当前用户信息
|
||||
|
||||
//创建日志记录
|
||||
HistoryLogs historyLogs = new HistoryLogs(
|
||||
message.getServiceName(),
|
||||
message.getCode(),
|
||||
message.getMessage(),
|
||||
JsonUtils.object2Json(message.getMessageObject()),
|
||||
message.getMessageType().toString(),
|
||||
message.getOperateType().toString(),
|
||||
userInfo == null ? null : userInfo.getId(),
|
||||
userInfo == null ? null : userInfo.getUsername(),
|
||||
""
|
||||
);
|
||||
_logger.debug("insert db historyLogs content : " + historyLogs);
|
||||
historyLogsService.insert(historyLogs);//日志插入数据库
|
||||
//message类型仅插入数据库
|
||||
if (message.getMessageScope() == MessageScope.DB) {
|
||||
WebContext.clearMessage();//清除message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
package org.maxkey.web.interceptor;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.maxkey.config.ApplicationConfig;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
@ -13,56 +11,58 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
/**
|
||||
* 权限Interceptor处理
|
||||
* 权限处理需在servlet.xml中配置
|
||||
* mvc:interceptors permission
|
||||
* 权限Interceptor处理 权限处理需在servlet.xml中配置 mvc:interceptors permission
|
||||
*
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
|
||||
public class PermissionAdapter extends HandlerInterceptorAdapter {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(PermissionAdapter.class);
|
||||
//无需Interceptor url
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
private ApplicationConfig applicationConfig;
|
||||
|
||||
static ConcurrentHashMap<String ,String >navigationsMap=null;
|
||||
/*
|
||||
* 请求前处理
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
|
||||
_logger.trace("PermissionAdapter preHandle");
|
||||
//判断用户是否登录
|
||||
if(WebContext.getAuthentication()==null||WebContext.getAuthentication().getAuthorities()==null){//判断用户和角色,判断用户是否登录用户
|
||||
_logger.trace("No Authentication ... forward to /login");
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
|
||||
dispatcher.forward(request, response);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean hasAccess=true;
|
||||
|
||||
|
||||
/*
|
||||
boolean preHandler = super.preHandle(request, response, handler);
|
||||
|
||||
if(preHandler) {
|
||||
preHandler = false;
|
||||
|
||||
|
||||
if(!preHandler){//无权限转向
|
||||
log.debug("You do not have permission to access "+accessUrl);
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
|
||||
dispatcher.forward(request, response);
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
return hasAccess;
|
||||
}
|
||||
private static final Logger _logger = LoggerFactory.getLogger(PermissionAdapter.class);
|
||||
// 无需Interceptor url
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
private ApplicationConfig applicationConfig;
|
||||
|
||||
static ConcurrentHashMap<String, String> navigationsMap = null;
|
||||
|
||||
/*
|
||||
* 请求前处理 (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(
|
||||
* javax.servlet.http.HttpServletRequest,
|
||||
* javax.servlet.http.HttpServletResponse, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request,
|
||||
HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
_logger.trace("PermissionAdapter preHandle");
|
||||
// 判断用户是否登录, 判断用户和角色,判断用户是否登录用户
|
||||
if (WebContext.getAuthentication() == null
|
||||
|| WebContext.getAuthentication().getAuthorities() == null) {
|
||||
_logger.trace("No Authentication ... forward to /login");
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
|
||||
dispatcher.forward(request, response);
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean hasAccess = true;
|
||||
|
||||
/*
|
||||
* boolean preHandler = super.preHandle(request, response, handler);
|
||||
*
|
||||
* if(preHandler) { preHandler = false;
|
||||
*
|
||||
*
|
||||
* if(!preHandler){//无权限转向
|
||||
* log.debug("You do not have permission to access "+accessUrl);
|
||||
* RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
|
||||
* dispatcher.forward(request, response); return false; } }
|
||||
*/
|
||||
return hasAccess;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
package org.maxkey.web.interceptor;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.maxkey.domain.UserInfo;
|
||||
import org.maxkey.web.WebConstants;
|
||||
import org.maxkey.web.WebContext;
|
||||
@ -11,38 +9,43 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
|
||||
public class PreLoginAppAdapter extends HandlerInterceptorAdapter {
|
||||
|
||||
|
||||
private static final Logger _logger = LoggerFactory.getLogger(PreLoginAppAdapter.class);
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
|
||||
_logger.debug("preHandle");
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
String redirect_uri=request.getRequestURL().toString();
|
||||
String appId=getAppIdFromRequestURI(request);
|
||||
_logger.debug("preHandle app Id "+appId);
|
||||
Object singlesignon_uri=WebContext.getAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
|
||||
if(singlesignon_uri!=null&&singlesignon_uri.equals(redirect_uri)){
|
||||
return true;
|
||||
}
|
||||
/*if(userInfo.getProtectedAppsMap().get(appId)!=null){
|
||||
|
||||
request.setAttribute("redirect_uri",redirect_uri);
|
||||
_logger.debug(""+redirect_uri);
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/authorize/protected/forward");
|
||||
dispatcher.forward(request, response);
|
||||
return false;
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getAppIdFromRequestURI(HttpServletRequest request){
|
||||
String[] uri=request.getRequestURI().split("/");
|
||||
String appId=uri[uri.length-1];
|
||||
return appId;
|
||||
}
|
||||
|
||||
private static final Logger _logger = LoggerFactory.getLogger(PreLoginAppAdapter.class);
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request,
|
||||
HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
_logger.debug("preHandle");
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
String redirect_uri = request.getRequestURL().toString();
|
||||
String appId = getAppIdFromRequestUrl(request);
|
||||
_logger.debug("preHandle app Id " + appId);
|
||||
Object singlesignon_uri = WebContext.getAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
|
||||
if (singlesignon_uri != null && singlesignon_uri.equals(redirect_uri)) {
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* if(userInfo.getProtectedAppsMap().get(appId)!=null){
|
||||
*
|
||||
* request.setAttribute("redirect_uri",redirect_uri);
|
||||
* _logger.debug(""+redirect_uri); RequestDispatcher dispatcher =
|
||||
* request.getRequestDispatcher("/authorize/protected/forward");
|
||||
* dispatcher.forward(request, response); return false; }
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request URL .
|
||||
* @param request http
|
||||
* @return .
|
||||
*/
|
||||
public static String getAppIdFromRequestUrl(HttpServletRequest request) {
|
||||
String[] uri = request.getRequestURI().split("/");
|
||||
String appId = uri[uri.length - 1];
|
||||
return appId;
|
||||
}
|
||||
}
|
||||
|
||||
324
style/checkstyle-rules.xml
Normal file
324
style/checkstyle-rules.xml
Normal file
@ -0,0 +1,324 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||
|
||||
<!--
|
||||
Checkstyle configuration that checks the Google coding conventions from Google Java Style
|
||||
that can be found at https://google.github.io/styleguide/javaguide.html
|
||||
Checkstyle is very configurable. Be sure to read the documentation at
|
||||
http://checkstyle.org (or in your downloaded distribution).
|
||||
To completely disable a check, just comment it out or delete it from the file.
|
||||
To suppress certain violations please review suppression filters.
|
||||
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
|
||||
-->
|
||||
|
||||
<module name = "Checker">
|
||||
<property name="charset" value="UTF-8"/>
|
||||
|
||||
<property name="severity" value="warning"/>
|
||||
|
||||
<property name="fileExtensions" value="java, properties, xml"/>
|
||||
<!-- Excludes all 'module-info.java' files -->
|
||||
<!-- See https://checkstyle.org/config_filefilters.html -->
|
||||
<module name="BeforeExecutionExclusionFileFilter">
|
||||
<property name="fileNamePattern" value="module\-info\.java$"/>
|
||||
</module>
|
||||
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
|
||||
<module name="SuppressionFilter">
|
||||
<property name="file" value="${org.checkstyle.google.suppressionfilter.config}"
|
||||
default="checkstyle-suppressions.xml" />
|
||||
<property name="optional" value="true"/>
|
||||
</module>
|
||||
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See http://checkstyle.org/config_whitespace.html -->
|
||||
<module name="FileTabCharacter">
|
||||
<property name="eachLine" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="LineLength">
|
||||
<property name="fileExtensions" value="java"/>
|
||||
<property name="max" value="100"/>
|
||||
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
<module name="OuterTypeFilename"/>
|
||||
<module name="IllegalTokenText">
|
||||
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
|
||||
<property name="format"
|
||||
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
|
||||
<property name="message"
|
||||
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
|
||||
</module>
|
||||
<module name="AvoidEscapedUnicodeCharacters">
|
||||
<property name="allowEscapesForControlCharacters" value="true"/>
|
||||
<property name="allowByTailComment" value="true"/>
|
||||
<property name="allowNonPrintableEscapes" value="true"/>
|
||||
</module>
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="OneTopLevelClass"/>
|
||||
<module name="NoLineWrap">
|
||||
<property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/>
|
||||
</module>
|
||||
<module name="EmptyBlock">
|
||||
<property name="option" value="TEXT"/>
|
||||
<property name="tokens"
|
||||
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
|
||||
</module>
|
||||
<module name="NeedBraces">
|
||||
<property name="tokens"
|
||||
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
|
||||
</module>
|
||||
<module name="LeftCurly">
|
||||
<property name="tokens"
|
||||
value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF,
|
||||
INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, LITERAL_DEFAULT,
|
||||
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF,
|
||||
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF,
|
||||
OBJBLOCK, STATIC_INIT"/>
|
||||
</module>
|
||||
<module name="RightCurly">
|
||||
<property name="id" value="RightCurlySame"/>
|
||||
<property name="tokens"
|
||||
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
|
||||
LITERAL_DO"/>
|
||||
</module>
|
||||
<module name="RightCurly">
|
||||
<property name="id" value="RightCurlyAlone"/>
|
||||
<property name="option" value="alone"/>
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
|
||||
INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF"/>
|
||||
</module>
|
||||
<module name="SuppressionXpathSingleFilter">
|
||||
<!-- suppresion is required till https://github.com/checkstyle/checkstyle/issues/7541 -->
|
||||
<property name="id" value="RightCurlyAlone"/>
|
||||
<property name="query" value="//RCURLY[parent::SLIST[count(./*)=1]
|
||||
or preceding-sibling::*[last()][self::LCURLY]]"/>
|
||||
</module>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="allowEmptyConstructors" value="true"/>
|
||||
<property name="allowEmptyLambdas" value="true"/>
|
||||
<property name="allowEmptyMethods" value="true"/>
|
||||
<property name="allowEmptyTypes" value="true"/>
|
||||
<property name="allowEmptyLoops" value="true"/>
|
||||
<property name="tokens"
|
||||
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
|
||||
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
|
||||
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
|
||||
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
|
||||
LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
|
||||
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
|
||||
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
|
||||
<message key="ws.notFollowed"
|
||||
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
|
||||
<message key="ws.notPreceded"
|
||||
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
|
||||
</module>
|
||||
<module name="OneStatementPerLine"/>
|
||||
<module name="MultipleVariableDeclarations"/>
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="FallThrough"/>
|
||||
<module name="UpperEll"/>
|
||||
<module name="ModifierOrder"/>
|
||||
<module name="EmptyLineSeparator">
|
||||
<property name="tokens"
|
||||
value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
|
||||
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
|
||||
<property name="allowNoEmptyLineBetweenFields" value="true"/>
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<property name="id" value="SeparatorWrapDot"/>
|
||||
<property name="tokens" value="DOT"/>
|
||||
<property name="option" value="nl"/>
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<property name="id" value="SeparatorWrapComma"/>
|
||||
<property name="tokens" value="COMMA"/>
|
||||
<property name="option" value="EOL"/>
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/258 -->
|
||||
<property name="id" value="SeparatorWrapEllipsis"/>
|
||||
<property name="tokens" value="ELLIPSIS"/>
|
||||
<property name="option" value="EOL"/>
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/259 -->
|
||||
<property name="id" value="SeparatorWrapArrayDeclarator"/>
|
||||
<property name="tokens" value="ARRAY_DECLARATOR"/>
|
||||
<property name="option" value="EOL"/>
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<property name="id" value="SeparatorWrapMethodRef"/>
|
||||
<property name="tokens" value="METHOD_REF"/>
|
||||
<property name="option" value="nl"/>
|
||||
</module>
|
||||
<module name="PackageName">
|
||||
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Package name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="TypeName">
|
||||
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="MemberName">
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Member name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="ParameterName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="LambdaParameterName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="CatchParameterName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="LocalVariableName">
|
||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="ClassTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Class type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="MethodTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Method type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="InterfaceTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="NoFinalizer"/>
|
||||
<module name="GenericWhitespace">
|
||||
<message key="ws.followed"
|
||||
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
|
||||
<message key="ws.preceded"
|
||||
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
|
||||
<message key="ws.illegalFollow"
|
||||
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
|
||||
<message key="ws.notPreceded"
|
||||
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
|
||||
</module>
|
||||
<module name="Indentation">
|
||||
<property name="basicOffset" value="4"/>
|
||||
<property name="braceAdjustment" value="0"/>
|
||||
<property name="caseIndent" value="4"/>
|
||||
<property name="throwsIndent" value="8"/>
|
||||
<property name="lineWrappingIndentation" value="8"/>
|
||||
<property name="arrayInitIndent" value="4"/>
|
||||
</module>
|
||||
<module name="AbbreviationAsWordInName">
|
||||
<property name="ignoreFinal" value="false"/>
|
||||
<property name="allowedAbbreviationLength" value="1"/>
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
|
||||
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF"/>
|
||||
</module>
|
||||
<module name="OverloadMethodsDeclarationOrder"/>
|
||||
<module name="VariableDeclarationUsageDistance"/>
|
||||
<module name="CustomImportOrder">
|
||||
<property name="sortImportsInGroupAlphabetically" value="true"/>
|
||||
<property name="separateLineBetweenGroups" value="true"/>
|
||||
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
|
||||
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>
|
||||
</module>
|
||||
<module name="MethodParamPad">
|
||||
<property name="tokens"
|
||||
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
|
||||
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
|
||||
</module>
|
||||
<module name="NoWhitespaceBefore">
|
||||
<property name="tokens"
|
||||
value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, METHOD_REF"/>
|
||||
<property name="allowLineBreaks" value="true"/>
|
||||
</module>
|
||||
<module name="ParenPad">
|
||||
<property name="tokens"
|
||||
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF,
|
||||
EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
|
||||
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL,
|
||||
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA"/>
|
||||
</module>
|
||||
<module name="OperatorWrap">
|
||||
<property name="option" value="NL"/>
|
||||
<property name="tokens"
|
||||
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
|
||||
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
|
||||
</module>
|
||||
<module name="AnnotationLocation">
|
||||
<property name="id" value="AnnotationLocationMostCases"/>
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="AnnotationLocation">
|
||||
<property name="id" value="AnnotationLocationVariables"/>
|
||||
<property name="tokens" value="VARIABLE_DEF"/>
|
||||
<property name="allowSamelineMultipleAnnotations" value="true"/>
|
||||
</module>
|
||||
<module name="NonEmptyAtclauseDescription"/>
|
||||
<module name="InvalidJavadocPosition"/>
|
||||
<module name="JavadocTagContinuationIndentation"/>
|
||||
<module name="SummaryJavadoc">
|
||||
<property name="forbiddenSummaryFragments"
|
||||
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
|
||||
</module>
|
||||
<module name="JavadocParagraph"/>
|
||||
<module name="AtclauseOrder">
|
||||
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
|
||||
<property name="target"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
|
||||
</module>
|
||||
<module name="JavadocMethod">
|
||||
<property name="scope" value="public"/>
|
||||
<property name="allowMissingParamTags" value="true"/>
|
||||
<property name="allowMissingReturnTag" value="true"/>
|
||||
<property name="allowedAnnotations" value="Override, Test"/>
|
||||
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
|
||||
</module>
|
||||
<module name="MissingJavadocMethod">
|
||||
<property name="scope" value="public"/>
|
||||
<property name="minLineCount" value="2"/>
|
||||
<property name="allowedAnnotations" value="Override, Test"/>
|
||||
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
|
||||
</module>
|
||||
<module name="MethodName">
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Method name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="SingleLineJavadoc">
|
||||
<property name="ignoreInlineTags" value="false"/>
|
||||
</module>
|
||||
<module name="EmptyCatchBlock">
|
||||
<property name="exceptionVariableName" value="expected"/>
|
||||
</module>
|
||||
<module name="CommentsIndentation">
|
||||
<property name="tokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/>
|
||||
</module>
|
||||
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
|
||||
<module name="SuppressionXpathFilter">
|
||||
<property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}"
|
||||
default="checkstyle-xpath-suppressions.xml" />
|
||||
<property name="optional" value="true"/>
|
||||
</module>
|
||||
</module>
|
||||
</module>
|
||||
Loading…
x
Reference in New Issue
Block a user