logs 优化

This commit is contained in:
Crystal.Sea
2021-10-06 10:37:12 +08:00
parent aed80b59fd
commit fe8c89a459
16 changed files with 255 additions and 133 deletions

View File

@@ -48,9 +48,9 @@ public class SocialSignOnEndpoint extends AbstractSocialSignOnEndpoint{
final static Logger _logger = LoggerFactory.getLogger(SocialSignOnEndpoint.class);
public ModelAndView socialSignOnAuthorize(HttpServletRequest request,String provider){
_logger.trace("SocialSignOn provider : "+provider);
_logger.trace("SocialSignOn provider : " + provider);
String authorizationUrl=buildAuthRequest(provider).authorize(request.getSession().getId());
_logger.trace("authorize SocialSignOn : "+authorizationUrl);
_logger.trace("authorize SocialSignOn : " + authorizationUrl);
return WebContext.redirect(authorizationUrl);
}
@@ -77,12 +77,16 @@ public class SocialSignOnEndpoint extends AbstractSocialSignOnEndpoint{
socialSignOnUser.setProvider(provider);
socialSignOnUser.setUserId(WebContext.getUserInfo().getId());
socialSignOnUser.setUsername(WebContext.getUserInfo().getUsername());
_logger.debug("Social Sign On unbind "+provider+" from user "+WebContext.getUserInfo().getUsername());
_logger.debug("Social Sign On unbind {} from user {}",
provider,
WebContext.getUserInfo().getUsername()
);
socialsAssociateService.delete(socialSignOnUser);
if(WebContext.getAttribute(SOCIALSIGNON_SESSION_REDIRECT_URI)!=null){
return WebContext.redirect(WebContext.getAttribute(SOCIALSIGNON_SESSION_REDIRECT_URI).toString());
Object redirect_uri = WebContext.getAttribute(SOCIALSIGNON_SESSION_REDIRECT_URI);
if(redirect_uri != null){
return WebContext.redirect(redirect_uri.toString());
}else{
return WebContext.forward("/socialsignon/list");
}
@@ -105,7 +109,8 @@ public class SocialSignOnEndpoint extends AbstractSocialSignOnEndpoint{
socialSignOnAuthorize(request,provider);
SocialSignOnProvider socialSignOnProvider = socialSignOnProviderService.get(provider);
socialSignOnProvider.setState(request.getSession().getId());
socialSignOnProvider.setRedirectUri(applicationConfig.getServerPrefix()+ "/logon/oauth20/callback/"+provider);
socialSignOnProvider.setRedirectUri(applicationConfig.getServerPrefix()+
"/logon/oauth20/callback/"+provider);
return socialSignOnProvider;
}
@@ -123,20 +128,21 @@ public class SocialSignOnEndpoint extends AbstractSocialSignOnEndpoint{
socialsAssociate.setSocialUserId(this.accountId);
//for login
String socialSignOnType= "";
if(WebContext.getAttribute(SOCIALSIGNON_TYPE_SESSION)!=null){
socialSignOnType=WebContext.getAttribute(SOCIALSIGNON_TYPE_SESSION).toString();
}
String socialSignOnType=
(WebContext.getAttribute(SOCIALSIGNON_TYPE_SESSION)!=null) ?
(WebContext.getAttribute(SOCIALSIGNON_TYPE_SESSION).toString()) : "";
if(socialSignOnType.equals(SOCIALSIGNON_TYPE.SOCIALSIGNON_TYPE_LOGON)||socialSignOnType.equals("")){
if(socialSignOnType.equals(SOCIALSIGNON_TYPE.SOCIALSIGNON_TYPE_LOGON)
||socialSignOnType.equals("")){
socialSignOn(socialsAssociate);
return WebContext.redirect("/index");
}else{
socialBind(socialsAssociate);
}
if(WebContext.getAttribute(SOCIALSIGNON_SESSION_REDIRECT_URI)!=null){
return WebContext.redirect(WebContext.getAttribute(SOCIALSIGNON_SESSION_REDIRECT_URI).toString());
Object redirect_uri = WebContext.getAttribute(SOCIALSIGNON_SESSION_REDIRECT_URI);
if(redirect_uri != null){
return WebContext.redirect(redirect_uri.toString());
}else{
return WebContext.forward("/socialsignon/list");
}
@@ -171,11 +177,15 @@ public class SocialSignOnEndpoint extends AbstractSocialSignOnEndpoint{
_logger.debug("Loaded SocialSignOn Socials Associate : "+socialsAssociate);
if(null == socialsAssociate) {
WebContext.getRequest().getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, new BadCredentialsException(WebContext.getI18nValue("login.error.social")));
WebContext.getRequest().getSession().setAttribute(
WebAttributes.AUTHENTICATION_EXCEPTION,
new BadCredentialsException(WebContext.getI18nValue("login.error.social"))
);
return false;
}
_logger.debug("Social Sign On from "+socialsAssociate.getProvider()+" mapping to user "+socialsAssociate.getUsername());
_logger.debug("Social Sign On from {} mapping to user {}",
socialsAssociate.getProvider(),socialsAssociate.getUsername());
LoginCredential loginCredential =new LoginCredential(
socialsAssociate.getUsername(),"",ConstantsLoginType.SOCIALSIGNON);

View File

@@ -23,6 +23,7 @@ import java.sql.Types;
import java.util.Date;
import java.util.List;
import org.maxkey.constants.ConstantsDatabase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -45,22 +46,16 @@ public class JdbcSocialsAssociateService implements SocialsAssociateService{
private final JdbcTemplate jdbcTemplate;
private String jdbcType;
public JdbcSocialsAssociateService(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate=jdbcTemplate;
try {
jdbcType = jdbcTemplate.getDataSource().getConnection().getMetaData().getDatabaseProductName();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean insert(SocialsAssociate socialsAssociate) {
socialsAssociate.setId(socialsAssociate.generateId());
jdbcTemplate.update("Oracle".equals(jdbcType)?DEFAULT_DEFAULT_INSERT_STATEMENT_ORACLE:DEFAULT_DEFAULT_INSERT_STATEMENT,
jdbcTemplate.update(
ConstantsDatabase.compare(ConstantsDatabase.ORACLE)?
DEFAULT_DEFAULT_INSERT_STATEMENT_ORACLE:DEFAULT_DEFAULT_INSERT_STATEMENT,
new Object[] {
socialsAssociate.getId(),
socialsAssociate.getUserId(),
@@ -70,7 +65,10 @@ public class JdbcSocialsAssociateService implements SocialsAssociateService{
socialsAssociate.getAccessToken(),
socialsAssociate.getSocialUserInfo(),
socialsAssociate.getExAttribute()},
new int[] {Types.VARCHAR, Types.VARCHAR,Types.VARCHAR,Types.VARCHAR, Types.VARCHAR,Types.VARCHAR, Types.VARCHAR,Types.VARCHAR });
new int[] {
Types.VARCHAR, Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
Types.VARCHAR,Types.VARCHAR, Types.VARCHAR,Types.VARCHAR
});
return true;
}
@@ -111,7 +109,13 @@ public class JdbcSocialsAssociateService implements SocialsAssociateService{
@Override
public boolean update(SocialsAssociate socialsAssociate) {
jdbcTemplate.update(DEFAULT_DEFAULT_UPDATE_STATEMENT,
new Object[] {socialsAssociate.getAccessToken(),socialsAssociate.getSocialUserInfo(),socialsAssociate.getExAttribute(),new Date(),socialsAssociate.getId()},
new Object[] {
socialsAssociate.getAccessToken(),
socialsAssociate.getSocialUserInfo(),
socialsAssociate.getExAttribute(),
new Date(),
socialsAssociate.getId()
},
new int[] {Types.VARCHAR, Types.VARCHAR,Types.VARCHAR, Types.TIMESTAMP,Types.VARCHAR });
return false;
}

View File

@@ -146,7 +146,7 @@ public class SocialSignOnProviderService{
}
}
_logger.debug(""+this.socialSignOnProviders);
_logger.debug("social SignOn Providers {}" , this.socialSignOnProviders);
}
}