반응형

log4j 취약점 사태에 따라서 프로젝트에 log4j 라이브러리를 변경해야 했다.

실제 프로젝트에서는 logback 을 사용중이었고 boot 버전은 2.2.4를 사용하고 있었고 spring-boot-starter-logging 을 사용중이었다.  이 라이브러리의 dependency 는 아래와 같다.

ch.qos.logback » logback-classic 1.2.3 
org.apache.logging.log4j » log4j-to-slf4j 2.12.1
org.slf4j » jul-to-slf4j 1.7.30
출처 : https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-logging/2.2.4.RELEASE

 

1. sping-boot-starter-logging 을 제외하고 log4j 라이브러리를 추가했다.

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

dependencies{
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.15.0'
    compile group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: '2.15.0'
    .....
}

그리고 나서 어플리케이션을 실행시켜보니 다음과 같은 로그가 남았다.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.4.RELEASE)

SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.
SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.

처음에는 어플리케이션이 실행이 안된건줄 알았는데 알고보니 로그가 안올라간것이었다. 그럼 왜 로그가 안나오는것일까??

일단 정확하지는 않지만 확인해본 바로는 프로젝트에서는 logback 을 사용중이었는데 sping-boot-starter-logging 라이브러리를 제외하는 바람에 logback 관련 라이브러리가 dependency 에 추가지되 않아서라는 추측을 하게 되었다. 

2. 로그백 라이브러리 추가

dependencies{
	implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.7'
    implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.7'
    ....
}

위와같이 로그백 라이브러리를 추가했다. 어플리케이션은 정상적으로 기동이 됐다. 그런데 다른 로컬 PC 에서 다시 SLF4J 관련 메세지가 나서 다시 수정을 했다.

3. sping-boot-starter-logging 제외 취소하고 log4j 만 추가.

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

1번에서 추가했던 위 부분을 삭제하고 2번에 추가했던 로그백 라이브러리도 삭제를 했다. 결과적으로는 log4j 라이브러리만 추가된 상황이다. 실제로 dependency를 확인해보면 다음과 같이 변경이 되어있다.

Gradle: org.apache.logging.log4j:log4j-api:2.15.0
Gradle: org.apache.logging.log4j:log4j-to-slf4j:2.15.0

어플리케이션도 정상적으로 잘 기동이 되었다.

이것때문에 구글에서 SLF4J 관련해서 계속 검색 하면서 삽질했는데 간단하게 해결이 됐다. ㅠㅠ 

 

728x90
반응형
반응형

Ubuntu 에서 Gradle 빌드 하는데 Error 가 났다. 


* What went wrong:Execution failed for task ':compileJava'.> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk-amd64 contains a valid JDK installation.

Error 내용을 보면 뭔가 찾을수 없다고 나온다.. tools.jar 파일.

일단 설치된 자바 버전을 확인해 보자.

java -versionopenjdk version "1.8.0_181"OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.16.04.1-b13)OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

버전은 1.8.0_181 openJDK 가 설치되어있다.

whereis javajava: /usr/bin/java /etc/java /usr/share/java /usr/share/man/man1/java.1.gz

JAVA 경로를 보니 위와 같이 되어있다.

ls -l /usr/bin/javalrwxrwxrwx 1 root root 22 Oct 19 01:17 /usr/bin/java -> /etc/alternatives/java

ls -l /etc/alternatives/javalrwxrwxrwx 1 root root 46 Oct 19 01:17 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

결론적으로 경로가 저렇게 /usr/bin/jvm/java-8-openjdk-amd64 를 보는게 아니라 jre 를 보고 있다.

update-alternatives --list javac/usr/lib/jvm/java-8-openjdk-amd64/bin/javac

javac 는 bin 하위를 바라보고 있다.

export JAVA_HOME=$(dirname $(dirname $(update-alternatives --list javac)))

JAVA_HOME 을 설정한 후에 잘 설정이 되어있는지 확인해본다.

echo $JAVA_HOME/usr/lib/jvm/java-8-openjdk-amd64


이렇게 한 후에 빌드를 하면 정상적으로 동작을 한다.


참고자료

https://askubuntu.com/questions/772235/how-to-find-path-to-java


728x90
반응형

'Development > Build' 카테고리의 다른 글

[Gradle]Ubuntu 에서 Gradle 설치하기  (0) 2018.10.19
Jenkins 설치  (0) 2018.09.19
Mac 에서 gradle 설치  (0) 2016.07.04
Maven 라이브러리 추출  (0) 2016.01.06
Maven clean, install, build??  (0) 2015.05.12
반응형

Ubuntu 에서 gradle 설치를 해보자.

설치 방법은 정말 간단하다.

sudo apt-get install gradle

$ sudo apt-get install gradleReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following additional packages will be installed:

이렇게 하면 설치가 쭉~~ 시작된다.

gradle -v------------------------------------------------------------Gradle 2.10------------------------------------------------------------Build time: 2016-01-26 15:17:49 UTCBuild number: noneRevision: UNKNOWNGroovy: 2.4.5Ant: Apache Ant(TM) version 1.9.6 compiled on July 20 2018JVM: 1.8.0_181 (Oracle Corporation 25.181-b13)OS: Linux 4.15.0-1021-gcp amd64

흠... 그런데... gradle 버전이 좀 이상하다.....

2.10?????

난 4 버전을 설치하고 싶은데.. 어떻게 해야하나.

sudo add-apt-repository ppa:cwchien/gradle
sudo add-apt-repository ppa:cwchien/gradle

sudo add-apt-repository ppa:cwchien/gradle

먼저 repository 를 추가한다.

그리고 sudo apt-get update 한번 쳐준다. 

sudo apt-get install gradle-4

여기까지 치고 TAB 키를 누르면

sudo apt-get install gradle-4.gradle-4.10 gradle-4.10.1 gradle-4.10.2 gradle-4.6 gradle-4.7 gradle-4.8.1 gradle-4.9

이렇게 설치할 수 있는 종류가 나온다.

나는 4.6 버전 선택해서 인스톨을 진행 했다.

gradle -v------------------------------------------------------------Gradle 4.6------------------------------------------------------------Build time: 2018-02-28 13:36:36 UTCRevision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46cGroovy: 2.4.12Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017JVM: 1.8.0_181 (Oracle Corporation 25.181-b13)OS: Linux 4.15.0-1021-gcp amd64

이렇게 설치를 마무리 하면 된다.



728x90
반응형

'Development > Build' 카테고리의 다른 글

[Gradle] gradle build error tool.jar... valid JDK  (0) 2018.10.19
Jenkins 설치  (0) 2018.09.19
Mac 에서 gradle 설치  (0) 2016.07.04
Maven 라이브러리 추출  (0) 2016.01.06
Maven clean, install, build??  (0) 2015.05.12
반응형

Spring Security 를 적용하는 내용을 처음부터 차근차근 정리를 해보려고 한다. 

목표는 Spring Security 를 공부하면서 각각의 기능들을 적용해보는것이다. 진행하다보면 Spring Security 뿐만 아니라 다른 내용들도 점점 추가될것 같다. 다 만들고 나서는 git에 소스를 공유할 생각이다. ^^;; 언제가 될지는 잘 모르겠다.


환경 : java 1.8, Spring Boot 1.5.3 Release, Maria DB, JPA, gradle


build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
buildscript {
    ext {
        springBootVersion = '1.5.3.RELEASE'
    }
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
 
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
 
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
 
repositories {
    jcenter()
    mavenCentral()
}
 
 
dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
 
    testCompile('org.springframework.boot:spring-boot-starter-test')
 
    runtime ('org.mariadb.jdbc:mariadb-java-client')
}
cs



아직 초반이어서 라이브러리가 몇개 없다. spring-boot 에서 사용하는 jpa, security, test, web 라이브러리가 끝이다. 그리고 DB를 사용하기 위한 mariadb client까지만 추가되어있다.


도메인.

Account.java

1
2
3
4
5
6
7
8
9
10
11
12
13
@Entity
public class Account {
    @Id
    private String loingId;
 
    private String username;
 
    private String password;
 
    private String email;
 
    private boolean enabled;
}
cs


Account 도메인이 있다. 만들기는 더 여러개 만들어놓았는데 우선은 이것만 필요해서 적었다. 위 Account.java 소스에는 getter/setter 메소드는 삭제하고 올렸다. (너무 길어서)


다음은 Account 관련 Service와 Repository 이다. 


AccountRepository.java

1
2
public interface AccountRepository extends JpaRepository<Account, String> {
}
cs


AccountService.java

1
2
3
4
public interface AccountService {
    Account get(String loginId);
}
 
cs


AccountServiceImpl.java

1
2
3
4
5
6
7
8
9
10
11
@Service
public class AccountServiceImpl implements AccountService {
 
    @Autowired
    private AccountRepository accountRepository;
 
    @Override
    public Account get(String loginId) {
        return accountRepository.findOne(loginId);
    }
}
cs


Repository를 다이렉트로 호출해도 되긴 하지만 아무래도 구조상 service 레이어가 있는게 맞다고 판단해서 repository는 Service 에서 호출하도록 한번 감쌌다. 지금은 간단히 호출만 하지만 나중에는 로직도 들어갈것이 예상된다.


CustomUserDetailService.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Service
public class CustomUserDetailService implements UserDetailsService{
 
    @Autowired
    private AccountService accountService;
 
    @Override
    public UserDetails loadUserByUsername(String loginId) throws UsernameNotFoundException {
 
        Account account = accountService.get(loginId);
 
        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
 
        User user = new User(account.getLoingId(), account.getPassword(), grantedAuthorities);
 
        return user;
    }
}
cs


UserDetailsService에 있는 loadUserByUsername 메소드를 제정의 해서 UserDetails 객체를 정의해준다. UserDetails는 사용자의 인증정보를 담고있다. 위에서 Account Service에서 loginId로 정보를 조회해서 가져온 id, password, 권한(아직 미구현으로 객체만 생성했다) 정보를 user로 생성해주고 있다.




ResourceSecurityConfiguration.java

1
2
3
4
5
6
7
8
9
10
11
12
@Configuration
@EnableGlobalAuthentication
public class ResourceSecurityConfiguration extends WebSecurityConfigurerAdapter {
 
    @Autowired
    private CustomUserDetailService customUserDetailService;
 
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(this.customUserDetailService);
    }
}
 
cs


WebSecurityConfigurerAdapter에 있는 init 메소드를 사용해서 AuthenticationManangerBuilder에 userDetailService를 내가 새로 만든 CustomUserDetailService를 사용하겠다고 설정해준다.


StudySpringApplication.java

1
2
3
4
5
6
7
8
9
10
@SpringBootApplication
public class StudySpringApplication {
 
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(StudySpringApplication.class);
 
        app.run(args);
    }
}
 
cs


application.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server:
  port: 9000
 
spring:
  datasource:
    driver-class-name: org.mariadb.jdbc.Driver
    url: jdbc:mariadb://localhost:3306/holmes
    username: root
    validation-query: select 1
    test-while-idle: true
    time-between-eviction-runs-millis: 300000
    test-on-borrow: false
 
  jpa:
    database: mysql
    show-sql: true
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        format_sql: true
        dialect: org.hibernate.dialect.MySQLDialect
        default_schema: holmes
cs


이제 어플리케이션을 실행해보면 로그인 페이지가 나온다. 





위에 소스와 약간 차이가 있을수 있지만 아래 Git repository 에 가면 소스를 확인할 수 있다. 


https://github.com/blusky10/study_spring


728x90
반응형
반응형

Mac 에서 Gradle 설치 방법을 간단히 적어본다..


먼저 아래 사이트에 가서 Gradle 을 다운받는다 (Complete distribution 클릭)


http://gradle.org/gradle-download/



그리고 나서 압축을 풀어주고 해당 폴더를 설치하고 싶은 위치에 옮겨준다. (나같은 경우는 Library 에 설치함)



그리고 환경변수를 등록해 준다.


open ~/.bash_profile



저장 한후에 profile 적용


source ~/.bash_profile


이렇게 하면 설치는 완료된다.


확인을 위해서 버전 확인!!




728x90
반응형

'Development > Build' 카테고리의 다른 글

[Gradle] gradle build error tool.jar... valid JDK  (0) 2018.10.19
[Gradle]Ubuntu 에서 Gradle 설치하기  (0) 2018.10.19
Jenkins 설치  (0) 2018.09.19
Maven 라이브러리 추출  (0) 2016.01.06
Maven clean, install, build??  (0) 2015.05.12

+ Recent posts