가격대비 성능이 괜찮은 공유기를 찾아 사용하다 보니 iptime을 주로 사용하게 되는데 어쩌다 한번씩 사용하다 보니 자주 일어버리게 되는 관리자 비밀 번호화 무선 인터넷 비밀번호 설정 방법을 기록해 둡니다

 

1. 관리자 비밀번호 설정

 

관리자 주소 http://192.168.0.1로 들어가


iptime 관리자 무선 비밀번호


관리도구를 클릭하여 로그인 창이 나오면


iptime 관리자 무선 비밀번호


초기 사용자이름과 비밀번호는 admin / admin 입니다그런데 보안을 강화한다고 비밀번호를 변경하여 시간이 지나면 잊어버리게 되는데 이런 경우에는 초기화를 해주면 됩니다.


iptime 관리자 무선 비밀번호


공유기에 있는 안쪽으로 조금 들어간 버튼모양을 눌러주면 모든 설정 값이 초기화 됩니다그러면 초기 값인 admin / admin 으로 로그인을 해 줍니다나중에 또 잊어버릴 수 있겠지만 관리자 비밀번호를 다시 설정 해 봅니다.


iptime 관리자 무선 비밀번호


좌측 메뉴탐색기에서 고급설정 > 시스템관리 > 관리자 설정 메뉴에서 계정과 비밀번호를 설정 하고 적용 버튼을 클릭 하면 됩니다.



2. 무선 비밀번호 설정

 

이번엔 무선 인터넷 비밀번호 설정 방법입니다요즘에 공유기 없는 집이 없으니 그냥 놔둬도 누가 쓰겠어? 인터넷을 사용 못하는 이웃이 있다면 서로 도우며 살아가야지하면 좋겠지만 무선 인터넷을 풀어두면 요즘엔 해킹을 통해서 노트북 카메라나 웹캠 등으로 사생활 침해와 개인정보들을 빼가는 일들이 벌어지니 꼭 비밀 번호를 설정해야 합니다.


iptime 관리자 무선 비밀번호


좌측 메뉴탐색기에서 기본설정 > 무선 설정/보안 메뉴를 선택 하고 인증 및 암호화와 네트워크 암호를 입력하고 적용 버튼을 클릭 합니다무선인터넷 이름을 변경 하려면 네트워크 이름이 초기값으로 iptime 으로 되어 있는데 다른 이름으로 변경해 줍니다.

이렇게 하면 공유기의 관리자와 무선인터넷 비밀번호를 변경해서 사용할 수 있습니다.


- copy coding -


Spring Security에서의 권한 별 접근은 아래 source 처럼 대부분 configure(HttpSecurity http)에 설정을 하여 관리를 하게 됩니다.


   @Override

   protected void configure(HttpSecurity http) throws Exception {

      http.httpBasic().and().authorizeRequests()

        .antMatchers("/").permitAll()

        .antMatchers("/page2").hasRole("ADMIN")

        .antMatchers("/page1").hasRole("USER")

        .anyRequest().authenticated()

        .and().logout().permitAll()

        .and().formLogin()

        .and().csrf().disable();

  }


다른 방법을 찾아보면 Controllerannotation을 추가하여 관리하는 방법도 있는데 이것이 @PreAuthorize, @PostAuthorize, @Secured 입니다사용 방법도 너무나 간단한데 권한 설정이 필요한 위치에 @PreAuthorize("hasRole('ROLE_ADMIN')") 이런식으로 어노테이션을 추가해 주면 권한 별로 접근을 통제 하게 됩니다예를 들자면...


    @PreAuthorize("hasRole('ROLE_ADMIN')")

    @RequestMapping("/preRole1")

    public @ResponseBody String preRole1() throws Exception {

              

           return "@PreAuthorize : get role ROLE_ADMIN";

    }


위에있는 예제처럼 추가를 하였는데 아무런 작동을 하지 않는다면 @PreAuthorize @Secured의 사용은 처음에는 비활성화 되어 있어서 사용 하려면 설정을 해줘야 됩니다이것도 아주 간단 한데 Configure 클래스 파일 상단에 아래 코드를 추가해 주기만 하면 활성화 됩니다.

@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)



테스트


몇가지 예를 들어 간단하게 테스트를 해보겠습니다.

 

copycodingADMIN 권한이고 honggil이는 USER 권한을 가지도록 configure에 설정을 합니다.


 @Autowired

 public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

    auth.inMemoryAuthentication()

        .withUser("copycoding").password(passwordEncoder().encode("copycopy")).roles("ADMIN");

    auth.inMemoryAuthentication()

        .withUser("honggil").password(passwordEncoder().encode("hoho")).roles("USER");

 }


Method에는 annotation을 사용하여 각 권한 별로  접근 설정을 합니다.


 @PreAuthorize("hasRole('ROLE_ADMIN')")

 @RequestMapping("/preRole1")

 public @ResponseBody String preRole1() throws Exception {

              

              return "@PreAuthorize : get role ROLE_ADMIN";

 }

       

 @PreAuthorize("hasRole('ROLE_USER')")

 @RequestMapping("/preRole2")

 public @ResponseBody String preRole2() throws Exception {

              

               return "@PreAuthorize : get role ROLE_USER";

 }

       

 @Secured("ROLE_ADMIN")

 @RequestMapping("/secRole1")

 public @ResponseBody String secRole1() throws Exception {

              

               return "@Secured : get role ROLE_ADMIN";

 }

 

 @Secured("ROLE_USER")

 @RequestMapping("/secRole2")

 public @ResponseBody String secRole2() throws Exception {

              

               return "@Secured : get role ROLE_USER";

 }



@PreAuthorize 테스트


ADMIN 권한이 있는 copycoding으로 로그인을 진행 합니다.


Spring Security PreAuthorize Secured


로그인이 성공 하면 http://localhost:9090/preRole1 에 접속해 봅니다


Spring Security PreAuthorize Secured


접근 권한이 있으니 접근을 할 수 있습니다.


그러면 이번엔 http://localhost:9090/preRole2 에 접속 합니다.


Spring Security PreAuthorize Secured


ADMIN만 접근 가능하니 USER 권한으로는 접근이 불가능 합니다


 

@Secured 테스트

 

USER 권한이 있는 honggil로 로그인을 하고 http://localhost:9090/secRole1 를 호출 합니다.


Spring Security PreAuthorize Secured


ADMIN만 접근 권한이 있으므로 접속이 차단 됩니다.

 

이번엔 http://localhost:9090/secRole2에 접속하면


Spring Security PreAuthorize Secured


USER 권한을 가지고 있어 접속이 가능 합니다.


configure를 이용하는 방법과 annotation을 이용하는 방법의 차이는 접근 권한을 한곳에서 관리 하느냐 여러곳에서 필요에 따라 관리하느냐 하는 관리적인 관점의 차이인데 프로젝트에 따라서 선택을 하던가 적절히 섞어서 사용 하던가 하면 될것 같습니다.

 

@PreAuthorize 와 쌍으로 @PostAuthorize 도 있습니다차이점은 @PreAuthorize 는 말 그대로 실행 전에 권한을 검사하는 거고 @PostAuthorize 는 실행 후 권한을 검사하는 건데 이것도 필요에 따라 선택을 하면 되겠죠.


전체 소스

WebSecurityConfigurerAdapter

package com.copycoding.security;

 

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.method.configuration.EnableGlobalMethodSecurity;

import org.springframework.security.config.annotation.web.builders.HttpSecurity;

import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;

import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import org.springframework.security.crypto.password.PasswordEncoder;

 

@Configuration

@EnableWebSecurity

@EnableGlobalMethodSecurity(securedEnabled=true, prePostEnabled=true)

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

 

        @Override

        protected void configure(HttpSecurity http) throws Exception {

               http.httpBasic().and().authorizeRequests()

        .antMatchers("/").permitAll()

        .antMatchers("/page2").hasRole("ADMIN")

        .antMatchers("/page1").hasRole("USER")

        .anyRequest().authenticated()

        .and().logout().permitAll()

        .and().formLogin()

        .and().csrf().disable();

        }

       

        @Autowired

        public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

               auth.inMemoryAuthentication()

                       .withUser("copycoding").password(passwordEncoder().encode("copycopy")).roles("ADMIN");

               auth.inMemoryAuthentication()

                       .withUser("honggil").password(passwordEncoder().encode("hoho")).roles("USER");

        }

       

        @Bean

    public PasswordEncoder passwordEncoder() {

        return new BCryptPasswordEncoder();

    }

} 


Controller

 package com.copycoding.security;

 

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpSession;

 

import org.springframework.security.access.annotation.Secured;

import org.springframework.security.access.prepost.PreAuthorize;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.bind.annotation.RestController;

 

@RestController

public class TestController {

       

        @RequestMapping("/")

    public @ResponseBody String home() throws Exception {

 

               return "Spring Boot ";

        }

       

        @RequestMapping("/page1")

    public @ResponseBody String pageNo1(HttpSession session, HttpServletRequest request) throws Exception {

              

               System.out.println("pageNo1=========ROLE_ADMIN===========>" + request.isUserInRole("ROLE_ADMIN"));

               System.out.println("pageNo1=========ROLE_USER============>" + request.isUserInRole("ROLE_USER"));

 

               return "Spring Boot : Page No 1";

        }

       

        @RequestMapping("/page2")

    public @ResponseBody String pageNo2(HttpSession session, HttpServletRequest request) throws Exception {

              

               System.out.println("pageNo2=======ROLE_ADMIN=============>" + request.isUserInRole("ROLE_ADMIN"));

               System.out.println("pageNo1=======ROLE_USER==============>" + request.isUserInRole("ROLE_USER"));

              

               return "Spring Boot : Page No 2";

        }

       

        @PreAuthorize("hasRole('ROLE_ADMIN')")

        @RequestMapping("/preRole1")

    public @ResponseBody String preRole1() throws Exception {

              

               return "@PreAuthorize : get role ROLE_ADMIN";

        }

       

        @PreAuthorize("hasRole('ROLE_USER')")

        @RequestMapping("/preRole2")

    public @ResponseBody String preRole2() throws Exception {

              

               return "@PreAuthorize : get role ROLE_USER";

        }

       

        @Secured("ROLE_ADMIN")

        @RequestMapping("/secRole1")

    public @ResponseBody String secRole1() throws Exception {

              

               return "@Secured : get role ROLE_ADMIN";

        }

 

        @Secured("ROLE_USER")

        @RequestMapping("/secRole2")

    public @ResponseBody String secRole2() throws Exception {

              

               return "@Secured : get role ROLE_USER";

        }

}


- copy coding -


1

+ Recent posts