commit
bee7fafbaf
|
@ -40,14 +40,14 @@ public class CasSecuredAppApplication {
|
|||
@Primary
|
||||
public AuthenticationEntryPoint authenticationEntryPoint(ServiceProperties sP) {
|
||||
CasAuthenticationEntryPoint entryPoint = new CasAuthenticationEntryPoint();
|
||||
entryPoint.setLoginUrl("https://localhost:8443/cas/login");
|
||||
entryPoint.setLoginUrl("https://localhost:6443/cas/login");
|
||||
entryPoint.setServiceProperties(sP);
|
||||
return entryPoint;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TicketValidator ticketValidator() {
|
||||
return new Cas30ServiceTicketValidator("https://localhost:8443/cas");
|
||||
return new Cas30ServiceTicketValidator("https://localhost:6443/cas");
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -71,7 +71,7 @@ public class CasSecuredAppApplication {
|
|||
@Bean
|
||||
public LogoutFilter logoutFilter() {
|
||||
LogoutFilter logoutFilter = new LogoutFilter(
|
||||
"https://localhost:8443/cas/logout", securityContextLogoutHandler());
|
||||
"https://localhost:6443/cas/logout", securityContextLogoutHandler());
|
||||
logoutFilter.setFilterProcessesUrl("/logout/cas");
|
||||
return logoutFilter;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class CasSecuredAppApplication {
|
|||
@Bean
|
||||
public SingleSignOutFilter singleSignOutFilter() {
|
||||
SingleSignOutFilter singleSignOutFilter = new SingleSignOutFilter();
|
||||
singleSignOutFilter.setCasServerUrlPrefix("https://localhost:8443/cas");
|
||||
singleSignOutFilter.setCasServerUrlPrefix("https://localhost:6443/cas");
|
||||
singleSignOutFilter.setIgnoreInitConfiguration(true);
|
||||
return singleSignOutFilter;
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -2,9 +2,9 @@
|
|||
# CAS Server Context Configuration
|
||||
#
|
||||
server.context-path=/cas
|
||||
server.port=8443
|
||||
server.port=6443
|
||||
|
||||
server.ssl.key-store=file:/etc/cas/thekeystore
|
||||
server.ssl.key-store=classpath:/etc/cas/thekeystore
|
||||
server.ssl.key-store-password=changeit
|
||||
server.ssl.key-password=changeit
|
||||
# server.ssl.ciphers=
|
||||
|
@ -40,6 +40,12 @@ spring.http.encoding.charset=UTF-8
|
|||
spring.http.encoding.enabled=true
|
||||
spring.http.encoding.force=true
|
||||
|
||||
##
|
||||
#CAS CONFIG LOCATION
|
||||
#
|
||||
cas.standalone.config=classpath:/etc/cas/config
|
||||
|
||||
|
||||
##
|
||||
# CAS Cloud Bus Configuration
|
||||
#
|
||||
|
@ -82,6 +88,7 @@ spring.thymeleaf.mode=HTML
|
|||
# CAS Log4j Configuration
|
||||
#
|
||||
# logging.config=file:/etc/cas/log4j2.xml
|
||||
|
||||
server.context-parameters.isLog4jAutoInitializationDisabled=true
|
||||
|
||||
##
|
||||
|
@ -104,9 +111,10 @@ cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQLDialect
|
|||
cas.authn.jdbc.query[0].user=root
|
||||
cas.authn.jdbc.query[0].password=
|
||||
cas.authn.jdbc.query[0].ddlAuto=none
|
||||
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
|
||||
#cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
|
||||
cas.authn.jdbc.query[0].driverClass=com.mysql.cj.jdbc.Driver
|
||||
cas.authn.jdbc.query[0].fieldPassword=password
|
||||
cas.authn.jdbc.query[0].passwordEncoder.type=BCRYPT
|
||||
cas.authn.jdbc.query[0].passwordEncoder.type=NONE
|
||||
|
||||
|
||||
##
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
cas.server.name: https://localhost:8443
|
||||
cas.server.prefix: https://localhost:8443/cas
|
||||
cas.server.name: https://localhost:6443
|
||||
cas.server.prefix: https://localhost:643/cas
|
||||
|
||||
cas.adminPagesSecurity.ip=127\.0\.0\.1
|
||||
|
||||
logging.config: file:/etc/cas/config/log4j2.xml
|
||||
|
||||
cas.serviceRegistry.initFromJson=true
|
||||
cas.serviceRegistry.config.location=classpath:/services
|
||||
|
||||
cas.authn.accept.users=
|
||||
cas.authn.accept.name=
|
||||
|
||||
|
||||
#CAS Database Authentication Property
|
||||
|
||||
# cas.authn.jdbc.query[0].healthQuery=
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
info:
|
||||
description: CAS Configuration
|
|
@ -0,0 +1,7 @@
|
|||
cas.server.name: https://cas.example.org:8443
|
||||
cas.server.prefix: https://cas.example.org:8443/cas
|
||||
|
||||
cas.adminPagesSecurity.ip=127\.0\.0\.1
|
||||
|
||||
logging.config: file:/etc/cas/config/log4j2.xml
|
||||
# cas.serviceRegistry.config.location: classpath:/services
|
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!-- Specify the refresh internal in seconds. -->
|
||||
<Configuration monitorInterval="5" packages="org.apereo.cas.logging">
|
||||
<Properties>
|
||||
<!--
|
||||
Default log directory is the current directory but that can be overridden with -Dcas.log.dir=<logdir>
|
||||
Or you can change this property to a new default
|
||||
-->
|
||||
<Property name="cas.log.dir" >.</Property>
|
||||
<!-- To see more CAS specific logging, adjust this property to info or debug or run server with -Dcas.log.leve=debug -->
|
||||
<Property name="cas.log.level" >warn</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d %p [%c] - <%m>%n"/>
|
||||
</Console>
|
||||
<RollingFile name="file" fileName="${sys:cas.log.dir}/cas.log" append="true"
|
||||
filePattern="${sys:cas.log.dir}/cas-%d{yyyy-MM-dd-HH}-%i.log">
|
||||
<PatternLayout pattern="%d %p [%c] - <%m>%n"/>
|
||||
<Policies>
|
||||
<OnStartupTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="10 MB"/>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
</Policies>
|
||||
</RollingFile>
|
||||
<RollingFile name="auditlogfile" fileName="${sys:cas.log.dir}/cas_audit.log" append="true"
|
||||
filePattern="${sys:cas.log.dir}/cas_audit-%d{yyyy-MM-dd-HH}-%i.log">
|
||||
<PatternLayout pattern="%d %p [%c] - %m%n"/>
|
||||
<Policies>
|
||||
<OnStartupTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="10 MB"/>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
</Policies>
|
||||
</RollingFile>
|
||||
|
||||
<RollingFile name="perfFileAppender" fileName="${sys:cas.log.dir}/perfStats.log" append="true"
|
||||
filePattern="${sys:cas.log.dir}/perfStats-%d{yyyy-MM-dd-HH}-%i.log">
|
||||
<PatternLayout pattern="%m%n"/>
|
||||
<Policies>
|
||||
<OnStartupTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="10 MB"/>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
</Policies>
|
||||
</RollingFile>
|
||||
|
||||
<CasAppender name="casAudit">
|
||||
<AppenderRef ref="auditlogfile" />
|
||||
</CasAppender>
|
||||
<CasAppender name="casFile">
|
||||
<AppenderRef ref="file" />
|
||||
</CasAppender>
|
||||
<CasAppender name="casConsole">
|
||||
<AppenderRef ref="console" />
|
||||
</CasAppender>
|
||||
<CasAppender name="casPerf">
|
||||
<AppenderRef ref="perfFileAppender" />
|
||||
</CasAppender>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<!-- If adding a Logger with level set higher than warn, make category as selective as possible -->
|
||||
<!-- Loggers inherit appenders from Root Logger unless additivity is false -->
|
||||
<AsyncLogger name="org.apereo" level="${sys:cas.log.level}" includeLocation="true"/>
|
||||
<AsyncLogger name="org.apereo.services.persondir" level="${sys:cas.log.level}" includeLocation="true"/>
|
||||
<AsyncLogger name="org.apereo.cas.web.flow" level="info" includeLocation="true"/>
|
||||
<AsyncLogger name="org.apache" level="warn" />
|
||||
<AsyncLogger name="org.apache.http" level="error" />
|
||||
<AsyncLogger name="org.springframework" level="warn" />
|
||||
<AsyncLogger name="org.springframework.cloud.server" level="warn" />
|
||||
<AsyncLogger name="org.springframework.cloud.client" level="warn" />
|
||||
<AsyncLogger name="org.springframework.cloud.bus" level="warn" />
|
||||
<AsyncLogger name="org.springframework.aop" level="warn" />
|
||||
<AsyncLogger name="org.springframework.boot" level="warn" />
|
||||
<AsyncLogger name="org.springframework.boot.actuate.autoconfigure" level="warn" />
|
||||
<AsyncLogger name="org.springframework.webflow" level="warn" />
|
||||
<AsyncLogger name="org.springframework.session" level="warn" />
|
||||
<AsyncLogger name="org.springframework.amqp" level="error" />
|
||||
<AsyncLogger name="org.springframework.integration" level="warn" />
|
||||
<AsyncLogger name="org.springframework.messaging" level="warn" />
|
||||
<AsyncLogger name="org.springframework.web" level="warn" />
|
||||
<AsyncLogger name="org.springframework.orm.jpa" level="warn" />
|
||||
<AsyncLogger name="org.springframework.scheduling" level="warn" />
|
||||
<AsyncLogger name="org.springframework.context.annotation" level="error" />
|
||||
<AsyncLogger name="org.springframework.boot.devtools" level="error" />
|
||||
<AsyncLogger name="org.springframework.web.socket" level="warn" />
|
||||
<AsyncLogger name="org.thymeleaf" level="warn" />
|
||||
<AsyncLogger name="org.pac4j" level="warn" />
|
||||
<AsyncLogger name="org.opensaml" level="warn"/>
|
||||
<AsyncLogger name="net.sf.ehcache" level="warn" />
|
||||
<AsyncLogger name="com.couchbase" level="warn" includeLocation="true"/>
|
||||
<AsyncLogger name="com.ryantenney.metrics" level="warn" />
|
||||
<AsyncLogger name="net.jradius" level="warn" />
|
||||
<AsyncLogger name="org.openid4java" level="warn" />
|
||||
<AsyncLogger name="org.ldaptive" level="warn" />
|
||||
<AsyncLogger name="com.hazelcast" level="warn" />
|
||||
<AsyncLogger name="org.jasig.spring" level="warn" />
|
||||
|
||||
<!-- Log perf stats only to perfStats.log -->
|
||||
<AsyncLogger name="perfStatsLogger" level="info" additivity="false" includeLocation="true">
|
||||
<AppenderRef ref="casPerf"/>
|
||||
</AsyncLogger>
|
||||
|
||||
<!-- Log audit to all root appenders, and also to audit log (additivity is not false) -->
|
||||
<AsyncLogger name="org.apereo.inspektr.audit.support" level="info" includeLocation="true" >
|
||||
<AppenderRef ref="casAudit"/>
|
||||
</AsyncLogger>
|
||||
|
||||
<!-- All Loggers inherit appenders specified here, unless additivity="false" on the Logger -->
|
||||
<AsyncRoot level="warn">
|
||||
<AppenderRef ref="casFile"/>
|
||||
<!--
|
||||
For deployment to an application server running as service,
|
||||
delete the casConsole appender below
|
||||
-->
|
||||
<AppenderRef ref="casConsole"/>
|
||||
</AsyncRoot>
|
||||
</Loggers>
|
||||
</Configuration>
|
Binary file not shown.
Binary file not shown.
|
@ -1,11 +1,18 @@
|
|||
package com.baeldung.concurrent.executorservice;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class DelayedCallable implements Callable<String> {
|
||||
|
||||
private String name;
|
||||
private long period;
|
||||
private CountDownLatch latch;
|
||||
|
||||
public DelayedCallable(String name, long period, CountDownLatch latch) {
|
||||
this(name, period);
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public DelayedCallable(String name, long period) {
|
||||
this.name = name;
|
||||
|
@ -16,9 +23,15 @@ public class DelayedCallable implements Callable<String> {
|
|||
|
||||
try {
|
||||
Thread.sleep(period);
|
||||
|
||||
if (latch != null) {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
} catch (InterruptedException ex) {
|
||||
// handle exception
|
||||
ex.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
return name;
|
||||
|
|
|
@ -9,22 +9,91 @@ import java.util.List;
|
|||
import java.util.concurrent.*;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class WaitingForThreadsToFinishTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WaitingForThreadsToFinishTest.class);
|
||||
private final static ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10);
|
||||
|
||||
public void awaitTerminationAfterShutdown(ExecutorService threadPool) {
|
||||
threadPool.shutdown();
|
||||
try {
|
||||
if (!threadPool.awaitTermination(60, TimeUnit.SECONDS)) {
|
||||
threadPool.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
threadPool.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMultipleThreads_whenUsingCountDownLatch_thenMainShoudWaitForAllToFinish() {
|
||||
|
||||
ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10);
|
||||
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// create a CountDownLatch that waits for the 2 threads to finish
|
||||
CountDownLatch latch = new CountDownLatch(2);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
WORKER_THREAD_POOL.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
latch.countDown();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// wait for the latch to be decremented by the two threads
|
||||
latch.await();
|
||||
|
||||
long processingTime = System.currentTimeMillis() - startTime;
|
||||
assertTrue(processingTime >= 1000);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMultipleThreads_whenInvokeAll_thenMainThreadShouldWaitForAllToFinish() {
|
||||
|
||||
ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10);
|
||||
|
||||
List<Callable<String>> callables = Arrays.asList(new DelayedCallable("fast thread", 100), new DelayedCallable("slow thread", 3000));
|
||||
|
||||
List<Callable<String>> callables = Arrays.asList(
|
||||
new DelayedCallable("fast thread", 100),
|
||||
new DelayedCallable("slow thread", 3000));
|
||||
|
||||
try {
|
||||
long startProcessingTime = System.currentTimeMillis();
|
||||
List<Future<String>> futures = WORKER_THREAD_POOL.invokeAll(callables);
|
||||
|
||||
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
|
||||
|
||||
try {
|
||||
WORKER_THREAD_POOL.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
fail("This thread should have been rejected !");
|
||||
Thread.sleep(1000000);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (RejectedExecutionException ex) {
|
||||
//
|
||||
}
|
||||
|
||||
long totalProcessingTime = System.currentTimeMillis() - startProcessingTime;
|
||||
assertTrue(totalProcessingTime >= 3000);
|
||||
|
@ -39,9 +108,7 @@ public class WaitingForThreadsToFinishTest {
|
|||
|
||||
} catch (ExecutionException | InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
WORKER_THREAD_POOL.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -49,14 +116,14 @@ public class WaitingForThreadsToFinishTest {
|
|||
|
||||
CompletionService<String> service = new ExecutorCompletionService<>(WORKER_THREAD_POOL);
|
||||
|
||||
List<Callable<String>> callables = Arrays.asList(new DelayedCallable("fast thread", 100), new DelayedCallable("slow thread", 3000));
|
||||
List<Callable<String>> callables = Arrays.asList(
|
||||
new DelayedCallable("fast thread", 100),
|
||||
new DelayedCallable("slow thread", 3000));
|
||||
|
||||
for (Callable<String> callable : callables) {
|
||||
service.submit(callable);
|
||||
}
|
||||
|
||||
WORKER_THREAD_POOL.shutdown();
|
||||
|
||||
try {
|
||||
|
||||
long startProcessingTime = System.currentTimeMillis();
|
||||
|
@ -79,8 +146,9 @@ public class WaitingForThreadsToFinishTest {
|
|||
|
||||
} catch (ExecutionException | InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -142,6 +210,6 @@ public class WaitingForThreadsToFinishTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
WORKER_THREAD_POOL.shutdown();
|
||||
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@
|
|||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
package com.baeldung.breakcontinue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* @author Santosh
|
||||
*
|
||||
*/
|
||||
public class BreakContinue {
|
||||
|
||||
public static int unlabeledBreak() {
|
||||
String searchName = "Wilson";
|
||||
int counter = 0;
|
||||
List<String> names = Arrays.asList("John", "Peter", "Robert", "Wilson", "Anthony", "Donald", "Richard");
|
||||
|
||||
for (String name : names) {
|
||||
counter++;
|
||||
if (name.equalsIgnoreCase(searchName)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static int unlabeledBreakNestedLoops() {
|
||||
String searchName = "Wilson";
|
||||
int counter = 0;
|
||||
Map<String, List<String>> nameMap = new HashMap<>();
|
||||
nameMap.put("Grade1", Arrays.asList("John", "Peter", "Robert", "Wilson"));
|
||||
nameMap.put("Grade2", Arrays.asList("Anthony", "Donald", "Richard", "Arnold"));
|
||||
nameMap.put("Grade3", Arrays.asList("Wilson", "Michael", "Stephen", "Ryan"));
|
||||
|
||||
Iterator<Entry<String, List<String>>> iterator = nameMap.entrySet()
|
||||
.iterator();
|
||||
Entry<String, List<String>> entry = null;
|
||||
List<String> names = null;
|
||||
while (iterator.hasNext()) {
|
||||
entry = iterator.next();
|
||||
names = entry.getValue();
|
||||
for (String name : names) {
|
||||
if (name.equalsIgnoreCase(searchName)) {
|
||||
counter++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static int labeledBreak() {
|
||||
String searchName = "Wilson";
|
||||
int counter = 0;
|
||||
Map<String, List<String>> nameMap = new HashMap<>();
|
||||
nameMap.put("Grade1", Arrays.asList("John", "Peter", "Robert", "Wilson"));
|
||||
nameMap.put("Grade2", Arrays.asList("Anthony", "Donald", "Richard", "Arnold"));
|
||||
nameMap.put("Grade3", Arrays.asList("Wilson", "Michael", "Stephen", "Ryan"));
|
||||
|
||||
Iterator<Entry<String, List<String>>> iterator = nameMap.entrySet()
|
||||
.iterator();
|
||||
Entry<String, List<String>> entry = null;
|
||||
List<String> names = null;
|
||||
compare:
|
||||
while (iterator.hasNext()) {
|
||||
entry = iterator.next();
|
||||
names = entry.getValue();
|
||||
for (String name : names) {
|
||||
if (name.equalsIgnoreCase(searchName)) {
|
||||
counter++;
|
||||
break compare;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static int unlabeledContinue() {
|
||||
String searchName = "Wilson";
|
||||
int counter = 0;
|
||||
Map<String, List<String>> nameMap = new HashMap<>();
|
||||
nameMap.put("Grade1", Arrays.asList("John", "Wilson", "Robert", "Wilson"));
|
||||
nameMap.put("Grade2", Arrays.asList("Anthony", "Donald", "Wilson", "Arnold"));
|
||||
nameMap.put("Grade3", Arrays.asList("Wilson", "Michael", "Wilson", "Ryan"));
|
||||
|
||||
Iterator<Entry<String, List<String>>> iterator = nameMap.entrySet()
|
||||
.iterator();
|
||||
Entry<String, List<String>> entry = null;
|
||||
List<String> names = null;
|
||||
while (iterator.hasNext()) {
|
||||
entry = iterator.next();
|
||||
names = entry.getValue();
|
||||
for (String name : names) {
|
||||
if (!name.equalsIgnoreCase(searchName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static int labeledContinue() {
|
||||
String searchName = "Wilson";
|
||||
int counter = 0;
|
||||
Map<String, List<String>> nameMap = new HashMap<>();
|
||||
nameMap.put("Grade1", Arrays.asList("John", "Wilson", "Robert", "Wilson"));
|
||||
nameMap.put("Grade2", Arrays.asList("Anthony", "Donald", "Wilson", "Arnold"));
|
||||
nameMap.put("Grade3", Arrays.asList("Wilson", "Michael", "Wilson", "Ryan"));
|
||||
|
||||
Iterator<Entry<String, List<String>>> iterator = nameMap.entrySet()
|
||||
.iterator();
|
||||
Entry<String, List<String>> entry = null;
|
||||
List<String> names = null;
|
||||
compare:
|
||||
while (iterator.hasNext()) {
|
||||
entry = iterator.next();
|
||||
names = entry.getValue();
|
||||
for (String name : names) {
|
||||
if (name.equalsIgnoreCase(searchName)) {
|
||||
counter++;
|
||||
continue compare;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.baeldung.breakcontinue;
|
||||
|
||||
import static com.baeldung.breakcontinue.BreakContinue.labeledBreak;
|
||||
import static com.baeldung.breakcontinue.BreakContinue.labeledContinue;
|
||||
import static com.baeldung.breakcontinue.BreakContinue.unlabeledBreak;
|
||||
import static com.baeldung.breakcontinue.BreakContinue.unlabeledBreakNestedLoops;
|
||||
import static com.baeldung.breakcontinue.BreakContinue.unlabeledContinue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BreakContinueTest {
|
||||
|
||||
@Test
|
||||
public void whenUnlabeledBreak_ThenEqual() {
|
||||
assertEquals(4, unlabeledBreak());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUnlabeledBreakNestedLoops_ThenEqual() {
|
||||
assertEquals(2, unlabeledBreakNestedLoops());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenLabeledBreak_ThenEqual() {
|
||||
assertEquals(1, labeledBreak());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUnlabeledContinue_ThenEqual() {
|
||||
assertEquals(5, unlabeledContinue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenLabeledContinue_ThenEqual() {
|
||||
assertEquals(3, labeledContinue());
|
||||
}
|
||||
|
||||
}
|
|
@ -15,5 +15,6 @@
|
|||
- [Data Classes in Kotlin](http://www.baeldung.com/kotlin-data-classes)
|
||||
- [Delegated Properties in Kotlin](http://www.baeldung.com/kotlin-delegated-properties)
|
||||
- [Sealed Classes in Kotlin](http://www.baeldung.com/kotlin-sealed-classes)
|
||||
- [JUnit 5 for Kotlin Developers](http://www.baeldung.com/junit-5-kotlin)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
## Building
|
||||
|
||||
To build the module, use Maven's `package` goal:
|
||||
|
||||
```
|
||||
mvn clean package
|
||||
```
|
||||
|
||||
## Running
|
||||
|
||||
To run the application, use Spring Boot's `run` goal:
|
||||
|
||||
```
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
The application will be accessible at [http://localhost:8080/](http://localhost:8080/)
|
|
@ -3,6 +3,7 @@ package com.baeldung.hibernate;
|
|||
import com.baeldung.hibernate.pojo.Employee;
|
||||
import com.baeldung.hibernate.pojo.EntityDescription;
|
||||
import com.baeldung.hibernate.pojo.Phone;
|
||||
import com.baeldung.hibernate.pojo.TemporalValues;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
|
@ -31,6 +32,7 @@ public class HibernateUtil {
|
|||
metadataSources.addAnnotatedClass(Employee.class);
|
||||
metadataSources.addAnnotatedClass(Phone.class);
|
||||
metadataSources.addAnnotatedClass(EntityDescription.class);
|
||||
metadataSources.addAnnotatedClass(TemporalValues.class);
|
||||
|
||||
Metadata metadata = metadataSources.buildMetadata();
|
||||
return metadata.getSessionFactoryBuilder()
|
||||
|
|
|
@ -0,0 +1,195 @@
|
|||
package com.baeldung.hibernate.pojo;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Date;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.*;
|
||||
import java.util.Calendar;
|
||||
|
||||
@Entity
|
||||
public class TemporalValues implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@Basic
|
||||
private java.sql.Date sqlDate;
|
||||
|
||||
@Basic
|
||||
private java.sql.Time sqlTime;
|
||||
|
||||
@Basic
|
||||
private java.sql.Timestamp sqlTimestamp;
|
||||
|
||||
@Basic
|
||||
@Temporal(TemporalType.DATE)
|
||||
private java.util.Date utilDate;
|
||||
|
||||
@Basic
|
||||
@Temporal(TemporalType.TIME)
|
||||
private java.util.Date utilTime;
|
||||
|
||||
@Basic
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private java.util.Date utilTimestamp;
|
||||
|
||||
@Basic
|
||||
@Temporal(TemporalType.DATE)
|
||||
private java.util.Calendar calendarDate;
|
||||
|
||||
@Basic
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private java.util.Calendar calendarTimestamp;
|
||||
|
||||
@Basic
|
||||
private java.time.LocalDate localDate;
|
||||
|
||||
@Basic
|
||||
private java.time.LocalTime localTime;
|
||||
|
||||
@Basic
|
||||
private java.time.OffsetTime offsetTime;
|
||||
|
||||
@Basic
|
||||
private java.time.Instant instant;
|
||||
|
||||
@Basic
|
||||
private java.time.LocalDateTime localDateTime;
|
||||
|
||||
@Basic
|
||||
private java.time.OffsetDateTime offsetDateTime;
|
||||
|
||||
@Basic
|
||||
private java.time.ZonedDateTime zonedDateTime;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getSqlDate() {
|
||||
return sqlDate;
|
||||
}
|
||||
|
||||
public void setSqlDate(Date sqlDate) {
|
||||
this.sqlDate = sqlDate;
|
||||
}
|
||||
|
||||
public Time getSqlTime() {
|
||||
return sqlTime;
|
||||
}
|
||||
|
||||
public void setSqlTime(Time sqlTime) {
|
||||
this.sqlTime = sqlTime;
|
||||
}
|
||||
|
||||
public Timestamp getSqlTimestamp() {
|
||||
return sqlTimestamp;
|
||||
}
|
||||
|
||||
public void setSqlTimestamp(Timestamp sqlTimestamp) {
|
||||
this.sqlTimestamp = sqlTimestamp;
|
||||
}
|
||||
|
||||
public java.util.Date getUtilDate() {
|
||||
return utilDate;
|
||||
}
|
||||
|
||||
public void setUtilDate(java.util.Date utilDate) {
|
||||
this.utilDate = utilDate;
|
||||
}
|
||||
|
||||
public java.util.Date getUtilTime() {
|
||||
return utilTime;
|
||||
}
|
||||
|
||||
public void setUtilTime(java.util.Date utilTime) {
|
||||
this.utilTime = utilTime;
|
||||
}
|
||||
|
||||
public java.util.Date getUtilTimestamp() {
|
||||
return utilTimestamp;
|
||||
}
|
||||
|
||||
public void setUtilTimestamp(java.util.Date utilTimestamp) {
|
||||
this.utilTimestamp = utilTimestamp;
|
||||
}
|
||||
|
||||
public Calendar getCalendarDate() {
|
||||
return calendarDate;
|
||||
}
|
||||
|
||||
public void setCalendarDate(Calendar calendarDate) {
|
||||
this.calendarDate = calendarDate;
|
||||
}
|
||||
|
||||
public Calendar getCalendarTimestamp() {
|
||||
return calendarTimestamp;
|
||||
}
|
||||
|
||||
public void setCalendarTimestamp(Calendar calendarTimestamp) {
|
||||
this.calendarTimestamp = calendarTimestamp;
|
||||
}
|
||||
|
||||
public LocalDate getLocalDate() {
|
||||
return localDate;
|
||||
}
|
||||
|
||||
public void setLocalDate(LocalDate localDate) {
|
||||
this.localDate = localDate;
|
||||
}
|
||||
|
||||
public LocalTime getLocalTime() {
|
||||
return localTime;
|
||||
}
|
||||
|
||||
public void setLocalTime(LocalTime localTime) {
|
||||
this.localTime = localTime;
|
||||
}
|
||||
|
||||
public OffsetTime getOffsetTime() {
|
||||
return offsetTime;
|
||||
}
|
||||
|
||||
public void setOffsetTime(OffsetTime offsetTime) {
|
||||
this.offsetTime = offsetTime;
|
||||
}
|
||||
|
||||
public Instant getInstant() {
|
||||
return instant;
|
||||
}
|
||||
|
||||
public void setInstant(Instant instant) {
|
||||
this.instant = instant;
|
||||
}
|
||||
|
||||
public LocalDateTime getLocalDateTime() {
|
||||
return localDateTime;
|
||||
}
|
||||
|
||||
public void setLocalDateTime(LocalDateTime localDateTime) {
|
||||
this.localDateTime = localDateTime;
|
||||
}
|
||||
|
||||
public OffsetDateTime getOffsetDateTime() {
|
||||
return offsetDateTime;
|
||||
}
|
||||
|
||||
public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
|
||||
this.offsetDateTime = offsetDateTime;
|
||||
}
|
||||
|
||||
public ZonedDateTime getZonedDateTime() {
|
||||
return zonedDateTime;
|
||||
}
|
||||
|
||||
public void setZonedDateTime(ZonedDateTime zonedDateTime) {
|
||||
this.zonedDateTime = zonedDateTime;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package com.baeldung.hibernate;
|
||||
|
||||
import com.baeldung.hibernate.pojo.TemporalValues;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TemporalValuesTest {
|
||||
|
||||
private Session session;
|
||||
|
||||
private Transaction transaction;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
session = HibernateUtil.getSessionFactory().withOptions()
|
||||
.jdbcTimeZone(TimeZone.getTimeZone("UTC"))
|
||||
.openSession();
|
||||
transaction = session.beginTransaction();
|
||||
session.createNativeQuery("delete from temporalvalues").executeUpdate();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
transaction.rollback();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntity_whenMappingSqlTypes_thenTemporalIsSelectedAutomatically() {
|
||||
TemporalValues temporalValues = new TemporalValues();
|
||||
temporalValues.setSqlDate(java.sql.Date.valueOf("2017-11-15"));
|
||||
temporalValues.setSqlTime(java.sql.Time.valueOf("15:30:14"));
|
||||
temporalValues.setSqlTimestamp(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332"));
|
||||
|
||||
session.save(temporalValues);
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
temporalValues = session.get(TemporalValues.class, temporalValues.getId());
|
||||
assertThat(temporalValues.getSqlDate()).isEqualTo(java.sql.Date.valueOf("2017-11-15"));
|
||||
assertThat(temporalValues.getSqlTime()).isEqualTo(java.sql.Time.valueOf("15:30:14"));
|
||||
assertThat(temporalValues.getSqlTimestamp()).isEqualTo(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntity_whenMappingUtilDateType_thenTemporalIsSpecifiedExplicitly() throws Exception {
|
||||
TemporalValues temporalValues = new TemporalValues();
|
||||
temporalValues.setUtilDate(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15"));
|
||||
temporalValues.setUtilTime(new SimpleDateFormat("HH:mm:ss").parse("15:30:14"));
|
||||
temporalValues.setUtilTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.332"));
|
||||
|
||||
session.save(temporalValues);
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
temporalValues = session.get(TemporalValues.class, temporalValues.getId());
|
||||
assertThat(temporalValues.getUtilDate()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15"));
|
||||
assertThat(temporalValues.getUtilTime()).isEqualTo(new SimpleDateFormat("HH:mm:ss").parse("15:30:14"));
|
||||
assertThat(temporalValues.getUtilTimestamp()).isEqualTo(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntity_whenMappingCalendarType_thenTemporalIsSpecifiedExplicitly() throws Exception {
|
||||
TemporalValues temporalValues = new TemporalValues();
|
||||
|
||||
Calendar calendarDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
calendarDate.set(Calendar.YEAR, 2017);
|
||||
calendarDate.set(Calendar.MONTH, 10);
|
||||
calendarDate.set(Calendar.DAY_OF_MONTH, 15);
|
||||
temporalValues.setCalendarDate(calendarDate);
|
||||
|
||||
Calendar calendarTimestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
calendarTimestamp.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.322"));
|
||||
temporalValues.setCalendarTimestamp(calendarTimestamp);
|
||||
|
||||
session.save(temporalValues);
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
temporalValues = session.get(TemporalValues.class, temporalValues.getId());
|
||||
assertThat(temporalValues.getCalendarDate().getTime()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15"));
|
||||
assertThat(temporalValues.getCalendarTimestamp().getTime()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.322"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntity_whenMappingJavaTimeTypes_thenTemporalIsSelectedAutomatically() {
|
||||
TemporalValues temporalValues = new TemporalValues();
|
||||
|
||||
temporalValues.setLocalDate(LocalDate.parse("2017-11-15"));
|
||||
temporalValues.setLocalTime(LocalTime.parse("15:30:18"));
|
||||
temporalValues.setOffsetTime(OffsetTime.parse("08:22:12+01:00"));
|
||||
temporalValues.setInstant(Instant.parse("2017-11-15T08:22:12Z"));
|
||||
temporalValues.setLocalDateTime(LocalDateTime.parse("2017-11-15T08:22:12"));
|
||||
temporalValues.setOffsetDateTime(OffsetDateTime.parse("2017-11-15T08:22:12+01:00"));
|
||||
temporalValues.setZonedDateTime(ZonedDateTime.parse("2017-11-15T08:22:12+01:00[Europe/Paris]"));
|
||||
|
||||
session.save(temporalValues);
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
temporalValues = session.get(TemporalValues.class, temporalValues.getId());
|
||||
assertThat(temporalValues.getLocalDate()).isEqualTo(LocalDate.parse("2017-11-15"));
|
||||
assertThat(temporalValues.getLocalTime()).isEqualTo(LocalTime.parse("15:30:18"));
|
||||
assertThat(temporalValues.getOffsetTime()).isEqualTo(OffsetTime.parse("08:22:12+01:00"));
|
||||
assertThat(temporalValues.getInstant()).isEqualTo(Instant.parse("2017-11-15T08:22:12Z"));
|
||||
assertThat(temporalValues.getLocalDateTime()).isEqualTo(LocalDateTime.parse("2017-11-15T08:22:12"));
|
||||
assertThat(temporalValues.getOffsetDateTime()).isEqualTo(OffsetDateTime.parse("2017-11-15T08:22:12+01:00"));
|
||||
assertThat(temporalValues.getZonedDateTime()).isEqualTo(ZonedDateTime.parse("2017-11-15T08:22:12+01:00[Europe/Paris]"));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,7 @@
|
|||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
<junit4.version>4.12</junit4.version>
|
||||
<spring.version>5.0.1.RELEASE</spring.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -111,6 +112,17 @@
|
|||
<version>${junit4.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.junit5.spring;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.baeldung.junit5.Greetings;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { SpringTestConfiguration.class })
|
||||
public class GreetingsSpringTest {
|
||||
|
||||
@Test
|
||||
void whenCallingSayHello_thenReturnHello() {
|
||||
assertTrue("Hello".equals(Greetings.sayHello()));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.junit5.spring;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SpringTestConfiguration {
|
||||
|
||||
}
|
|
@ -51,7 +51,6 @@ public class MemberStatusIntegrationTest {
|
|||
|
||||
/**
|
||||
* This test should fail, comment out <code>@Ignore</code> to see how failed test can be reflected in Serenity report. <br/>
|
||||
* Remember to add <code><testFailureIgnore>true</testFailureIgnore></code> under maven-surefire-plugin configuration.
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
|
|
|
@ -26,12 +26,6 @@
|
|||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>apache-log4j-extras</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--log4j2 dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
|
|
|
@ -85,7 +85,6 @@
|
|||
<exclude>**/JdbcTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<exclude>**/JdbcTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -65,7 +65,6 @@
|
|||
<exclude>**/*EntryPointsTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -149,6 +149,7 @@
|
|||
<module>spring-batch</module>
|
||||
<module>spring-bom</module>
|
||||
<module>spring-boot</module>
|
||||
<module>spring-boot-keycloak</module>
|
||||
<module>spring-boot-bootstrap</module>
|
||||
<module>spring-cloud-data-flow</module>
|
||||
<module>spring-cloud</module>
|
||||
|
@ -230,6 +231,8 @@
|
|||
<module>spring-zuul</module>
|
||||
<module>spring-reactor</module>
|
||||
<module>spring-vertx</module>
|
||||
|
||||
<module>spring-rest-embedded-tomcat</module>
|
||||
|
||||
|
||||
<module>testing</module>
|
||||
|
@ -339,7 +342,7 @@
|
|||
<exclude>**/JdbcTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
<includes>
|
||||
<include>**/*LiveTest.java</include>
|
||||
</includes>
|
||||
<testFailureIgnore>false</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
|
|
@ -152,7 +152,7 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
|
||||
<failIfNoTests>false</failIfNoTests>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
|
|
|
@ -19,9 +19,11 @@
|
|||
</parent>
|
||||
|
||||
<properties>
|
||||
<start-class>com.example.activitiwithspring.ActivitiWithSpringApplication</start-class>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<activiti.version>6.0.0</activiti.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -30,9 +32,14 @@
|
|||
<artifactId>activiti-spring-boot-starter-basic</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.activiti</groupId>
|
||||
<artifactId>activiti-spring-boot-starter-security</artifactId>
|
||||
<version>${activiti.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -67,7 +74,7 @@
|
|||
<exclude>**/JdbcTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.activiti.security.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
public class MvcConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/login")
|
||||
.setViewName("login");
|
||||
registry.addViewController("/homepage")
|
||||
.setViewName("homepage");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.baeldung.activiti.security.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.activiti.engine.IdentityService;
|
||||
import org.activiti.engine.RuntimeService;
|
||||
import org.activiti.engine.TaskService;
|
||||
import org.activiti.engine.runtime.ProcessInstance;
|
||||
import org.activiti.engine.task.Task;
|
||||
import org.activiti.spring.SpringProcessEngineConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class ProcessController {
|
||||
|
||||
@Autowired
|
||||
private RuntimeService runtimeService;
|
||||
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
private IdentityService identityService;
|
||||
|
||||
@Autowired
|
||||
SpringProcessEngineConfiguration config;
|
||||
|
||||
@GetMapping("/protected-process")
|
||||
public String startProcess() {
|
||||
|
||||
String userId = SecurityContextHolder.getContext()
|
||||
.getAuthentication()
|
||||
.getName();
|
||||
|
||||
identityService.setAuthenticatedUserId(userId);
|
||||
|
||||
ProcessInstance pi = runtimeService.startProcessInstanceByKey("protected-process");
|
||||
|
||||
List<Task> usertasks = taskService.createTaskQuery()
|
||||
.processInstanceId(pi.getId())
|
||||
.list();
|
||||
|
||||
taskService.complete(usertasks.iterator()
|
||||
.next()
|
||||
.getId());
|
||||
|
||||
return "Process started. Number of currently running process instances = " + runtimeService.createProcessInstanceQuery()
|
||||
.count();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.baeldung.activiti.security.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.activiti.engine.identity.Group;
|
||||
import org.activiti.engine.identity.GroupQuery;
|
||||
import org.activiti.engine.impl.GroupQueryImpl;
|
||||
import org.activiti.engine.impl.Page;
|
||||
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.GroupEntityImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.GroupEntityManagerImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.data.GroupDataManager;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.provisioning.JdbcUserDetailsManager;
|
||||
|
||||
public class SpringSecurityGroupManager extends GroupEntityManagerImpl {
|
||||
|
||||
private JdbcUserDetailsManager userManager;
|
||||
|
||||
public SpringSecurityGroupManager(ProcessEngineConfigurationImpl processEngineConfiguration, GroupDataManager groupDataManager) {
|
||||
super(processEngineConfiguration, groupDataManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Group> findGroupByQueryCriteria(GroupQueryImpl query, Page page) {
|
||||
|
||||
if (query.getUserId() != null) {
|
||||
return findGroupsByUser(query.getUserId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long findGroupCountByQueryCriteria(GroupQueryImpl query) {
|
||||
return findGroupByQueryCriteria(query, null).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Group> findGroupsByUser(String userId) {
|
||||
UserDetails userDetails = userManager.loadUserByUsername(userId);
|
||||
System.out.println("group manager");
|
||||
if (userDetails != null) {
|
||||
List<Group> groups = userDetails.getAuthorities()
|
||||
.stream()
|
||||
.map(a -> a.getAuthority())
|
||||
.map(a -> {
|
||||
Group g = new GroupEntityImpl();
|
||||
g.setId(a);
|
||||
return g;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return groups;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setUserManager(JdbcUserDetailsManager userManager) {
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
public Group createNewGroup(String groupId) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String groupId) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
|
||||
}
|
||||
|
||||
public GroupQuery createNewGroupQuery() {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
}
|
||||
|
||||
public List<Group> findGroupsByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
}
|
||||
|
||||
public long findGroupCountByNativeQuery(Map<String, Object> parameterMap) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
package com.baeldung.activiti.security.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.activiti.engine.identity.Group;
|
||||
import org.activiti.engine.identity.User;
|
||||
import org.activiti.engine.identity.UserQuery;
|
||||
import org.activiti.engine.impl.Page;
|
||||
import org.activiti.engine.impl.UserQueryImpl;
|
||||
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.GroupEntityImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.UserEntity;
|
||||
import org.activiti.engine.impl.persistence.entity.UserEntityImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.UserEntityManagerImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.data.UserDataManager;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.provisioning.JdbcUserDetailsManager;
|
||||
|
||||
public class SpringSecurityUserManager extends UserEntityManagerImpl {
|
||||
|
||||
private JdbcUserDetailsManager userManager;
|
||||
|
||||
public SpringSecurityUserManager(ProcessEngineConfigurationImpl processEngineConfiguration, UserDataManager userDataManager, JdbcUserDetailsManager userManager) {
|
||||
super(processEngineConfiguration, userDataManager);
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserEntity findById(String userId) {
|
||||
UserDetails userDetails = userManager.loadUserByUsername(userId);
|
||||
if (userDetails != null) {
|
||||
UserEntityImpl user = new UserEntityImpl();
|
||||
user.setId(userId);
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findUserByQueryCriteria(UserQueryImpl query, Page page) {
|
||||
List<User> users = null;
|
||||
if (query.getGroupId() != null) {
|
||||
users = userManager.findUsersInGroup(query.getGroupId())
|
||||
.stream()
|
||||
.map(username -> {
|
||||
User user = new UserEntityImpl();
|
||||
user.setId(username);
|
||||
return user;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
if (page != null) {
|
||||
return users.subList(page.getFirstResult(), page.getFirstResult() + page.getMaxResults());
|
||||
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
if (query.getId() != null) {
|
||||
UserDetails userDetails = userManager.loadUserByUsername(query.getId());
|
||||
if (userDetails != null) {
|
||||
UserEntityImpl user = new UserEntityImpl();
|
||||
user.setId(query.getId());
|
||||
return Collections.singletonList(user);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkPassword(String userId, String password) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setUserManager(JdbcUserDetailsManager userManager) {
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
public User createNewUser(String userId) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
}
|
||||
|
||||
public void updateUser(User updatedUser) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
|
||||
}
|
||||
|
||||
public void delete(UserEntity userEntity) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePicture(User user) {
|
||||
UserEntity userEntity = (UserEntity) user;
|
||||
if (userEntity.getPictureByteArrayRef() != null) {
|
||||
userEntity.getPictureByteArrayRef()
|
||||
.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String userId) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
|
||||
}
|
||||
|
||||
public long findUserCountByQueryCriteria(UserQueryImpl query) {
|
||||
return findUserByQueryCriteria(query, null).size();
|
||||
}
|
||||
|
||||
public List<Group> findGroupsByUser(String userId) {
|
||||
UserDetails userDetails = userManager.loadUserByUsername(userId);
|
||||
if (userDetails != null) {
|
||||
List<Group> groups = userDetails.getAuthorities()
|
||||
.stream()
|
||||
.map(a -> a.getAuthority())
|
||||
.map(a -> {
|
||||
Group g = new GroupEntityImpl();
|
||||
g.setId(a);
|
||||
return g;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return groups;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserQuery createNewUserQuery() {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
}
|
||||
|
||||
public List<User> findUsersByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
}
|
||||
|
||||
public long findUserCountByNativeQuery(Map<String, Object> parameterMap) {
|
||||
throw new UnsupportedOperationException("This operation is not supported!");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.baeldung.activiti.security.withactiviti;
|
||||
|
||||
import org.activiti.engine.IdentityService;
|
||||
import org.activiti.spring.security.IdentityServiceUserDetailsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.antMatcher("/**")
|
||||
.authorizeRequests()
|
||||
.antMatchers("/protected-process*")
|
||||
.authenticated()
|
||||
.anyRequest()
|
||||
.permitAll()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/login")
|
||||
.defaultSuccessUrl("/homepage")
|
||||
.failureUrl("/login?error=true")
|
||||
.and()
|
||||
.csrf()
|
||||
.disable()
|
||||
.logout()
|
||||
.logoutSuccessUrl("/login");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private IdentityService identityService;
|
||||
|
||||
@Bean
|
||||
public IdentityServiceUserDetailsService userDetailsService() {
|
||||
return new IdentityServiceUserDetailsService(identityService);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.userDetailsService(userDetailsService());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.baeldung.activiti.security.withactiviti;
|
||||
|
||||
import org.activiti.engine.IdentityService;
|
||||
import org.activiti.engine.identity.Group;
|
||||
import org.activiti.engine.identity.User;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = { "com.baeldung.activiti.security.config", "com.baeldung.activiti.security.withactiviti" })
|
||||
public class SpringSecurityActivitiApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringSecurityActivitiApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
InitializingBean usersAndGroupsInitializer(IdentityService identityService) {
|
||||
return new InitializingBean() {
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
User user = identityService.newUser("activiti_user");
|
||||
user.setPassword("pass");
|
||||
identityService.saveUser(user);
|
||||
|
||||
Group group = identityService.newGroup("user");
|
||||
group.setName("ROLE_USER");
|
||||
group.setType("USER");
|
||||
identityService.saveGroup(group);
|
||||
identityService.createMembership(user.getId(), group.getId());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.baeldung.activiti.security.withspring;
|
||||
|
||||
import org.activiti.engine.impl.persistence.entity.data.impl.MybatisGroupDataManager;
|
||||
import org.activiti.engine.impl.persistence.entity.data.impl.MybatisUserDataManager;
|
||||
import org.activiti.spring.SpringProcessEngineConfiguration;
|
||||
import org.activiti.spring.boot.SecurityAutoConfiguration;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.provisioning.JdbcUserDetailsManager;
|
||||
|
||||
import com.baeldung.activiti.security.config.SpringSecurityGroupManager;
|
||||
import com.baeldung.activiti.security.config.SpringSecurityUserManager;
|
||||
|
||||
@SpringBootApplication(exclude = SecurityAutoConfiguration.class, scanBasePackages = { "com.baeldung.activiti.security.config", "com.baeldung.activiti.security.withspring" })
|
||||
public class ActivitiSpringSecurityApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ActivitiSpringSecurityApplication.class, args);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SpringProcessEngineConfiguration processEngineConfiguration;
|
||||
|
||||
@Autowired
|
||||
private JdbcUserDetailsManager userManager;
|
||||
|
||||
@Bean
|
||||
InitializingBean processEngineInitializer() {
|
||||
return new InitializingBean() {
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
processEngineConfiguration.setUserEntityManager(new SpringSecurityUserManager(processEngineConfiguration, new MybatisUserDataManager(processEngineConfiguration), userManager));
|
||||
processEngineConfiguration.setGroupEntityManager(new SpringSecurityGroupManager(processEngineConfiguration, new MybatisGroupDataManager(processEngineConfiguration)));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.baeldung.activiti.security.withspring;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.provisioning.JdbcUserDetailsManager;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.antMatcher("/**")
|
||||
.authorizeRequests()
|
||||
.antMatchers("/protected-process*")
|
||||
.authenticated()
|
||||
.anyRequest()
|
||||
.permitAll()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/login")
|
||||
.defaultSuccessUrl("/homepage")
|
||||
.failureUrl("/login?error=true")
|
||||
.and()
|
||||
.csrf()
|
||||
.disable()
|
||||
.logout()
|
||||
.logoutSuccessUrl("/login");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JdbcUserDetailsManager userDetailsManager() {
|
||||
JdbcUserDetailsManager manager = new JdbcUserDetailsManager();
|
||||
manager.setDataSource(dataSource);
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.userDetailsService(userDetailsManager());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
insert into users(username, password, enabled) values ('spring_user', 'pass', true);
|
||||
|
||||
insert into authorities(username, authority) values ('spring_user','ROLE_USER');
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef" xmlns:modeler="http://activiti.com/modeler" modeler:version="1.0ev" modeler:exportDateTime="20170726123124" modeler:modelId="1005315" modeler:modelVersion="1" modeler:modelLastUpdated="1501068675875">
|
||||
<process id="protected-process" name="protected-process" isExecutable="true">
|
||||
<startEvent id="startEvent" name="startEvent">
|
||||
</startEvent>
|
||||
<sequenceFlow id="sequence-flow-1" sourceRef="startEvent" targetRef="A">
|
||||
</sequenceFlow>
|
||||
<userTask id="A" name="A">
|
||||
<potentialOwner>
|
||||
<resourceAssignmentExpression>
|
||||
<formalExpression>ROLE_USER</formalExpression>
|
||||
</resourceAssignmentExpression>
|
||||
</potentialOwner>
|
||||
</userTask>
|
||||
<sequenceFlow id="sequence-flow-2" sourceRef="A" targetRef="endEvent">
|
||||
</sequenceFlow>
|
||||
<endEvent id="endEvent" name="endEvent">
|
||||
</endEvent>
|
||||
</process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_protected-process">
|
||||
<bpmndi:BPMNPlane bpmnElement="protected-process" id="BPMNPlane_protected-process">
|
||||
<bpmndi:BPMNShape bpmnElement="startEvent" id="BPMNShape_startEvent">
|
||||
<omgdc:Bounds height="30.0" width="30.0" x="120.0" y="163.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="endEvent" id="BPMNShape_endEvent">
|
||||
<omgdc:Bounds height="28.0" width="28.0" x="365.0" y="164.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="A" id="BPMNShape_A">
|
||||
<omgdc:Bounds height="80.0" width="100.0" x="210.0" y="138.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge bpmnElement="sequence-flow-1" id="BPMNEdge_sequence-flow-1">
|
||||
<omgdi:waypoint x="150.0" y="178.0"/>
|
||||
<omgdi:waypoint x="210.0" y="178.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="sequence-flow-2" id="BPMNEdge_sequence-flow-2">
|
||||
<omgdi:waypoint x="310.0" y="178.0"/>
|
||||
<omgdi:waypoint x="365.0" y="178.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</definitions>
|
|
@ -0,0 +1,3 @@
|
|||
create table users(username varchar(255), password varchar(255), enabled boolean);
|
||||
|
||||
create table authorities(username varchar(255),authority varchar(255));
|
|
@ -0,0 +1,21 @@
|
|||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<h1>Login</h1>
|
||||
<form name='f' action="login" method='POST'>
|
||||
<table>
|
||||
<tr>
|
||||
<td>User:</td>
|
||||
<td><input type='text' name='username' value=''/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password:</td>
|
||||
<td><input type='password' name='password' /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input name="submit" type="submit" value="submit" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,31 @@
|
|||
package com.example.activitiwithspring;
|
||||
|
||||
import org.activiti.engine.IdentityService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import com.baeldung.activiti.security.withspring.ActivitiSpringSecurityApplication;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ActivitiSpringSecurityApplication.class)
|
||||
@WebAppConfiguration
|
||||
public class ActivitiSpringSecurityIntegrationTest {
|
||||
@Autowired
|
||||
private IdentityService identityService;
|
||||
|
||||
@Test
|
||||
public void whenUserExists_thenOk() {
|
||||
identityService.setUserPicture("spring_user", null);
|
||||
}
|
||||
|
||||
@Test(expected = UsernameNotFoundException.class)
|
||||
public void whenUserNonExistent_thenSpringException() {
|
||||
identityService.setUserPicture("user3", null);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,10 +16,10 @@ import java.time.Month;
|
|||
@EnableAspectJAutoProxy
|
||||
public class AopConfiguration {
|
||||
|
||||
@Pointcut("execution(public String com.baeldung.performancemonitor.PersonService.getFullName(..))")
|
||||
@Pointcut("execution(public String org.baeldung.performancemonitor.PersonService.getFullName(..))")
|
||||
public void monitor() { }
|
||||
|
||||
@Pointcut("execution(public int com.baeldung.performancemonitor.PersonService.getAge(..))")
|
||||
@Pointcut("execution(public int org.baeldung.performancemonitor.PersonService.getAge(..))")
|
||||
public void myMonitor() { }
|
||||
|
||||
@Bean
|
||||
|
@ -30,7 +30,7 @@ public class AopConfiguration {
|
|||
@Bean
|
||||
public Advisor performanceMonitorAdvisor() {
|
||||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
||||
pointcut.setExpression("com.baeldung.performancemonitor.AopConfiguration.monitor()");
|
||||
pointcut.setExpression("org.baeldung.performancemonitor.AopConfiguration.monitor()");
|
||||
return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor());
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class AopConfiguration {
|
|||
@Bean
|
||||
public Advisor myPerformanceMonitorAdvisor() {
|
||||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
||||
pointcut.setExpression("com.baeldung.performancemonitor.AopConfiguration.myMonitor()");
|
||||
pointcut.setExpression("org.baeldung.performancemonitor.AopConfiguration.myMonitor()");
|
||||
return new DefaultPointcutAdvisor(pointcut, myPerformanceMonitorInterceptor());
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.boot.version>1.5.8.RELEASE</spring.boot.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
|
@ -20,4 +21,16 @@
|
|||
<module>spring-boot-admin-client</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
|
@ -11,10 +11,10 @@
|
|||
<description>Spring Boot Admin Client</description>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-5</artifactId>
|
||||
<artifactId>spring-boot-admin</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-5</relativePath>
|
||||
<relativePath>../../spring-boot-admin</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
<description>Spring Boot Admin Server</description>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-5</artifactId>
|
||||
<artifactId>spring-boot-admin</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-5</relativePath>
|
||||
<relativePath>../../spring-boot-admin</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -12,10 +12,12 @@
|
|||
<description>This is a simple application demonstrating integration between Keycloak and Spring Boot.</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.5.8.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-4</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-4</relativePath>
|
||||
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -27,4 +27,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [A Java Client for a WebSockets API](http://www.baeldung.com/websockets-api-java-spring-client)
|
||||
- [Spring Boot and Togglz Aspect](http://www.baeldung.com/spring-togglz)
|
||||
- [Getting Started with GraphQL and Spring Boot](http://www.baeldung.com/spring-graphql)
|
||||
- [Guide to Spring Type Conversions](http://www.baeldung.com/spring-type-conversions)
|
||||
|
||||
|
|
|
@ -24,10 +24,6 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
|
@ -172,17 +168,6 @@
|
|||
<artifactId>artemis-server</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.keycloak.bom</groupId>
|
||||
<artifactId>keycloak-adapter-bom</artifactId>
|
||||
<version>3.3.0.CR2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<finalName>spring-boot</finalName>
|
||||
|
@ -282,7 +267,7 @@
|
|||
|
||||
<properties>
|
||||
<!-- The main class to start by executing java -jar -->
|
||||
<start-class>org.baeldung.boot.DemoApplication</start-class>
|
||||
<start-class>org.baeldung.demo.DemoApplication</start-class>
|
||||
<spring.version>4.3.4.RELEASE</spring.version>
|
||||
<git-commit-id-plugin.version>2.2.1</git-commit-id-plugin.version>
|
||||
<jquery.version>3.1.1</jquery.version>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package org.baeldung.boot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.client;
|
||||
package org.baeldung.boot.client;
|
||||
|
||||
public class Details {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.client;
|
||||
package org.baeldung.boot.client;
|
||||
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.stereotype.Service;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.config;
|
||||
package org.baeldung.boot.config;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -18,7 +18,7 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
|||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories(basePackages = { "org.baeldung.repository", "org.baeldung.boot.repository", "org.baeldung.boot.boottest" })
|
||||
@EnableJpaRepositories(basePackages = { "org.baeldung.boot.repository", "org.baeldung.boot.boottest","org.baeldung.repository" })
|
||||
@PropertySource("classpath:persistence-generic-entity.properties")
|
||||
@EnableTransactionManagement
|
||||
public class H2JpaConfig {
|
||||
|
@ -41,7 +41,7 @@ public class H2JpaConfig {
|
|||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||
em.setDataSource(dataSource());
|
||||
em.setPackagesToScan(new String[] { "org.baeldung.domain", "org.baeldung.boot.model", "org.baeldung.boot.boottest" });
|
||||
em.setPackagesToScan(new String[] { "org.baeldung.boot.domain", "org.baeldung.boot.model", "org.baeldung.boot.boottest", "org.baeldung.model" });
|
||||
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
|
||||
em.setJpaProperties(additionalProperties());
|
||||
return em;
|
|
@ -1,9 +1,9 @@
|
|||
package org.baeldung.config;
|
||||
package org.baeldung.boot.config;
|
||||
|
||||
import org.baeldung.converter.GenericBigDecimalConverter;
|
||||
import org.baeldung.converter.StringToEnumConverterFactory;
|
||||
import org.baeldung.converter.StringToEmployeeConverter;
|
||||
import org.baeldung.web.resolver.HeaderVersionArgumentResolver;
|
||||
import org.baeldung.boot.converter.GenericBigDecimalConverter;
|
||||
import org.baeldung.boot.converter.StringToEmployeeConverter;
|
||||
import org.baeldung.boot.converter.StringToEnumConverterFactory;
|
||||
import org.baeldung.boot.web.resolver.HeaderVersionArgumentResolver;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.controller;
|
||||
package org.baeldung.boot.controller;
|
||||
|
||||
import org.baeldung.domain.GenericEntity;
|
||||
import org.baeldung.domain.Modes;
|
||||
import org.baeldung.web.resolver.Version;
|
||||
import org.baeldung.boot.domain.GenericEntity;
|
||||
import org.baeldung.boot.domain.Modes;
|
||||
import org.baeldung.boot.web.resolver.Version;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
@ -1,43 +1,43 @@
|
|||
package org.baeldung.controller.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class HelloWorldServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public HelloWorldServlet() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("HelloWorldServlet: GET METHOD");
|
||||
out.flush();
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("HelloWorldServlet: POST METHOD");
|
||||
out.flush();
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.baeldung.boot.controller.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class HelloWorldServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public HelloWorldServlet() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("HelloWorldServlet: GET METHOD");
|
||||
out.flush();
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("HelloWorldServlet: POST METHOD");
|
||||
out.flush();
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +1,43 @@
|
|||
package org.baeldung.controller.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class SpringHelloWorldServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SpringHelloWorldServlet() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("SpringHelloWorldServlet: GET METHOD");
|
||||
out.flush();
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("SpringHelloWorldServlet: POST METHOD");
|
||||
out.flush();
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.baeldung.boot.controller.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class SpringHelloWorldServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SpringHelloWorldServlet() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("SpringHelloWorldServlet: GET METHOD");
|
||||
out.flush();
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("SpringHelloWorldServlet: POST METHOD");
|
||||
out.flush();
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.converter;
|
||||
package org.baeldung.boot.converter;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.converter;
|
||||
package org.baeldung.boot.converter;
|
||||
|
||||
|
||||
import com.baeldung.toggle.Employee;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.converter;
|
||||
package org.baeldung.boot.converter;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.converter;
|
||||
package org.baeldung.boot.converter;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
|
@ -0,0 +1,16 @@
|
|||
package org.baeldung.boot.converter.controller;
|
||||
|
||||
import com.baeldung.toggle.Employee;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/string-to-employee")
|
||||
public class StringToEmployeeConverterController {
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> getStringToEmployee(@RequestParam("employee") Employee employee) {
|
||||
return ResponseEntity.ok(employee);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.domain;
|
||||
package org.baeldung.boot.domain;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.domain;
|
||||
package org.baeldung.boot.domain;
|
||||
|
||||
public enum Modes {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.jsoncomponent;
|
||||
package org.baeldung.boot.jsoncomponent;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.jsoncomponent;
|
||||
package org.baeldung.boot.jsoncomponent;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.jsoncomponent;
|
||||
package org.baeldung.boot.jsoncomponent;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.jsoncomponent;
|
||||
package org.baeldung.boot.jsoncomponent;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
@ -1,22 +1,22 @@
|
|||
package org.baeldung.monitor.jmx;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.codahale.metrics.JmxReporter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
|
||||
@Configuration
|
||||
public class MonitoringConfig {
|
||||
@Autowired
|
||||
private MetricRegistry registry;
|
||||
|
||||
@Bean
|
||||
public JmxReporter jmxReporter() {
|
||||
JmxReporter reporter = JmxReporter.forRegistry(registry)
|
||||
.build();
|
||||
reporter.start();
|
||||
return reporter;
|
||||
}
|
||||
}
|
||||
package org.baeldung.boot.monitor.jmx;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.codahale.metrics.JmxReporter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
|
||||
@Configuration
|
||||
public class MonitoringConfig {
|
||||
@Autowired
|
||||
private MetricRegistry registry;
|
||||
|
||||
@Bean
|
||||
public JmxReporter jmxReporter() {
|
||||
JmxReporter reporter = JmxReporter.forRegistry(registry)
|
||||
.build();
|
||||
reporter.start();
|
||||
return reporter;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.repository;
|
||||
package org.baeldung.boot.repository;
|
||||
|
||||
import org.baeldung.domain.GenericEntity;
|
||||
import org.baeldung.boot.domain.GenericEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface GenericEntityRepository extends JpaRepository<GenericEntity, Long> {
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.web.resolver;
|
||||
package org.baeldung.boot.web.resolver;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.stereotype.Component;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.web.resolver;
|
||||
package org.baeldung.boot.web.resolver;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot;
|
||||
package org.baeldung.demo;
|
||||
|
||||
import com.baeldung.graphql.GraphqlConfiguration;
|
||||
import org.springframework.boot.SpringApplication;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.boottest;
|
||||
package org.baeldung.demo.boottest;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.boottest;
|
||||
package org.baeldung.demo.boottest;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.boottest;
|
||||
package org.baeldung.demo.boottest;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.boottest;
|
||||
package org.baeldung.demo.boottest;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.boottest;
|
||||
package org.baeldung.demo.boottest;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package org.baeldung.boot.components;
|
||||
package org.baeldung.demo.components;
|
||||
|
||||
import org.baeldung.boot.model.Foo;
|
||||
import org.baeldung.boot.repository.FooRepository;
|
||||
import org.baeldung.demo.model.Foo;
|
||||
import org.baeldung.demo.repository.FooRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.exceptions;
|
||||
package org.baeldung.demo.exceptions;
|
||||
|
||||
public class CommonException extends RuntimeException {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.exceptions;
|
||||
package org.baeldung.demo.exceptions;
|
||||
|
||||
public class FooNotFoundException extends RuntimeException {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.model;
|
||||
package org.baeldung.demo.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.boot.repository;
|
||||
package org.baeldung.demo.repository;
|
||||
|
||||
import org.baeldung.boot.model.Foo;
|
||||
import org.baeldung.demo.model.Foo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface FooRepository extends JpaRepository<Foo, Integer> {
|
|
@ -1,7 +1,7 @@
|
|||
package org.baeldung.boot.service;
|
||||
package org.baeldung.demo.service;
|
||||
|
||||
import org.baeldung.boot.components.FooService;
|
||||
import org.baeldung.boot.model.Foo;
|
||||
import org.baeldung.demo.components.FooService;
|
||||
import org.baeldung.demo.model.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
@ -3,7 +3,7 @@ package org.baeldung.endpoints.info;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.baeldung.boot.repository.UserRepository;
|
||||
import org.baeldung.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.info.Info;
|
||||
import org.springframework.boot.actuate.info.InfoContributor;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package org.baeldung.main;
|
||||
|
||||
import org.baeldung.boot.controller.servlet.HelloWorldServlet;
|
||||
import org.baeldung.boot.controller.servlet.SpringHelloWorldServlet;
|
||||
import org.baeldung.common.error.SpringHelloServletRegistrationBean;
|
||||
import org.baeldung.common.resources.ExecutorServiceExitCodeGenerator;
|
||||
import org.baeldung.controller.servlet.HelloWorldServlet;
|
||||
import org.baeldung.controller.servlet.SpringHelloWorldServlet;
|
||||
import org.baeldung.service.LoginService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
@ -11,6 +11,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -21,7 +22,7 @@ import java.util.concurrent.Executors;
|
|||
|
||||
@RestController
|
||||
@EnableAutoConfiguration(exclude = MySQLAutoconfiguration.class)
|
||||
@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.service" })
|
||||
@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources","org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.boot.config"})
|
||||
public class SpringBootApplication {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.boot.model;
|
||||
package org.baeldung.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.boot.repository;
|
||||
package org.baeldung.repository;
|
||||
|
||||
import org.baeldung.boot.model.User;
|
||||
import org.baeldung.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.session.exception;
|
||||
|
||||
import org.baeldung.boot.model.Foo;
|
||||
import org.baeldung.demo.model.Foo;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.session.exception.repository;
|
||||
|
||||
import org.baeldung.boot.model.Foo;
|
||||
import org.baeldung.demo.model.Foo;
|
||||
|
||||
public interface FooRepository {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.session.exception.repository;
|
||||
|
||||
import org.baeldung.boot.model.Foo;
|
||||
import org.baeldung.demo.model.Foo;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.baeldung;
|
||||
|
||||
import org.baeldung.domain.Modes;
|
||||
import org.baeldung.boot.Application;
|
||||
import org.baeldung.boot.domain.Modes;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package org.baeldung;
|
||||
|
||||
import org.baeldung.config.H2JpaConfig;
|
||||
import org.baeldung.domain.GenericEntity;
|
||||
import org.baeldung.repository.GenericEntityRepository;
|
||||
import org.baeldung.boot.Application;
|
||||
import org.baeldung.boot.config.H2JpaConfig;
|
||||
import org.baeldung.boot.domain.GenericEntity;
|
||||
import org.baeldung.boot.repository.GenericEntityRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package org.baeldung;
|
||||
|
||||
import org.baeldung.domain.GenericEntity;
|
||||
import org.baeldung.repository.GenericEntityRepository;
|
||||
import org.baeldung.boot.Application;
|
||||
import org.baeldung.boot.domain.GenericEntity;
|
||||
import org.baeldung.boot.repository.GenericEntityRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.baeldung;
|
||||
|
||||
import org.baeldung.boot.Application;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package org.baeldung;
|
||||
|
||||
import org.baeldung.boot.Application;
|
||||
import org.baeldung.boot.domain.GenericEntity;
|
||||
import org.baeldung.boot.repository.GenericEntityRepository;
|
||||
import org.baeldung.config.H2TestProfileJPAConfig;
|
||||
import org.baeldung.domain.GenericEntity;
|
||||
import org.baeldung.repository.GenericEntityRepository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue