-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($auth-center): migrate codes from
api-portal
- Loading branch information
1 parent
efc5c26
commit 9b07500
Showing
32 changed files
with
1,724 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../src/main/java/com/jmsoftware/authcenter/universal/configuration/CustomConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.jmsoftware.authcenter.universal.configuration; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* <h1>CustomConfiguration</h1> | ||
* <p>Custom configurations which are written in .yml files, containing a variety of fragmentary configs. Such as, | ||
* Druid login info, web security switch, web log and so on.</p> | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com | ||
* @date 2019-03-23 14:24 | ||
**/ | ||
@Data | ||
@Component | ||
@ConfigurationProperties(prefix = "custom.configuration") | ||
public class CustomConfiguration { | ||
/** | ||
* <p>The username of super user who has no restriction to access any system's resources.</p> | ||
* <p><strong>ATTENTION</strong>: The value of username of super user must be equal to the value that is | ||
* persistent in database.</p> | ||
*/ | ||
private String superUser; | ||
/** | ||
* Ignore URLs | ||
*/ | ||
private IgnoredRequest ignoredRequest; | ||
private String druidLoginName; | ||
private String druidPassword; | ||
/** | ||
* <p>Web security feature switch. Default is false.</p> | ||
* true - disable web security; false - enable web security. | ||
*/ | ||
private Boolean webSecurityDisabled = false; | ||
/** | ||
* Web request log switch. Default is false. | ||
* <p> | ||
* true - disable web request log; false - enable web request log. | ||
*/ | ||
private Boolean webRequestLogDisabled = false; | ||
} |
54 changes: 54 additions & 0 deletions
54
...enter/src/main/java/com/jmsoftware/authcenter/universal/configuration/IgnoredRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.jmsoftware.authcenter.universal.configuration; | ||
|
||
import com.google.common.collect.Lists; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* <h1>IgnoredRequest</h1> | ||
* <p> | ||
* Ignored request configuration. | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com | ||
* @date 5/2/20 11:41 PM | ||
**/ | ||
@Data | ||
public class IgnoredRequest { | ||
/** | ||
* Ignored URL pattern. | ||
*/ | ||
private List<String> pattern = Lists.newArrayList(); | ||
/** | ||
* Ignored GET request. | ||
*/ | ||
private List<String> get = Lists.newArrayList(); | ||
/** | ||
* Ignored POST request. | ||
*/ | ||
private List<String> post = Lists.newArrayList(); | ||
/** | ||
* Ignored DELETE request. | ||
*/ | ||
private List<String> delete = Lists.newArrayList(); | ||
/** | ||
* Ignored PUT request. | ||
*/ | ||
private List<String> put = Lists.newArrayList(); | ||
/** | ||
* Ignored HEAD request. | ||
*/ | ||
private List<String> head = Lists.newArrayList(); | ||
/** | ||
* Ignored PATCH request. | ||
*/ | ||
private List<String> patch = Lists.newArrayList(); | ||
/** | ||
* Ignored OPTIONS request. | ||
*/ | ||
private List<String> options = Lists.newArrayList(); | ||
/** | ||
* Ignored TRACE request. | ||
*/ | ||
private List<String> trace = Lists.newArrayList(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
.../main/java/com/jmsoftware/authcenter/universal/configuration/SftpClientConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.jmsoftware.authcenter.universal.configuration; | ||
|
||
import com.jcraft.jsch.ChannelSftp; | ||
import lombok.Data; | ||
import lombok.val; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.expression.common.LiteralExpression; | ||
import org.springframework.integration.annotation.ServiceActivator; | ||
import org.springframework.integration.file.remote.session.CachingSessionFactory; | ||
import org.springframework.integration.file.remote.session.SessionFactory; | ||
import org.springframework.integration.sftp.outbound.SftpMessageHandler; | ||
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory; | ||
import org.springframework.integration.sftp.session.SftpRemoteFileTemplate; | ||
import org.springframework.messaging.MessageHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* <h1>SftpClientConfiguration</h1> | ||
* <p>SFTP client configuration</p> | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com | ||
* @date 2019-07-04 18:18 | ||
**/ | ||
@Data | ||
@Component | ||
@ConfigurationProperties(prefix = "sftp.client.configuration") | ||
public class SftpClientConfiguration { | ||
/** | ||
* SFTP server IP | ||
*/ | ||
private String host; | ||
/** | ||
* SFTP server port | ||
*/ | ||
private Integer port; | ||
/** | ||
* Login user | ||
*/ | ||
private String user; | ||
/** | ||
* Login password | ||
*/ | ||
private String password; | ||
/** | ||
* Remote directory | ||
*/ | ||
private String directory; | ||
/** | ||
* Private key | ||
*/ | ||
private Resource privateKey; | ||
/** | ||
* Private key pass phrase | ||
*/ | ||
private String privateKeyPassPhrase; | ||
/** | ||
* The maximum cache size of session. Default: 10 | ||
*/ | ||
private Integer sessionCacheSize = 10; | ||
/** | ||
* The session wait timeout (time unit: MILLISECONDS). Default: 10 * 1000L (10 seconds) | ||
*/ | ||
private Long sessionWaitTimeout = 10 * 1000L; | ||
|
||
@Bean | ||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() { | ||
val factory = new DefaultSftpSessionFactory(true); | ||
factory.setHost(host); | ||
factory.setPort(port); | ||
factory.setUser(user); | ||
if (privateKey != null) { | ||
factory.setPrivateKey(privateKey); | ||
factory.setPrivateKeyPassphrase(privateKeyPassPhrase); | ||
} else { | ||
factory.setPassword(password); | ||
} | ||
factory.setAllowUnknownKeys(true); | ||
// We return a caching session factory, so that we don't have to reconnect to SFTP server for each time | ||
val cachingSessionFactory = new CachingSessionFactory<>(factory, sessionCacheSize); | ||
cachingSessionFactory.setSessionWaitTimeout(sessionWaitTimeout); | ||
return cachingSessionFactory; | ||
} | ||
|
||
@Bean | ||
@ServiceActivator(inputChannel = "toSftpChannel") | ||
@SuppressWarnings("UnresolvedMessageChannel") | ||
public MessageHandler handler(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) { | ||
val handler = new SftpMessageHandler(sftpSessionFactory); | ||
handler.setRemoteDirectoryExpression(new LiteralExpression(directory)); | ||
handler.setFileNameGenerator(message -> { | ||
if (message.getPayload() instanceof File) { | ||
return ((File) message.getPayload()).getName(); | ||
} else { | ||
throw new IllegalArgumentException("File expected as payload."); | ||
} | ||
}); | ||
return handler; | ||
} | ||
|
||
@Bean | ||
public SftpRemoteFileTemplate template(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) { | ||
return new SftpRemoteFileTemplate(sftpSessionFactory); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...c/main/java/com/jmsoftware/authcenter/universal/configuration/SftpSubDirectoryRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.jmsoftware.authcenter.universal.configuration; | ||
|
||
import com.jmsoftware.authcenter.universal.domain.SftpSubDirectory; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.integration.sftp.session.SftpRemoteFileTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* <h1>SftpSubDirectoryRunner</h1> | ||
* <p>After dependency injection finished, we must inti the SFTP server's sub directory for out business. If you want | ||
* to customize initialization configuration, config SftpSubDirectory.</p> | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com | ||
* @date 2019-07-05 08:51 | ||
* @see SftpSubDirectory | ||
**/ | ||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class SftpSubDirectoryRunner implements ApplicationRunner { | ||
private final SftpRemoteFileTemplate sftpRemoteFileTemplate; | ||
private final SftpClientConfiguration sftpClientConfiguration; | ||
|
||
@Override | ||
public void run(ApplicationArguments args) { | ||
sftpRemoteFileTemplate.setAutoCreateDirectory(true); | ||
sftpRemoteFileTemplate.execute(session -> { | ||
if (!session.exists(sftpClientConfiguration.getDirectory())) { | ||
log.info("Make directories for SFTP server. Directory: {}", sftpClientConfiguration.getDirectory()); | ||
session.mkdir(sftpClientConfiguration.getDirectory()); | ||
} else { | ||
log.info("SFTP server remote directory exists: {}", sftpClientConfiguration.getDirectory()); | ||
} | ||
return null; | ||
}); | ||
|
||
log.info("Staring to initial SFTP server sub directory."); | ||
sftpRemoteFileTemplate.execute(session -> { | ||
for (val sftpSubDirectory : SftpSubDirectory.values()) { | ||
val fullPath = sftpClientConfiguration.getDirectory() + sftpSubDirectory.getSubDirectory(); | ||
if (!session.exists(fullPath)) { | ||
log.info("SFTP server sub directory does not exist. Creating sub directory: {}", fullPath); | ||
session.mkdir(fullPath); | ||
} else { | ||
log.info("SFTP server sub directory exists. Path: {}", fullPath); | ||
} | ||
} | ||
return null; | ||
}); | ||
log.info("Initialing SFTP server sub directory is done."); | ||
} | ||
} |
Oops, something went wrong.