diff --git a/.gitignore b/.gitignore index 0ee7db0c..8f5b91a2 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,7 @@ build/* *.log.* */logs/* */jdk/* -jdk/* \ No newline at end of file +jdk/* + +*/org/apache/mybatis/jpa/* +org/apache/mybatis/jpa/* \ No newline at end of file diff --git a/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/OAuthClient.java b/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/OAuthClient.java index d22ef3c3..4850344c 100644 --- a/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/OAuthClient.java +++ b/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/OAuthClient.java @@ -17,12 +17,13 @@ import org.maxkey.client.utils.Preconditions; public class OAuthClient { private static Log log = LogFactory.getLog(OAuthClient. class ); + private static final String DEFAULT_WEB_URL = "http://sso.maxkey.org/maxkey"; - public static String OAUTH_V20_USERINFO_URI="http://login.connsec.com/maxkey/api/oauth/v20/me"; + public static String OAUTH_V20_USERINFO_URI=DEFAULT_WEB_URL+"/api/oauth/v20/me"; - public static String OAUTH_V10A_USERINFO_URI="http://login.connsec.com/maxkey/api/oauth/v10a/me"; + public static String OAUTH_V10A_USERINFO_URI=DEFAULT_WEB_URL+"/api/oauth/v10a/me"; - public static String OPENID_CONNECT_V10A_USERINFO_URI="http://login.connsec.com/maxkey/api/connect/v10/userinfo"; + public static String OPENID_CONNECT_V10A_USERINFO_URI=DEFAULT_WEB_URL+"/api/connect/v10/userinfo"; //action method private HttpVerb method = HttpVerb.GET; diff --git a/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/builder/api/ConnsecApi10a.java b/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/builder/api/ConnsecApi10a.java index 2750426d..f5eedf26 100644 --- a/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/builder/api/ConnsecApi10a.java +++ b/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/builder/api/ConnsecApi10a.java @@ -4,7 +4,8 @@ import org.maxkey.client.oauth.model.Token; public class ConnsecApi10a extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "http://login.connsec.com/maxkey/oauth/v10a/authz?oauth_token=%s"; + private static final String DEFAULT_WEB_URL = "http://sso.maxkey.org/maxkey"; + private static final String AUTHORIZATION_URL = DEFAULT_WEB_URL+"/oauth/v10a/authz?oauth_token=%s"; public ConnsecApi10a() { @@ -13,13 +14,13 @@ public class ConnsecApi10a extends DefaultApi10a @Override public String getAccessTokenEndpoint() { - return "http://login.connsec.com/maxkey/oauth/v10a/access_token"; + return DEFAULT_WEB_URL+"/oauth/v10a/access_token"; } @Override public String getRequestTokenEndpoint() { - return "http://login.connsec.com/maxkey/oauth/v10a/request_token"; + return DEFAULT_WEB_URL+"/oauth/v10a/request_token"; } @Override diff --git a/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/builder/api/ConnsecApi20.java b/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/builder/api/ConnsecApi20.java index b9607964..0cbe6d31 100644 --- a/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/builder/api/ConnsecApi20.java +++ b/maxkey-client-sdk/src/main/java/org/maxkey/client/oauth/builder/api/ConnsecApi20.java @@ -9,7 +9,7 @@ import org.maxkey.client.utils.Preconditions; public class ConnsecApi20 extends DefaultApi20 { //approval_prompt:force or auto - private static final String DEFAULT_WEB_URL = "http://login.connsec.com/maxkey"; + private static final String DEFAULT_WEB_URL = "http://sso.maxkey.org/maxkey"; private static final String AUTHORIZATION_URL = "%s/oauth/v20/authorize?client_id=%s&response_type=code&redirect_uri=%s&approval_prompt=auto"; diff --git a/maxkey-core/src/main/java/org/maxkey/authn/AbstractAuthenticationProvider.java b/maxkey-core/src/main/java/org/maxkey/authn/AbstractAuthenticationProvider.java index d0c9be2e..c39ace8e 100644 --- a/maxkey-core/src/main/java/org/maxkey/authn/AbstractAuthenticationProvider.java +++ b/maxkey-core/src/main/java/org/maxkey/authn/AbstractAuthenticationProvider.java @@ -80,12 +80,23 @@ public abstract class AbstractAuthenticationProvider{ } // user authenticated - _logger.debug("'{0}' authenticated successfully by {}.", authentication.getPrincipal(), getProviderName()); + _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 + _logger.debug("Login Session {}.", WebContext.getSession().getId()); + 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); + // create new authentication response containing the user and it's authorities UsernamePasswordAuthenticationToken simpleUserAuthentication = new UsernamePasswordAuthenticationToken(userInfo.getUsername(), authentication.getCredentials(), authentication.getAuthorities()); return simpleUserAuthentication; diff --git a/maxkey-core/src/main/java/org/maxkey/authn/BasicAuthentication.java b/maxkey-core/src/main/java/org/maxkey/authn/BasicAuthentication.java index 1994d03a..9b200429 100644 --- a/maxkey-core/src/main/java/org/maxkey/authn/BasicAuthentication.java +++ b/maxkey-core/src/main/java/org/maxkey/authn/BasicAuthentication.java @@ -1,8 +1,10 @@ package org.maxkey.authn; +import java.util.ArrayList; import java.util.Collection; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; public class BasicAuthentication implements Authentication{ /** @@ -17,10 +19,13 @@ public class BasicAuthentication implements Authentication{ String j_remeberme; String j_auth_type; String j_jwt_token; - + ArrayList grantedAuthority; boolean authenticated; public BasicAuthentication() { + grantedAuthority = new ArrayList(); + grantedAuthority.add(new SimpleGrantedAuthority("ROLE_USER")); + grantedAuthority.add(new SimpleGrantedAuthority("ORDINARY_USER")); } @Override @@ -30,7 +35,7 @@ public class BasicAuthentication implements Authentication{ @Override public Collection getAuthorities() { - return null; + return grantedAuthority; } @Override @@ -122,6 +127,14 @@ public class BasicAuthentication implements Authentication{ public void setJ_jwt_token(String j_jwt_token) { this.j_jwt_token = j_jwt_token; } + + public ArrayList getGrantedAuthority() { + return grantedAuthority; + } + + public void setGrantedAuthority(ArrayList grantedAuthority) { + this.grantedAuthority = grantedAuthority; + } @Override public String toString() { diff --git a/maxkey-core/src/main/java/org/maxkey/authn/RealmAuthenticationProvider.java b/maxkey-core/src/main/java/org/maxkey/authn/RealmAuthenticationProvider.java index fe9c929f..d1386b24 100644 --- a/maxkey-core/src/main/java/org/maxkey/authn/RealmAuthenticationProvider.java +++ b/maxkey-core/src/main/java/org/maxkey/authn/RealmAuthenticationProvider.java @@ -52,6 +52,7 @@ public class RealmAuthenticationProvider extends AbstractAuthenticationProvider authenticationRealm.passwordPolicyValid(userInfo); authenticationRealm.passwordMatches(userInfo, auth.getJ_password()); + authenticationRealm.grantAuthority(userInfo); /** * put userInfo to current session context */ @@ -63,9 +64,11 @@ public class RealmAuthenticationProvider extends AbstractAuthenticationProvider _logger.debug("do Remeber Me"); } } + + auth.setAuthenticated(true); UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken =new UsernamePasswordAuthenticationToken( - userInfo, - auth.getJ_password(), + auth, + "PASSWORD", authenticationRealm.grantAuthorityAndNavs(userInfo)); usernamePasswordAuthenticationToken.setDetails(new WebAuthenticationDetails(WebContext.getRequest())); diff --git a/maxkey-core/src/main/java/org/maxkey/authn/support/rememberme/AbstractRemeberMeService.java b/maxkey-core/src/main/java/org/maxkey/authn/support/rememberme/AbstractRemeberMeService.java index 3d91f0a5..832047dd 100644 --- a/maxkey-core/src/main/java/org/maxkey/authn/support/rememberme/AbstractRemeberMeService.java +++ b/maxkey-core/src/main/java/org/maxkey/authn/support/rememberme/AbstractRemeberMeService.java @@ -69,7 +69,7 @@ public abstract class AbstractRemeberMeService { cookie.setMaxAge(maxAge); //cookie.setPath("/"); - cookie.setDomain("."+applicationConfig.getDomainName()); + cookie.setDomain(applicationConfig.getDomainName()); response.addCookie(cookie); request.getSession().removeAttribute(WebConstants.REMEBER_ME_SESSION); } @@ -126,7 +126,7 @@ public abstract class AbstractRemeberMeService { cookie.setMaxAge(maxAge); //cookie.setPath("/"); - cookie.setDomain("."+applicationConfig.getDomainName()); + cookie.setDomain(applicationConfig.getDomainName()); response.addCookie(cookie); return true; } @@ -135,7 +135,7 @@ public abstract class AbstractRemeberMeService { Cookie cookie= new Cookie(WebConstants.REMEBER_ME_COOKIE,null); cookie.setMaxAge(0); - cookie.setDomain("."+applicationConfig.getDomainName()); + cookie.setDomain(applicationConfig.getDomainName()); response.addCookie(cookie); remove(WebContext.getUserInfo().getUsername()); diff --git a/maxkey-core/src/main/java/org/maxkey/domain/Accounts.java b/maxkey-core/src/main/java/org/maxkey/domain/Accounts.java index a2371bbc..41c36d5a 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/Accounts.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/Accounts.java @@ -2,6 +2,12 @@ package org.maxkey.domain; import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + import org.apache.mybatis.jpa.persistence.JpaBaseDomain; import org.hibernate.validator.constraints.Length; @@ -15,22 +21,33 @@ import org.hibernate.validator.constraints.Length; STATUS char(1) null constraint PK_ROLES primary key clustered (ID) */ -public class Accounts extends JpaBaseDomain implements Serializable{ +@Table(name = "ACCOUNTS") +public class Accounts extends JpaBaseDomain implements Serializable{ /** * */ private static final long serialVersionUID = 6829592256223630307L; + @Id + @Column + @GeneratedValue(strategy=GenerationType.AUTO,generator="uuid") private String id; + @Column private String uid; + @Column private String username; + @Column private String displayName; + @Column private String appId; + @Column private String appName; @Length(max=60) + @Column private String relatedUsername; + @Column private String relatedPassword; public Accounts(){ diff --git a/maxkey-core/src/main/java/org/maxkey/domain/LoginAppsHistory.java b/maxkey-core/src/main/java/org/maxkey/domain/LoginAppsHistory.java index 350545dc..cfd3853c 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/LoginAppsHistory.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/LoginAppsHistory.java @@ -1,21 +1,39 @@ package org.maxkey.domain; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + import org.apache.mybatis.jpa.persistence.JpaBaseDomain; /** * @author Crystal.Sea * */ + +@Table(name = "LOGIN_APPS_HISTORY") public class LoginAppsHistory extends JpaBaseDomain { private static final long serialVersionUID = 5085201575292304749L; + @Id + @Column + @GeneratedValue(strategy=GenerationType.AUTO,generator="uuid") String id; + @Column private String sessionId; + @Column private String appId; + @Column private String appName; + @Column private String uid; + @Column private String username; + @Column private String displayName; + @Column private String loginTime; diff --git a/maxkey-core/src/main/java/org/maxkey/domain/LoginHistory.java b/maxkey-core/src/main/java/org/maxkey/domain/LoginHistory.java index ef5d19b6..bfab0e76 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/LoginHistory.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/LoginHistory.java @@ -2,6 +2,9 @@ package org.maxkey.domain; import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Table; + import org.apache.mybatis.jpa.persistence.JpaBaseDomain; @@ -9,32 +12,42 @@ import org.apache.mybatis.jpa.persistence.JpaBaseDomain; * @author Crystal.Sea * */ +@Table(name = "LOGIN_HISTORY") public class LoginHistory extends JpaBaseDomain implements Serializable{ /** * */ private static final long serialVersionUID = -1321470643357719383L; - + @Column String sessionId; + @Column String uid; + @Column String username; + @Column String displayName; - + @Column String loginType; + @Column String message; - + @Column String code; - + @Column String provider; - + @Column String sourceIp; + @Column String browser; + @Column String platform; + @Column String application; + @Column String loginUrl; - + @Column String loginTime; + @Column String logoutTime; diff --git a/maxkey-core/src/main/java/org/maxkey/domain/UserInfo.java b/maxkey-core/src/main/java/org/maxkey/domain/UserInfo.java index e1dd9f96..9eebc2f9 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/UserInfo.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/UserInfo.java @@ -3,6 +3,12 @@ package org.maxkey.domain; import java.io.IOException; import java.util.HashMap; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + import org.apache.mybatis.jpa.persistence.JpaBaseDomain; import org.codehaus.jackson.annotate.JsonIgnore; import org.maxkey.util.StringUtils; @@ -12,6 +18,7 @@ import org.springframework.web.multipart.MultipartFile; * @author Crystal.Sea * */ +@Table(name = "USERINFO") public class UserInfo extends JpaBaseDomain { /** @@ -19,8 +26,11 @@ public class UserInfo extends JpaBaseDomain { */ private static final long serialVersionUID = 6402443942083382236L; // - + @Id + @Column + @GeneratedValue(strategy=GenerationType.AUTO,generator="uuid") String id; + @Column protected String username; protected String password; protected String decipherable; diff --git a/maxkey-core/src/main/java/org/maxkey/domain/apps/Applications.java b/maxkey-core/src/main/java/org/maxkey/domain/apps/Applications.java index 94b074cd..2c7994cb 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/apps/Applications.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/apps/Applications.java @@ -3,12 +3,18 @@ package org.maxkey.domain.apps; import java.io.Serializable; import java.util.Arrays; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + import org.apache.mybatis.jpa.persistence.JpaBaseDomain; import org.maxkey.constants.BOOLEAN; import org.maxkey.domain.Accounts; import org.springframework.web.multipart.MultipartFile; - +@Table(name = "APPLICATIONS") public class Applications extends JpaBaseDomain implements Serializable{ /** @@ -30,7 +36,9 @@ public class Applications extends JpaBaseDomain implements Serializable{ public static final int INTRANET=3; } - + @Id + @Column + @GeneratedValue(strategy=GenerationType.AUTO,generator="uuid") protected String id; /** * diff --git a/maxkey-core/src/main/java/org/maxkey/domain/apps/CasDetails.java b/maxkey-core/src/main/java/org/maxkey/domain/apps/CasDetails.java index f596c47f..01e8ca5a 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/apps/CasDetails.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/apps/CasDetails.java @@ -1,14 +1,25 @@ package org.maxkey.domain.apps; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +@Table(name = "CAS_DETAILS") public class CasDetails extends Applications { /** * */ private static final long serialVersionUID = -4272290765948322084L; + @Id + @Column + @GeneratedValue(strategy=GenerationType.AUTO,generator="uuid") + private String id; + @Column private String service; - + @Column private String validation; /** diff --git a/maxkey-core/src/main/java/org/maxkey/domain/apps/FormBasedDetails.java b/maxkey-core/src/main/java/org/maxkey/domain/apps/FormBasedDetails.java index c5bb7c84..05cb191b 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/apps/FormBasedDetails.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/apps/FormBasedDetails.java @@ -1,20 +1,33 @@ package org.maxkey.domain.apps; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; /** * @author Crystal.Sea * */ +@Table(name = "FORM_BASED_DETAILS") public class FormBasedDetails extends Applications { /** * */ private static final long serialVersionUID = 563313247706861431L; + @Id + @Column + @GeneratedValue(strategy=GenerationType.AUTO,generator="uuid") + protected String id; - + @Column private String redirectUri; + @Column private String usernameMapping; + @Column private String passwordMapping; + @Column private String authorizeView; @@ -81,6 +94,16 @@ public class FormBasedDetails extends Applications { } + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + @Override public String toString() { return "FormBasedDetails [redirectUri=" + redirectUri diff --git a/maxkey-core/src/main/java/org/maxkey/domain/apps/SAML20Details.java b/maxkey-core/src/main/java/org/maxkey/domain/apps/SAML20Details.java index e25b1cbf..4fb0512c 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/apps/SAML20Details.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/apps/SAML20Details.java @@ -1,19 +1,96 @@ package org.maxkey.domain.apps; +import java.util.Arrays; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.springframework.web.multipart.MultipartFile; /** * @author Crystal.Sea * */ -public class SAML20Details extends SAMLBaseDetails { +@Table(name = "SAML_V20_DETAILS") +public class SAML20Details extends Applications { /** * */ private static final long serialVersionUID = -291159876339333345L; + @Id + @Column + @GeneratedValue(strategy=GenerationType.AUTO,generator="uuid") + protected String id; + @Column + private String certIssuer; + @Column + private String certSubject; + @Column + private String certExpiration; + @Column + private byte[] keyStore; + private String entityId; + @Column + private String spAcsUrl; + @Column + private String issuer; + @Column + private String audience; + @Column + private String nameidFormat; + @Column + private String validityInterval; + /** + * Redirect-Post + * Post-Post + * IdpInit-Post + * Redirect-PostSimpleSign + * Post-PostSimpleSign + * IdpInit-PostSimpleSign + */ + @Column + private String binding; + + /** + * 0 false + * 1 true + */ + @Column + private int encrypted; + + /** + * for upload + */ + @Column + private MultipartFile certMetaFile; + /** + * metadata or certificate + */ + @Column + private String fileType; + + /** + * 0 original + * 1 uppercase + * 2 lowercase + */ + @Column + private int nameIdConvert; + public static class BINDINGTYPE{ + public String Redirect_Post="Redirect-Post"; + public String Post_Post="Post-Post"; + public String IdpInit_Post="IdpInit-Post"; + public String Redirect_PostSimpleSign="Redirect-PostSimpleSign"; + public String Post_PostSimpleSign="Post-PostSimpleSign"; + public String IdpInit_PostSimpleSign="IdpInit-PostSimpleSign"; + } @@ -25,4 +102,315 @@ public class SAML20Details extends SAMLBaseDetails { } + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + /** + * @return the certIssuer + */ + public String getCertIssuer() { + return certIssuer; + } + + + + + /** + * @param certIssuer the certIssuer to set + */ + public void setCertIssuer(String certIssuer) { + this.certIssuer = certIssuer; + } + + + + + /** + * @return the certSubject + */ + public String getCertSubject() { + return certSubject; + } + + + + + /** + * @param certSubject the certSubject to set + */ + public void setCertSubject(String certSubject) { + this.certSubject = certSubject; + } + + + + + /** + * @return the certExpiration + */ + public String getCertExpiration() { + return certExpiration; + } + + + + + /** + * @param certExpiration the certExpiration to set + */ + public void setCertExpiration(String certExpiration) { + this.certExpiration = certExpiration; + } + + + + + /** + * @return the keyStore + */ + public byte[] getKeyStore() { + return keyStore; + } + + + + + /** + * @param keyStore the keyStore to set + */ + public void setKeyStore(byte[] keyStore) { + this.keyStore = keyStore; + } + + + + + /** + * @return the entityId + */ + public String getEntityId() { + return entityId; + } + + + + + /** + * @param entityId the entityId to set + */ + public void setEntityId(String entityId) { + this.entityId = entityId; + } + + + + + /** + * @return the spAcsUrl + */ + public String getSpAcsUrl() { + return spAcsUrl; + } + + + + + /** + * @param spAcsUrl the spAcsUrl to set + */ + public void setSpAcsUrl(String spAcsUrl) { + this.spAcsUrl = spAcsUrl; + } + + + + + /** + * @return the issuer + */ + public String getIssuer() { + return issuer; + } + + + + + /** + * @param issuer the issuer to set + */ + public void setIssuer(String issuer) { + this.issuer = issuer; + } + + + + + + /** + * @return the audience + */ + public String getAudience() { + return audience; + } + + + + + /** + * @param audience the audience to set + */ + public void setAudience(String audience) { + this.audience = audience; + } + + + + + /** + * @return the nameidFormat + */ + public String getNameidFormat() { + return nameidFormat; + } + + + + + /** + * @param nameidFormat the nameidFormat to set + */ + public void setNameidFormat(String nameidFormat) { + this.nameidFormat = nameidFormat; + } + + + + + /** + * @return the validityInterval + */ + public String getValidityInterval() { + return validityInterval; + } + + + + + /** + * @param validityInterval the validityInterval to set + */ + public void setValidityInterval(String validityInterval) { + this.validityInterval = validityInterval; + } + + + + + /** + * @return the certMetaFile + */ + public MultipartFile getCertMetaFile() { + return certMetaFile; + } + + + + + /** + * @param certMetaFile the certMetaFile to set + */ + public void setCertMetaFile(MultipartFile certMetaFile) { + this.certMetaFile = certMetaFile; + } + + + + + /** + * @return the fileType + */ + public String getFileType() { + return fileType; + } + + + + + /** + * @param fileType the fileType to set + */ + public void setFileType(String fileType) { + this.fileType = fileType; + } + + + + + public String getBinding() { + return binding; + } + + + + + public void setBinding(String binding) { + this.binding = binding; + } + + + public int getEncrypted() { + return encrypted; + } + + + + + public void setEncrypted(int encrypted) { + this.encrypted = encrypted; + } + + + + + public int getNameIdConvert() { + return nameIdConvert; + } + + + + + public void setNameIdConvert(int nameIdConvert) { + this.nameIdConvert = nameIdConvert; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "SAMLBaseDetails [certIssuer=" + certIssuer + ", certSubject=" + + certSubject + ", certExpiration=" + certExpiration + + ", keyStore=" + Arrays.toString(keyStore) + ", entityId=" + + entityId + ", spAcsUrl=" + spAcsUrl + ", issuer=" + issuer + + ", audience=" + audience + ", nameidFormat=" + nameidFormat + + ", validityInterval=" + validityInterval + ", binding=" + + binding + ", encrypted=" + encrypted + ", certMetaFile=" + + certMetaFile + ", fileType=" + fileType + ", nameIdConvert=" + + nameIdConvert + "]"; + } + + + + + + } diff --git a/maxkey-core/src/main/java/org/maxkey/domain/apps/SAMLBaseDetails.java b/maxkey-core/src/main/java/org/maxkey/domain/apps/SAMLBaseDetails.java deleted file mode 100644 index 6092644f..00000000 --- a/maxkey-core/src/main/java/org/maxkey/domain/apps/SAMLBaseDetails.java +++ /dev/null @@ -1,378 +0,0 @@ -package org.maxkey.domain.apps; - -import java.util.Arrays; - -import org.springframework.web.multipart.MultipartFile; - - -/** - * @author Crystal.Sea - * - */ -public class SAMLBaseDetails extends Applications { - - /** - * - */ - private static final long serialVersionUID = -1091817972127532386L; - - private String certIssuer; - private String certSubject; - private String certExpiration; - private byte[] keyStore; - - private String entityId; - private String spAcsUrl; - private String issuer; - private String audience; - private String nameidFormat; - private String validityInterval; - /** - * Redirect-Post - * Post-Post - * IdpInit-Post - * Redirect-PostSimpleSign - * Post-PostSimpleSign - * IdpInit-PostSimpleSign - */ - private String binding; - - /** - * 0 false - * 1 true - */ - private int encrypted; - - /** - * for upload - */ - private MultipartFile certMetaFile; - /** - * metadata or certificate - */ - private String fileType; - - /** - * 0 original - * 1 uppercase - * 2 lowercase - */ - private int nameIdConvert; - - - public static class BINDINGTYPE{ - public String Redirect_Post="Redirect-Post"; - public String Post_Post="Post-Post"; - public String IdpInit_Post="IdpInit-Post"; - public String Redirect_PostSimpleSign="Redirect-PostSimpleSign"; - public String Post_PostSimpleSign="Post-PostSimpleSign"; - public String IdpInit_PostSimpleSign="IdpInit-PostSimpleSign"; - } - - - - /** - * - */ - public SAMLBaseDetails() { - super(); - - } - - - /** - * @return the certIssuer - */ - public String getCertIssuer() { - return certIssuer; - } - - - - - /** - * @param certIssuer the certIssuer to set - */ - public void setCertIssuer(String certIssuer) { - this.certIssuer = certIssuer; - } - - - - - /** - * @return the certSubject - */ - public String getCertSubject() { - return certSubject; - } - - - - - /** - * @param certSubject the certSubject to set - */ - public void setCertSubject(String certSubject) { - this.certSubject = certSubject; - } - - - - - /** - * @return the certExpiration - */ - public String getCertExpiration() { - return certExpiration; - } - - - - - /** - * @param certExpiration the certExpiration to set - */ - public void setCertExpiration(String certExpiration) { - this.certExpiration = certExpiration; - } - - - - - /** - * @return the keyStore - */ - public byte[] getKeyStore() { - return keyStore; - } - - - - - /** - * @param keyStore the keyStore to set - */ - public void setKeyStore(byte[] keyStore) { - this.keyStore = keyStore; - } - - - - - /** - * @return the entityId - */ - public String getEntityId() { - return entityId; - } - - - - - /** - * @param entityId the entityId to set - */ - public void setEntityId(String entityId) { - this.entityId = entityId; - } - - - - - /** - * @return the spAcsUrl - */ - public String getSpAcsUrl() { - return spAcsUrl; - } - - - - - /** - * @param spAcsUrl the spAcsUrl to set - */ - public void setSpAcsUrl(String spAcsUrl) { - this.spAcsUrl = spAcsUrl; - } - - - - - /** - * @return the issuer - */ - public String getIssuer() { - return issuer; - } - - - - - /** - * @param issuer the issuer to set - */ - public void setIssuer(String issuer) { - this.issuer = issuer; - } - - - - - - /** - * @return the audience - */ - public String getAudience() { - return audience; - } - - - - - /** - * @param audience the audience to set - */ - public void setAudience(String audience) { - this.audience = audience; - } - - - - - /** - * @return the nameidFormat - */ - public String getNameidFormat() { - return nameidFormat; - } - - - - - /** - * @param nameidFormat the nameidFormat to set - */ - public void setNameidFormat(String nameidFormat) { - this.nameidFormat = nameidFormat; - } - - - - - /** - * @return the validityInterval - */ - public String getValidityInterval() { - return validityInterval; - } - - - - - /** - * @param validityInterval the validityInterval to set - */ - public void setValidityInterval(String validityInterval) { - this.validityInterval = validityInterval; - } - - - - - /** - * @return the certMetaFile - */ - public MultipartFile getCertMetaFile() { - return certMetaFile; - } - - - - - /** - * @param certMetaFile the certMetaFile to set - */ - public void setCertMetaFile(MultipartFile certMetaFile) { - this.certMetaFile = certMetaFile; - } - - - - - /** - * @return the fileType - */ - public String getFileType() { - return fileType; - } - - - - - /** - * @param fileType the fileType to set - */ - public void setFileType(String fileType) { - this.fileType = fileType; - } - - - - - public String getBinding() { - return binding; - } - - - - - public void setBinding(String binding) { - this.binding = binding; - } - - - public int getEncrypted() { - return encrypted; - } - - - - - public void setEncrypted(int encrypted) { - this.encrypted = encrypted; - } - - - - - public int getNameIdConvert() { - return nameIdConvert; - } - - - - - public void setNameIdConvert(int nameIdConvert) { - this.nameIdConvert = nameIdConvert; - } - - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "SAMLBaseDetails [certIssuer=" + certIssuer + ", certSubject=" - + certSubject + ", certExpiration=" + certExpiration - + ", keyStore=" + Arrays.toString(keyStore) + ", entityId=" - + entityId + ", spAcsUrl=" + spAcsUrl + ", issuer=" + issuer - + ", audience=" + audience + ", nameidFormat=" + nameidFormat - + ", validityInterval=" + validityInterval + ", binding=" - + binding + ", encrypted=" + encrypted + ", certMetaFile=" - + certMetaFile + ", fileType=" + fileType + ", nameIdConvert=" - + nameIdConvert + "]"; - } - -} diff --git a/maxkey-core/src/main/java/org/maxkey/domain/apps/TokenBasedDetails.java b/maxkey-core/src/main/java/org/maxkey/domain/apps/TokenBasedDetails.java index cb2b3733..983e419c 100644 --- a/maxkey-core/src/main/java/org/maxkey/domain/apps/TokenBasedDetails.java +++ b/maxkey-core/src/main/java/org/maxkey/domain/apps/TokenBasedDetails.java @@ -3,11 +3,17 @@ */ package org.maxkey.domain.apps; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; /** * @author Crystal.Sea * */ +@Table(name = "TOKEN_BASED_DETAILS") public class TokenBasedDetails extends Applications { /** @@ -15,23 +21,39 @@ public class TokenBasedDetails extends Applications { */ private static final long serialVersionUID = -1717427271305620545L; + @Id + @Column + @GeneratedValue(strategy=GenerationType.AUTO,generator="uuid") + protected String id; /** * */ + @Column private String redirectUri; // + @Column private String cookieName; + @Column private String algorithm; + @Column private String algorithmKey; + @Column private String expires; // + @Column private int uid; + @Column private int username; + @Column private int email; + @Column private int windowsAccount; + @Column private int employeeNumber; + @Column private int departmentId; + @Column private int department; diff --git a/maxkey-core/src/main/java/org/maxkey/web/WebConstants.java b/maxkey-core/src/main/java/org/maxkey/web/WebConstants.java index 52520218..d305e2ca 100644 --- a/maxkey-core/src/main/java/org/maxkey/web/WebConstants.java +++ b/maxkey-core/src/main/java/org/maxkey/web/WebConstants.java @@ -53,4 +53,6 @@ public class WebConstants { public static final String CURRENT_SINGLESIGNON_URI = "current_singlesignon_uri"; + public static final String AUTHENTICATION = "current_authentication"; + } diff --git a/maxkey-core/src/main/java/org/maxkey/web/WebContext.java b/maxkey-core/src/main/java/org/maxkey/web/WebContext.java index d2e24e06..a9ee4d50 100644 --- a/maxkey-core/src/main/java/org/maxkey/web/WebContext.java +++ b/maxkey-core/src/main/java/org/maxkey/web/WebContext.java @@ -147,11 +147,15 @@ public final class WebContext { } return true; } + + public static void setAuthentication(Authentication authentication) { + setAttribute(WebConstants.AUTHENTICATION,authentication); + } - public static Authentication getAuthentication(){ - UsernamePasswordAuthenticationToken authentication =(UsernamePasswordAuthenticationToken)SecurityContextHolder.getContext().getAuthentication(); - return authentication; - } + public static Authentication getAuthentication() { + Authentication authentication = (Authentication)getAttribute(WebConstants.AUTHENTICATION); + return authentication; + } public static boolean isAuthenticated(){ if (getUserInfo() != null) { diff --git a/maxkey-dao/.classpath b/maxkey-dao/.classpath index 467ef2f2..540156aa 100644 --- a/maxkey-dao/.classpath +++ b/maxkey-dao/.classpath @@ -12,6 +12,18 @@ + + + + + + + + + + + + diff --git a/maxkey-dao/.settings/org.eclipse.wst.common.component b/maxkey-dao/.settings/org.eclipse.wst.common.component index bc78e037..b9758908 100644 --- a/maxkey-dao/.settings/org.eclipse.wst.common.component +++ b/maxkey-dao/.settings/org.eclipse.wst.common.component @@ -2,5 +2,7 @@ + + diff --git a/maxkey-dao/src/main/java/org/maxkey/dao/persistence/MyAppsListMapper.java b/maxkey-dao/src/main/java/org/maxkey/dao/persistence/MyAppsListMapper.java index 5bce30dd..5ba10635 100644 --- a/maxkey-dao/src/main/java/org/maxkey/dao/persistence/MyAppsListMapper.java +++ b/maxkey-dao/src/main/java/org/maxkey/dao/persistence/MyAppsListMapper.java @@ -3,6 +3,8 @@ */ package org.maxkey.dao.persistence; +import java.util.List; + import org.apache.mybatis.jpa.persistence.IJpaBaseMapper; import org.maxkey.domain.apps.UserApplications; @@ -12,5 +14,5 @@ import org.maxkey.domain.apps.UserApplications; */ public interface MyAppsListMapper extends IJpaBaseMapper { - + public List queryMyApps(UserApplications userApplications); } diff --git a/maxkey-dao/src/main/java/org/maxkey/dao/service/MyAppsListService.java b/maxkey-dao/src/main/java/org/maxkey/dao/service/MyAppsListService.java index dbf52d71..ba761ce6 100644 --- a/maxkey-dao/src/main/java/org/maxkey/dao/service/MyAppsListService.java +++ b/maxkey-dao/src/main/java/org/maxkey/dao/service/MyAppsListService.java @@ -1,5 +1,7 @@ package org.maxkey.dao.service; +import java.util.List; + import org.apache.mybatis.jpa.persistence.JpaBaseService; import org.maxkey.dao.persistence.MyAppsListMapper; import org.maxkey.domain.apps.UserApplications; @@ -12,6 +14,9 @@ public class MyAppsListService extends JpaBaseService{ super(MyAppsListMapper.class); } + public List queryMyApps(UserApplications userApplications){ + return getMapper().queryMyApps(userApplications); + } /* (non-Javadoc) * @see com.connsec.db.service.BaseService#getMapper() */ diff --git a/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/DesktopDetailsMapper.xml b/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/DesktopDetailsMapper.xml index 611cff44..dc830d5f 100644 --- a/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/DesktopDetailsMapper.xml +++ b/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/DesktopDetailsMapper.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/ForgotPasswordMapper.xml b/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/ForgotPasswordMapper.xml index 9f7305ec..1fdf3e8a 100644 --- a/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/ForgotPasswordMapper.xml +++ b/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/ForgotPasswordMapper.xml @@ -1,6 +1,6 @@ - + + SELECT diff --git a/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/ReportMapper.xml b/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/ReportMapper.xml index 102495d6..82a02d68 100644 --- a/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/ReportMapper.xml +++ b/maxkey-dao/src/main/resources/org/maxkey/dao/persistence/xml/mysql/ReportMapper.xml @@ -1,6 +1,6 @@ - + - - - - - - - - - - - - +
+ +
+
<% if (session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION) != null && !(session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION) instanceof UnapprovedClientAuthenticationException)) { %> @@ -63,11 +28,10 @@ <% } %> -

Please Confirm OAuth 2.0

You hereby authorize "${client.clientId}" to access your protected resources.

-
+
    @@ -87,8 +51,10 @@
-
+ diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/webapp/WEB-INF/web.xml b/maxkey-webs/maxkey-web-maxkey/src/main/webapp/WEB-INF/web.xml index a5611615..fd12bb16 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/webapp/WEB-INF/web.xml +++ b/maxkey-webs/maxkey-web-maxkey/src/main/webapp/WEB-INF/web.xml @@ -108,6 +108,16 @@ ipAddressFilter /* + + + + + OAuth20TokenEndpointAuthenticationFilter + org.maxkey.authz.oauth2.provider.endpoint.TokenEndpointAuthenticationFilter + + + OAuth20TokenEndpointAuthenticationFilter + /oauth/v20/token